The Perfect MikroTik Config Restore Script
Restoring config files on MikroTik routers have always been a pain. I set out to make the perfect config restore script for MikroTik routers.
Have your every tried to paste configuration commands into a MikroTik router? Yeah, it doesn’t work. As soon as the script adds an interface to a bridge or changes an IP you get disconnected and the rest of the script lines fail to restore.
Using the ‘run after reset‘ method is really the best way to restore a MikroTik router’s configuration but it has it’s own little caveats like editing the script first and adding a :delay 15s;
line at the top.
After reboot, there is no clear indication if the import was successful or failed. While troubleshooting an error riddled backup I had the idea of introducing an audible beep before and after the import process. This lead me to develop this script.
This script is designed to restore plain-text, export files created using the following command.
1 | /export file=myrtrbackup |
I personally use the following export command to backup my routers. I find it easier to read and every line of the script is independent so copy and paste just works.
1 2 | /export terse file=myrtrbackup |
Features
- Introduces a delay – This allows time for the router’s interfaces to initialize before running the import script.
- Audible prompts – Before and after beep sequences to tell you if the import was successful.
- Logging to disk – you can inspect perfectrestore.log.0.txt to see if the import was successful. This is useful if your router does not have a builtin speaker (some models don’t).
How to use this script
Time needed: 1 minute.
WinBox Method
- Upload
perfectrestore.rsc
to your router’s flash folder - Rename your backup file
backup.rsc
and upload it to the router’s flash folder - Click “System | Reset Configuration” in Winbox
- Check the box “No Default Configuration” and choose
flash/perfectrestore.rsc
from the “Run After Reset” dropdown - Click the [Reset Configuration] button
The router will erase the existing configuration, reboot and execute the perfectrestore script. The script will introduce the proper delay, play the beginning beeps, then /import flash/backup.rsc
. If the import completes without error you will here the success beep sequence.
CLI Method
- Upload
perfectrestore.rsc
andbackup.rsc
to your router’s flash folder via scp or ftp - Issue the following command on the router.1/system reset-configuration no-defaults=yes run-after-reset=flash/perfectrestore.rsc
perfectrestore.rsc script download
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | # # perfectrestore.rsc # Version: 0.1.1 # Author: Jonathan Cutrer # License: MIT # Project: https://github.com/joncutrer/perfectrestore # { :local targetfile "flash/backup.rsc" # Wait for interfaces to initialize :delay 15s # Beep Functions :local doStartBeep [:parse ":beep frequency=1000 length=300ms;:delay 150ms;:beep frequency=1500 length=300ms;"]; :local doFinishBeep [:parse ":beep frequency=1000 length=.6;:delay .5s;:beep frequency=1600 length=.6;:delay .5s;:beep frequency=2100 length=.3;:delay .3s;:beep frequency=2500 length=.3;:delay .3s;:beep frequency=2400 length=1; "]; # Setup temporary logging to disk /system logging action add disk-file-count=1 disk-file-name=flash/perfectrestore.log disk-lines-per-file=4096 name=perfectrestore target=disk /system logging add action=perfectrestore topics=system,info /system logging add action=perfectrestore topics=script,info /system logging add action=perfectrestore topics=warning /system logging add action=perfectrestore topics=error /system logging add action=perfectrestore topics=critical /system logging add action=perfectrestore topics=debug # Play Audible Start Sequence $doStartBeep # Import the rsc file :log info "BEGIN IMPORT file=$targetfile" import $targetfile :log info "END IMPORT file=$targetfile" # Post import delay :delay 10s # Play Audible Finish Sequence $doFinishBeep # Teardown temporary logging to disk /system logging remove [/system logging find where action=perfectrestore] /system logging action remove [/system logging action find where name=perfectrestore] } |
Github Project
https://github.com/joncutrer/perfectrestore
I hope this script makes MikroTik Backups and Restores easier for you.
Have questions? Leave a comment below!!!
4 Replies to “The Perfect MikroTik Config Restore Script”
Lifesaver man. Thanks!
Thank you for the time and effort for this.
Great! Works perfectly (of course) – thanks!!!
Thank you so much!