otrdiena, 2017. gada 31. janvāris

Multiple MikroTik router backup on windows server


Create and export keys to MikroTik routers

First backups are saved to linux server, then forwarded to Windows server
First generate and import keys to all MikroTik routers via this manual. Test backup.
Keys are generated according to  http://wiki.mikrotik.com/wiki/Using_SSH_for_system_backup
Since RouterOS there are seized support for DSA keys. So instead of DSA you have to generate RSA key.
 ssh-keygen -t rsa
Also there are difference in last command.
instead of user ssh-keys import file=huekeys user=admin
you have to type just user ssh-keys import
[admin@mikrotik] > user ssh-keys import

public-key-file: mkey

Scheduled MikroTik backup collecting to Ubuntu server

Create directory to collect backups

mkdir rbackups

Create shell script

touch /rbackups/routerbackup

Script to collect backup files from routers

/home/ubuntu/rbackups/routerbackup.sh

#!/bin/bash
rm -rf *.rsc
rm -rf *.backup
for i in {1..6};do
name=MikroTik.$i.st
bfile=$(date +"%Y%m%d").$name
ssh admin@10.1.2.$i export file=$bfile
ssh admin@10.1.2.$i system backup save name=$bfile
sftp admin@10.1.2.$i:$bfile.rsc
sftp admin@10.1.2.$i:$bfile.backup
ssh admin@10.1.2.$i /file remove [/file find name=$bfile.rsc]
ssh admin@10.1.2.$i /file remove [/file find name=$bfile.backup]
done
chmod a+rw *.rsc

chmod a+rw *.backup.backup

Schedule script to execute every friday at 17:17 

sudo Crontab -e
17 17 * * 5 username /home/ubuntu/rbackups/routerbackup.sh

Scheduled MikroTik backup collecting to Windows server

Create directory to mount Windows server share
sudo mkdir /mnt/storagem

Script to copy backup files to Windows server
sudo touch /etc/cron.weekly/moveMTbackups.sh

pass=************
mount -t cifs -o domain=domainname,username=Backup,password=$pass //STORE.domainname.localhost/Backup\$ /mnt/storagem
cp /home/ubuntu/backups/*.backup /mnt/storagem/
cp /home/ubuntu/backups/*.rsc /mnt/storagem/
umount /mnt/storagem
Permissions to execute to shell script
sudo chmod 755 /etc/cron.weekly/movemikrotikbackups.sh
Where store is windows servername and Backup$ are hidden share.
Schedule script to execute every friday at 18:18
sudo Crontab -e 18 18 * * 5 /etc/cron.weekly/moveMTbackups.sh
As you can notice backup files are in place.





Nav komentāru:

Ierakstīt komentāru