Home » MikroTik Router » MikroTik Router Auto Backup via Email

MikroTik Router Auto Backup via Email

MikroTik Router is popularly used in not only ISP network but also enterprise office network. So, network administrators of any company should learn how to maintain MikroTik router properly. A regular task of a network administrator is to store configuration file backup. Almost every network administrator takes configuration file backup manually. But MikroTik router provides an E-mail tool by which network administrators can automate configuration file backup regularly via email and can reduce his/her daily manual task easily. E-mail tool is not configured by default in MikroTik router. So, network administrators must configure E-mail tool as well as do some scripting for getting email backup service. In this article, I will show you how to configure MikroTik E-mail tool to get configuration file backup via email with a few steps.

mikrotik-mail-backup

MikroTik Router Automated Email Backup Configuration

Now we will configure MikroTik E-mail tool so that it can send configuration file backup  via email. Complete configuration for storing backup and then sending via email can be divided into 3 steps.

  1. Email configuration
  2. Writing script for storing backup and sending Email
  3. Creating scheduler for executing script regularly

Step 1: MikroTik Router Email Configuration

For sending email from MikroTik router, first we need to configure sender email. MikroTik does not have a SMTP server. For this, we have to provide SMTP server as well as username and password so that MikroTik router can send mail through that SMTP server. So, to setup SMTP server and username and password in your MikroTik router, follow my below steps carefully.

  • Go to Tools > Email and provide sender email information as below:
    Server: SMTP Server IP address (Use your mail server IP or try using this Gmail IP: 173.194.77.108)
    Port: SMTP Server Port (usually 25 or if you use Gmail SMTP, use 587)
    From: Put your email address which will indicate from address for the mail.
    User: Put email user name (first part of @ sign) or full email address if applicable.
    Password: Put your email password.
  • Alternatively, you can do below cmd:/tool e-mail
    set address=173.194.77.108
    set port=587
    set from=systemzonedotnet@gmail.com
    set user= systemzonedotnet
    set password=*******
    Where 173.194.77.108 is Gmail SMTP Server IP, systemzonedotnet@gmail.com is a test mail ID created for this article and “*******” is the password.
  • For checking email configuration, send a test mail from MikroTik with below cmd:/tool e-mail send to=sezan.sayeed@yahoo.com subject=”email test” body=”email test” tls=yes

If everything is OK, the test email will be sent to the receiver email address. Email configuration has been completed if you follow above steps carefully. Now we will write script for storing backup file and sending via mail.

Step 2: Script for storing backup file and sending via email

After completing email configuration, we will no write a script that will store backup file and then send the backup file to the desired mail address. Follow below steps to write script in your MikroTik router.

  • Go to System > Scripts and click on PLUS SIGN (+) to add new script. New Script window will appear.
  • Type your script name (for example, Mail Backup) in Name input box and then copy and paste the below code in source box.
    :log info “Mikrotik Backup JOB Started . . . “
    :global backupfile configbackup
    :log info “Deleting old Backup File If available otherwise ignore & process further . . . “
    /system backup save name=$backupfile
    :log info “Backup process pausing for 10s so it complete creating backup file”
    :delay 10s
    :log info “Start Sending Backup File via Email using GMAIL SMTP  . . .” tool e-mailsend to=sezan.sayeed@yahoo.com subject=([/system clock get date] . \ ” MikroTik Backup”) body=”MikroTik email Backup” tls=yes file=$backupfile
    :delay 40s
    :log info “Backup Finished”
    :log info “Deleting Backup File. All Done.”
    /file remove $backupfile
  • Now click Apply and OK button for saving this script.
  • You can run this script manually by clicking Run Script button or typing this cmd: > system script run 0 

Script for storing configuration backup file and sending the file via email is now ready. Now we will create a scheduler so that this script can be run regularly at a fixed time.

Step 3: Scheduler for Executing Script Regularly

We have created script for storing configuration and sending via mail. But the script cannot execute itself. So, we have to create a scheduler that will execute the above script regularly at our desired time. For creating a scheduler in your MikroTik router, follow my below steps.

  • Go to System > Scheduler and click on PLUS SIGN (+) to add new scheduler.
  • Type scheduler name in Name input box and put script executing time in Start Time input box. For example, if you want to execute the script at 5:30 PM, put the time as 17:30:00.
  • Put sending time interval at Interval input field. For example, if you want to execute the script daily, put the value as 24:00:00
  • Now put your script name that you have provided at step 2(here, Mail Backup) in On Event box and then click Apply and OK button.

Scheduler is now ready. If everything is OK, MikroTik Router will send a mail regularly to the desired email address where configuration file should have attached.

You should follow the above steps one by one otherwise your desired result may not come. If you face difficulty to do above steps properly, please watch my video tutorial carefully about MikroTik Router Auto Backup via Email. I hope, it will reduce your confusion.


Note: This configuration has been done in MikroTik Router OS version 5.20. If you face any problem in upgraded version, please let me know. I will try to solve the problem.

MikroTik Router configuration file backup via email has been discussed in this article. I hope, you are now able to configure your MikroTik Router for sending configuration file backup via email. If you face any problem, feel free to discuss in comment or contact with from Contact page. I will try my best to stay with you.

mikrotik-router-auto-backup-via-email

ABOUT ME

I, Md. Abu Sayeed, am a system administrator. I like to share knowledge that I am learning from my daily experience. As a system administrator, I like to play with computer networking, Redhat Linux , Windows server, physical server and storage, virtual technology and other system related topics. I hope, my daily experiences that I am sharing in this website will be beneficial for you. So, if this article is helpful for you, don't forget to give a positive feedback by sharing on your favorite social media or liking our Facebook Page. You can also keep subscribed to our website for getting email notification of new post by providing your name and email address in Subscription Page.   

2 comments

  • Pranoy Majumder

    I am using Mikrotik CCR1016-12G Router v6.24. I set up email in mikrotik and it works i mean it can send me an email from the router. I have my own mail server. In script, “Start Sending Backup File via Email using GMAIL SMTP . . .” what should i use instead of GMAIL SMTP? i used my mail server ip address but nothing happens.

    • “Start Sending Backup File via Email using GMAIL SMTP . . .”. it is just a message. you can edit it as your wish. if you use your mail server IP and port, mikrotik can send email successfully.

Leave a Reply

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

*