Hi, It is short post about how to create backup of Mikrotik device from Linux server. It is nothing new, because there are plenty of such solutions around the internet, especially on Mikrotik wiki [http://wiki.mikrotik.com/wiki/Main_Page]. This one is modified by me and it is working, so maybe it will be useful for others guys too. Especially for those in a hurry. On the other hand it is not a tutorial for copy paste - you need few additional steps :).

Important - You need to remember, that if you use mikrotik it is best to have export and backup. When you have only backup it may be not enough.

You will need:

  • Mikrotik device
  • Some linux server or vps. Let say it will be Ubuntu.

If devices are in the same network it is easy, if not - best would be to set secure connection over vpn.

You need to generate ssh keys and send it to your MT to be able to login without password.

Script:

#!/bin/bash
export name=mt
export folder=/some/share/name/
file="date +%Y%m%d-$name"
ssh userx@mt export file=$file
sleep 5
sftp userx@mt:$file.rsc $folder
ssh userx@mt system backup save name=$file dont-encrypt=yes
sleep 10
sftp userx@mt:$file.backup $folder
chown someone:users $folder$file.rsc $folder$file.backup

Explanation:

You need to change " for ` in above code. I added IP of this MT to hosts, so I can use now it's name instead. Sleep is needed, because my files are big and I want to be sure that everything will be ready to download. I need to use chown on these file, because I want to be able to open them from windows domain user account.

Now you only need to add this script as /etc/cron.weekly/xyz