Mirkotik router backup with SSH and SFTP
mikrotik
Everybody knows how important it is to backup. I use Mikrotik Routers in my home network and have quite complex configuration which I would not want to write again from scratch. Prior to this day I have used scheduled script on Mikrotik to create backups locally, transferring it out of router itself into another location is great way to increase backup durability.
Setup
To be able to use backup script you should have ssh key pair as ssh is used as secure protocol to connect
to router.
Upload your public key to Mikrotik via Files
menu and execute:
Note: To generate new ssh key pair you can use ssh-keygen
.
Important: By sshing to router with this key you will have admin privliedges. I was not sure if there is poossiblity to lower permissions for backup purposes. Leave me a note if that’s the case.
Script
If we have ssh
connectivity from system that should do backup then it’s time to do remote backup.
This script will:
- write log and create backup
- download backup with sftp
- remove backup from router and log end of script execution
$1 is variable which is passed as arguemnt to script. Ex:
If you have more than one device then it’s easy to backup all of them.
3h4x
- Sentry 9 - fix for PagerDuty legacy integration.
- Migration to Google Cloud Dns from different provider.
- Mass file renaming containing nonASCII characters to ASCII
- Infrastructure continuous deployment with terraform and atlantis
- Free git repository for private projects - GitHub vs GitLab vs BitBucket