Many have encountered a remarkable feature, for example, in HPE switches — if the configuration was not saved manually for some reason, the previous saved config is applied after a reboot. The technology is somewhat ruthless (forgot to save — redo it), but fair and reliable.
However, this function is not available in Mikrotiks, although there is a long-known adage: 'remotely configuring a router — leads to a long journey'. And even a nearby router can easily be turned into a 'brick until reset'.
Strangely enough, I couldn't find a single manual on this matter, so I had to do it manually.
The first thing we do is create a script to back up the configuration. In the future, we will use this script to 'save' the state.
We go to System -> Scripts and create a script, let's say, 'fullbackup' (of course, without quotes).
system backup save dont-encrypt=yes name=Backup_full
We won't use a password since otherwise, we would have to specify it in plain text in the neighboring script, and I don't see the point in such 'protection'.
We create a second script that will restore the configuration upon each startup. We'll call it 'full_restore'.
This script is a bit more complicated. The thing is, when restoring a configuration, a reboot also occurs. Without using any control mechanism, we will get a cyclic reboot.
The control mechanism turned out to be a bit 'sturdy', but reliable. Upon each execution of the script, it first checks for the presence of the file 'restore_on_reboot.txt'.
If the file exists — it means a restore from the backup is required. We delete the file and proceed with the restoration followed by a reboot.
If the file does not exist — we simply create this file and do nothing (i.e., it means this is already the second boot after restoring from the backup).
:if ([/file find name=restore_on_reboot.txt] != "") do={ /file rem restore_on_reboot.txt; system backup load name=Backup_full password=""} else={ /file print file=restore_on_reboot.txt }
It's best to check the script's operation at this stage before adding the task to the scheduler.
If everything is okay — we proceed to the third and final action — we add a task to the scheduler to run the script at each boot.
We go to System -> Scheduler and add a new task.
In the field Start time we specify startup (yes, we write it out, in letters)
In the field On Event we write
/system script run full_restore
Next, we run the script that saves the config! We don't want to do all this again, do we?
Let's add some "junk" to the settings for testing, or remove something important and finally try rebooting the router.
Yes, many will probably say: "There is a safe mode!". However, it won't be suitable if you need to reconnect to the router after your work (for example, if you change the address or Wi-Fi network settings you are connected to). And don’t forget about the possibility of "forgetting" to enable this mode.
P.S. The main thing now is not to forget to "save".
Source: habr.com
