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 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.
- Email configuration
- Writing script for storing backup and sending Email
- 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: 188.8.131.52)
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 user= systemzonedotnet
Where 184.108.40.206 is Gmail SMTP Server IP, email@example.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 firstname.lastname@example.org 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”
:log info “Start Sending Backup File via Email using GMAIL SMTP . . .” tool e-mailsend email@example.com subject=([/system clock get date] . \ ” MikroTik Backup”) body=”MikroTik email Backup” tls=yes file=$backupfile
: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.