· MikroTik Tutorial · 3 min read
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...
This post was originally published on jcutrer.com (WordPress) and has been migrated to the archive.
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 its 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.
/export file=myrtrbackupI 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.
/export terse file=myrtrbackupFeatures
- 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.rscand upload it to the router’s flash folderClick “System | Reset Configuration” in Winbox
**Check the box “No Default Configuration” and choose
flash/perfectrestore.rscfrom the “Run After Reset” dropdown **** Click the 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.rscandbackup.rscto your router’s flash folder via scp or ftp- Issue the following command on the router.
/system reset-configuration no-defaults=yes run-after-reset=flash/perfectrestore.rscperfectrestore.rsc script (https://github.com/joncutrer/perfectrestore/blob/master/perfectrestore.rsc)
#
# 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 action remove
}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!!!
Comments are disabled (Giscus not yet configured).