Mikrotik Router auto backup script and send backup via Email

 

In this lesson, we will be discussing on how to take Mikrotik router backup automatically and send the backup file to email.

To do this we will write a script and use scheduler to run the script at regular interval. We will make this configuration as such so that every day at 9:00PM router will take automatic backup and send it to our email.

At first, we will have to set up E-mail on router so that this router send the Router Backup to our E-mail address. Router needs a SMTP Server Address to send E-mail.

To set the SMTP Server in MikroTik:

  • We first go to Tools
  • Then E-mail
  • Put SMTP Server Information.
PING to find out GMAIL SMTP IP

SMTP Server Information:

  • Server= smtp.gmail.com or 74.125.130.109
  • Port=SMTP-Port (587 by default)
  • TLS/SSL: Required.
  • From=Email-Address (Router’s Email Address)
  • User: [Your full Gmail username (email address), for example [email protected].]
  • Password: [Your Gmail password]
E-mail Settings in Mikrotik Router

Manual: System/Script:

Now, we will write the script and save it on router script section:

  • From menu select system and then script.
  • Click + sign to add script.
  • We will copy our script from notepad and paste it.
  • We will give it a name as RouterBackup.
  • Uncheck romon and dude.
  • Click apply and ok.

The Script for auto backup:

/export file=config;
/system backup save name=config;
/tool e-mail send to="[email protected]" subject=([/system identity get name]." Backup") body=("Mikrotik Configuration Backup for - ".[/system clock get date]) file=config.rsc,config.backup;
/log info "Backup e-mail sent.";
System/Script

Manual: System/Scheduler

Now, we will make schedule for router backup.

  • Go to system and then scheduler.
  • Click + sign to add.
  • On event write the script name ‘RouterBackup’ that we have created.
  • We give our scheduler name same as script name.
  • Start time 21:00:00 and interval 1Day.
System/Schedule

Make sure router shows the correct time. We need to verify this. First, we check SNTP and then clock.

If you follow upto this, your configuration is done. You will get your router backup to your given E-mail everyday at 9:00PM.

Video Tutorial:

Spread the love

Leave a Reply

Your email address will not be published. Required fields are marked *