MikroTik Router Auto Backup via Email
MikroTik Router by default provides a lot of tools for reducing system admin’s burden. E-mail tool is one of them. Using this tool system administrator can automate configuration file backup regularly via email and can reduce his/her daily manual task easily. So, this article is designed to show how to configure MikroTik Router Auto Backup via Email with a few steps.
MikroTik Router basic configuration was explained in my previous article. If you are new here, feel free to spend some time to study about MikroTik Router basic configuration and then continue the rest of this article.
MikroTik Router Automated Email Backup Steps:
- Email configuration
- Writing script for storing backup and sending Email
- Creating scheduler for running script regularly
MikroTik Router Email Configuration
For sending email from router, first you need to configure sender email. For this do the below steps:
- 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: 184.108.40.206)
Port: SMTP Server Port (usually 25 or if you use Gmail SMTP, use 587)
From: Put your email address here that will indicate from address.
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 220.127.116.11 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 is now complete. Next we shall write script for storing backup file and sending via mail.
Script for storing backup file and sending via email
Now we shall write a script that will store backup file and then send the backup file to the desired mail address. Follow below steps to do that.
- Go to System > Scripts and click add (+) new button.
- Type your script name (for example, Mail Backup) at Name field 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
Our script for storing configuration backup file and sending the file via email is now ready. Next we shall create a scheduler that will run this script regularly.
Scheduler for Running Script Regularly
Now we shall create a scheduler that will run the above script regularly at our desired time. For this do the below steps:
- Go to System > Scheduler and click add (+) new button.
- Type scheduler name at Name field and put the Start Time when the script will run. For example, if you want to run the script at 5:30 PM, put time as 17:30:00.
- Put sending time interval at Interval field. For example, if you want to run the script daily, put the value as 24:00:00.
- Now put your script name (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 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. So, if you face difficulty to do above steps properly, please watch the below video 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’ll 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 contact with from Contact page. I’ll try my best to stay with you.