I was recently looking for a simpler alternative to something like RANCID to periodically backup all our MikroTik configs.
RANCID is great and all, but I didn’t really need the diff copies of each file, and I was plenty happy just knowing that I have a .backup and .rsc file for each router I manage.
Given I use Gmail it might have been ok just to have each router send them there and leave it at that, but I’m not really the sort of person to half-ass my afterhours projects.. I learnt from Greg that you have to just whole-ass them
So, there’s plenty of ways to have a MikroTik router backup and send a copy of it’s config to an email account, but what I really wanted to do was have them automagically move into a Google Drive folder of my choosing. Why Google Drive? Well I already use GMail so I have 30GB of hosted space I can keep everything together in, so why wouldn’t I?! This also sync between my Desktop and Laptop so I’ll always have copies of the backups with me.
I searched around and finally stumbled across this post about a script called “Send to Google Drive” that can run in the background on your GMail account all the time.
So to start with I created a script to export, send and then remove config files from the local router (saved as backup-and-email):
Next I logged into my gmail account and created a label called “RBackup” and another called “RBackup Saved” for the files to flow into, then logged into Google Drive and created a new folder in the root directory called “Router Backups”
Then as instructed I copied the spreadsheet provided and set the values as follows:
Then followed the 2 step procedure to authorise and run the app.
Next I created the filter in GMail for all emails from email@example.com destined to firstname.lastname@example.org where subject contained “[Config Backup]” and move it into the newly created “RBackup” folder/label.
Any emails that get moved here will be processed the by script, have the “RBackupSaved” label appended to them and attachments moved into the predetermined “Router Backups” folder I created in Google Drive.
To test I manually ran the script on my router and waited; it takes about a minute sometimes for the script to see the files, but the end result is that each night a new copy of all my router backups come flying into my Google Drive folder ready for any emergencies.
Next step is to ensure there’s a scheduler entry to have the script run each night, week, month or however often you’d like your backups.