Guide to Backup Mikrotik Configuration to Gmail Email

To backup the proxy, please use the backup script that can be run every day.

here we will provide an explanation of how to periodically backup the proxy configuration to your gmail email.
1. we utilize gmail SMTP to send an email to ourselves.

2. go to system -> script -> add a new script with the name "backup" policy checked all of them.
Fill in the source script as follows:



#### Modify these values to match your requirements #### 
#Your email address to receive the backups :local toemail "xxx@gmail.com"
#The From address (you can use your own address if you want) :local fromemail "xxx@gmail.com"
#A mail server your machines can send through :local emailserver "74.125.200.108"
:local password "xxx"
############## Don’t edit below this line ##############

:local sysname [/system identity get name] :local textfilename :local backupfilename :local time [/system clock get time] :local date [/system clock get date] :local newdate ""; :for i from=0 to=([:len $date]-1) do={ :local tmp [:pick $date $i]; :if ($tmp !="/") do={ :set newdate "$newdate$tmp" } :if ($tmp ="/") do={} }
#check for spaces in system identity to replace with underscores :if ([:find $sysname " "] !=0) do={ :local name $sysname; :local newname ""; :for i from=0 to=([:len $name]-1) do={ :local tmp [:pick $name $i]; :if ($tmp !=" ") do={ :set newname "$newname$tmp" } :if ($tmp =" ") do={ :set newname "$newname_" } }
:set sysname $newname; }
:set textfilename ($"newdate" . "-" . $"sysname" . ".rsc") :set backupfilename ($"newdate" . "-" . $"sysname" . ".backup") :execute [/export file=$"textfilename"] :execute [/system backup save name=$"backupfilename"] #Allow time for export to complete :delay 2s

#email copies :log info "Emailing backups" /tool e-mail send to=$"toemail" from=$"fromemail" start-tls=yes port=587 subject="[Mikrotik Backup Export] $sysname $time" file=$"textfilename" user=$"fromemail" password=$"password" #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=$"fromemail" start-tls=yes port=587 subject="[Mikrotik Backup] $sysname $time" file=$"backupfilename" user=$"fromemail" password=$"password"
#Allow time to send :delay 10s
#delete copies /file remove $textfilename /file remove $backupfilename


make sure the red2 color is replaced with your gmail account.

3. go to system -> scheduler -> create a new schedule with the name "backup"

start date fill in today's date, start time fill in what time the script will be executed, interval fill in 1d 00:00:00 which means every 1 day the script will be called.
on event: backup
Policy: check everything

click save/ok.

4. go to tools -> email and fill in and save as follows:


5. please wait and make sure the scheduler is running correctly by looking at the "run count" column which means how many times the scheduler has been run.

Did you find it helpful? Yes No

Send feedback
Sorry we couldn't be helpful. Help us improve this article with your feedback.