‘30/10/2017 ‘Gmail + Google Drive + MikroTik scripting = Automated Backups Folder | The (unofficial) Micatik ste
Gmail + Google Drive + MikroTik
scripting = Automated Backups Folder
@April10,2014 — wscripts, software automation, backup, export, export compact, gmail,
google drive, google script, labnolorg, mikrotik,routeros,rsc script, system backup & Omega-00
Iwas recently looking for a simpler alternative to something like RANCIO to periodically backup all our
MikeoTik configs
RANCID is great and all, but didn’t really need the diff copies of each file, and I was plenty happy just
knowing that | have a backup and .sc file for each router | manage.
Given | use Gmail t might have been ok just to have each router send them there and leave ita that,
but I'm not really the sort of person to half-ass my afterhours projects...| learnt from Greg that you
have to ust 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 already use GMail so I have 30GB of hosted space | can keep
everything together in, so why wouldn't ?! This also sync between my Desktop and Laptop soll,
always have copies of the backups with me.
| 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.
Perfect!
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)
1] fh Modify these values to match your requirements #it
2
3| fyour enail address to receive the backups
4| local toenail "yougexanple..com”
6 | #the From address (you can use your own address if you want)
7| tlocal’ fromemail *nikrotik@example. com”
8
9| #8 mail server your machines can send through
1@| ‘local enailserver "smtp.exanple. con”
u
12 | weiwaawnwen® Don’t edit below this Line #emHmHHiARHNRH
3
14| local sysname [/systen identity get name]
15 | Hocal textfilename
36 | Hocal backupfilenane
17| local tine [/systen clock get tine]
18| local date [/systen clock get date]
19| local newdate
29| :for i from=@ to=([:len $date]-1) do={ :local tmp [:pick $date $i];
21| tif ($tmp 15"/*) dos( rset newdate "snewdatestmp” }
22 | :if ($tmp ="/") do=t}
23| }
24| itcheck for spaces in system identity to replace with underscores
25| rif ([:Find $sysname """] !=@) do={
26 | local name $sysnames
27| local newname
28 | :for i from=
to=({:len $name]-1) do=:
tlocal tmp [pick $name $i];
htps:iiwew mikrotk-rouleras.com/2014/04/gmaitgoogle-crive-mikrotk-sripting-automated-backups folder! 19‘30/10/2017 ‘Gmail + Google Drive + MikroTik scripting = Automated Backups Folder | The (unofficial) Micatik ste
29 | rif ($tmp !=""") do={ :set newname “Snewnamestmp" }
30] if ($tmp =" ") do={ :Set newname "$newname_" }
ai} }
32 | set sysname $newname;
33
34 | rset textfilename ($"newdate sname" . ".rsc")
35 | set backupfilename ($"newdat sysname” .-".backup")
execute [/export file=$"textfilenane
rexecute [/system backup save nane=$"backupfilename"]
38 | #Allow time for export to complete
39] :delay 2s
41| #email copies
42 | :log info "Emailing backups"
43 | /tool e-mail send to- fromenail” server=[:resolve $em
4a | send as different subjects to force GMail to treat as new message thr
45 | :local time [/system clock get time]
46 | /tool e-mail send to=$"toenail” from=s
fromenail” server=[:resolve $em
43 | #Allow time to send
49| :delay 10s
51] #delete copies
52 | /file remove $textfilenane
53 | /file remove $backupfilename
Next | logged into my gmail account and created a label called “Rackup" 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:
|Gmail Label that the script should monitor Backup
Router Backups
|Google Drive folder where the Gmail attachments are be
saved
[Gmail Label that should be applied to processed messages |RBackupSaved
Then followed the 2 step procedure to authorise and run the app.
Next | created the filter in GMail for all emails from secretrouteremail@example.com destined to
myemailaddress@example.com where subject contained “[Config Backup]" and move it into the
newly created “Backup” 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 | created
in Google Drive.
Totest| 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.
htps:shwew mikrotk-rouleras.com/2014/04/gmailgoogle-crive-mikrotk-sripting-automated-backups older!0/10/2017 ‘Gmail + Google Drive + MikroTik scripting = Automated Backups Folder | The (unofficial) Micatik ste
"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.
1 | /systen scheduler
2| add interval=1d nane=daily-backup on-event="/systen script run backup-a
< »
Big thanks to the fellow at Labnol.org who made his script freely available, hopefully mine is of use to
some of you as well!
The finished product:
Bil Roe Bacups
ot I a 1228 am nw
2 02 TT 2 m= 1220 am
Bec 5 m= 220m
2 I chp v= 228m
3-2 TT r= 22h am we
a! 1224 am we
502 I E29 m= reztam
i. Tc m wean
Share this:
Ei Facebook | ch Reddit | yF Twittor | fg Email & Print
Related
MikroTik Scripting: Failover
Routing for Asterisk PBX
Hi guys, This is my second
article and | wanted to raise
the difficulty level of my
RouterOS asa PXE (Net Boot) TheBrothersWISP7—Airfiber tutorials! We work a lot with
server - Latvian Mikrotik Videos - Asterisk PBX and MikroTik
Mikrotik Basics July 17,2014
In "mikrotik" August 16, 2012 In "scripts"
With 10 comments
Translate]
12 thoughts on “Gmail + Google Drive + MikroTik
scripting = Automated Backups Folder”
htps:shwew mikrotk-rouleras.com/2014/04/gmailgoogle-crive-mikrotk-sripting-automated-backups older! 3190/10/2017
‘@
Brandon
@
Alej
@
Alej
‘Gmail + Google Drive + MikroTik scripting = Automated Backups Folder | The (unofficial) Micatik site
April 10, 2024 at 8:54 am,
‘Awesome! Can't wait to play with this!
April 10, 2014 at 8:27 pm
Hi, i followed all your guidelines.
Butit doesn’t work
Itseems the device doesn’t send the email
thank you
April 10, 2014 at 8:45 pm
here i am, it sends email but it doen't go to google drive @
thanks
April 10, 2014 at 10:22 pm
it works, but the script has some errors @
Alej
April 12,2014 at 11:11 am
Hey Aj,
Aron
Peyroteo
Cardoso
Where did you get stuck, the script not moving the attachments from the email into
the backup folder?
April 23, 2014 at 3:19 am,
It’s working perfectly!
htps:shwew mikrotk-rouleras.com/2014/04/gmailgoogle-crive-mikrotk-sripting-automated-backups older!
490/10/2017
‘Gmail + Google Drive + MikroTik scripting = Automated Backups Folder | The (unofficial) Micatik site
September 9, 2014 a 7:05 pm
it gives script error after each $ sign
moni
March 4, 2015 at 6:46 am
How to implement SMTP authorisation please?
Adam
Leonardo
March 23, 2015 at 11:46 pm
‘Simply awesome. Thank You.
Pivetti
‘August 18, 2015 at 5:10 pm.
Thank you very much, very helpful.
My 2 cents:
Julien
Grossiord
(@jgrossior
¢)
+
ibr771
al
Joeweb
~ use https://sendtodropbox.com to take an email to a Dropbox account instead
Gmail, works like a charm
from address and smtp server are better to configure once forall in /tool e-mail
{this will enable @Adam to implement SMTP Auth, TLS, etc).
October 4, 2015 at 2:39 pm
heloo
the scriptis not working with mikrotik 6.31
December 7, 2015 at 9:39 am
This is the working configuration with Google mail accounts.
Here's the script
‘i#H# Modify these values to match your requirements ##i
htps:shwew mikrotk-rouleras.com/2014/04/gmailgoogle-crive-mikrotk-sripting-automated-backups older!
59‘30/10/2017
‘Gmail + Google Drive + MikroTik scripting = Automated Backups Folder | The (unofficial) Micatik ste
#Your email address to receive the backups
slocal toemail “info@gmailaccount”™
‘The From address (you can use your own address if you want)
local fromemail “info@gmailaccount”
‘#A mail server your machines can send through
slocal emailserver “173.194.65.16"
#A mail Username
slocal pass “accountpassword”
‘HeeuEHHANHEH Don't edit below this line HHHHNERHHEHEH
slocal sysname [/system identity get name]
slocal textfilename
slocal backupfilename
local time [/system clock get time]
local date [/system clock get date}
-for i from=0 to=([:len Sdate]-1) do={ local tmp [:pick $date $i];
sif (Stmp !="/") do={ :set newdate “Snewdatestmp" }
sif (Stmp ="/") do={}
}
‘check for spaces in system identity to replace with underscores
:if({find Ssysname * “| !=0) d
local name sysname;
slocal newname “";
slocal newdate
:for i from=0 to=([len $name]-1) do={ local tmp [:pick Sname Si];
‘if (Stmp =" *) do={ set newname “Snewnamestmp” }
if (Stmp =" “) do={:set newname “Snewname_"}
}
:set sysname Snewname;
}
sset textfilename ($"newdate’ ‘$"sysname" . “rsc")
:set backupfilename (S"newdate” *-". $"sysname”.“backup")
sexecute [/export file=$"textfilename"]
sexecute [/system backup save name=$"backupfilename”}
#Allow time for export to complete
sdelay 2s
email copies
log info “invio per Email i backups”
tool e-mail send to=$"toemail”from=$"tromemait” server=[:resolve Semailserver]
port=25 user=$"fromemail” pass-$”pass” subject="[Backup Configurazione]
Ssysname $time” file=$"textfilename”
#Send as different subjects to force GMail to treat as new message thread.
:local time [/system clock get time]
{tool e-mail send to=$"toemail”from=$”tromemail” server=[:resolve Semailserver]
port=25 user=$"fromemail” pass=$”pass” subject="[Backup Configurazione]
Ssysname $time” file=$"backupfilename”
htps:shwew mikrotk-rouleras.com/2014/04/gmailgoogle-crive-mikrotk-sripting-automated-backups older! a9wutomated Backups Folder| The (unofficial) Mikrotik site
‘30/10/2017 Gmail + Google Drive + MikroTk scripting
#Allow time to send
sdelay 10s
delete copies
file remove $textfilename
{file remove Sbackupfilename
htps:shwew mikrotk-rouleras.com/2014/04/gmailgoogle-crive-mikrotk-sripting-automated-backups older!
79‘30/10/2017 {Gmail + Google Drive + MikroTk scripting = Automated Backups Folder | The (unofficial) Mikrotik site
htps:shwew mikrotk-rouleras.com/2014/04/gmailgoogle-crive-mikrotk-sripting-automated-backups older!
89‘30/10/2017 {Gmail + Google Drive + MikroTk scripting = Automated Backups Folder | The (unofficial) Mikrotik site
htps:shwew mikrotk-rouleras.com/2014/04/gmailgoogle-crive-mikrotk-sripting-automated-backups older!
99