Mikrotik Schedule Backup to Gmail automatically into my gmail on daily basis

Mikrotik Schedule Backup to Gmail automatically into my gmail on daily basis system setting, 2 step is need to setting up everything.



This method include create and configure SMTP server, Delete old backup, Send Backup to Provided Email, Create Schedule as daily Basis.


1. Open Mikrotik Via Winbox

2. Open new Terminal 

3. Copy below script and paste in New Terminal then Press Enter

**GMAILUSERNAME = Input Your Gmail user

**YOUREMAILID@gmail.com = Input Your Gmail account

**YOURCURRENTPASSWORD = Input Your Gmail password

**RECEIVEREMAILADDRESS = Input Your Gmail account


/system script

add name=BackupEmailByKarimzi source="# Enter Sender/Receiver Details.\r\

    \n\r\

    \n:global gmailuser  GMAILUSERNAME\r\

    \n:global gmailid  YOUREMAILID@gmail.com\r\

    \n:global gmailpwd  YOURCURRENTPASSWORD\r\

    \n\r\

    \n## --- Do not change below ---- ##\r\

    \n\r\

    \n\r\

    \n# Enter Receiver  Details.\r\

    \n:global recmail RECEIVEREMAILADDRESS\r\

    \n\r\

    \n## --- Do not change below ---- ##\r\

    \n\r\

    \n#:log warning \"Mikrotik Router Backup JOB Started . . . \"\r\

    \n:local gmailip\r\

    \n:set gmailip [:resolve \"smtp.gmail.com\"]\r\

    \n:global backupfile configbackup\r\

    \n:global mikrotikexport mtexport_backup\r\

    \n:global sub1 ([/system identity get name])\r\

    \n:global sub2 ([/system clock get time])\r\

    \n:global sub3 ([/system clock get date])\r\

    \n:log warning \"Creating new up to date backup files . . . \"\r\

    \n\r\

    \n/system backup save dont-encrypt=yes name=\$backupfile\r\

    \n/export compact file=\$mikrotikexport\r\

    \n\r\

    \n/tool e-mail set address=\$gmailip from=\$gmailid password=\$gmailpwd port=587 start-tls=yes user=\$gmailuser\r\

    \n\r\

    \n:log warning \"Backup process pausing for 10s so it can complete creating backup if system is busy ...\"\r\

    \n:delay 10s\r\

    \n:log info \"Start Sending Backup File via Email using GMAIL SMTP . . .\"\r\

    \n/tool e-mail send to=\$recmail password=\$gmailpwd subject=\"\$sub3 \$sub2 \$sub1 Configuration BACKUP File\" from=\$gmailid file=\$backupfile server=\$gmailip start-tls=yes\r\

    \n:delay 30s\r\

    \n/tool e-mail send to=\$gmailid password=\$gmailpwd subject=\"\$sub3 \$sub2 \$sub1 Configuration EXPORT File\" from=\$gmailid file=\$mikrotikexport server=\$gmailip start-tls=yes\r\

    \n# Delete Old backup files to save space.\r\

    \n/file remove \$backupfile\r\

    \n:delay 30s\r\

    \n/file remove \$mikrotikexport\r\

    \n/tool e-mail set address=0.0.0.0 from=<> password=xxxx port=25 start-tls=yes user=yourid\r\

    \n:log warning \"Backup Finished & Backup File Removed. All Done. You should verify your inbox for confirmation\""


4. Now Copy below script and paste new terminal then press enter for create schedule. Here I am taking backup Every Night at 12.05 am, and auto backup start from oct/21/2021. You can be chage time as per your requirement.


Now Add Scheduler (Every Night at 12.05am)


/system scheduler


add interval=1d name=BackupEmailByKarimzi on-event​=BackupEmail start-date=oct/21/2021 start-time=00:05:00


Comments