How can I make backup schedule of the system and send the backup file to a mail adresse
ver. 2.9.8
How can I make backup schedule of the system and send the backup file to a mail adresse
ver. 2.9.8
There are some examples here:
http://www.mikrotik.com/docs/ros/2.8/appex/scripting1.content
There is not an exact script, but this page is pretty good. Also, you can look here for the scripting manual:
http://www.mikrotik.com/docs/ros/2.9/system/scripting
Here is the script I use. You will have to set a schedule for it to run at the time you wish.
This script portion is very long because it customizes the backup file name to the router’s indentity and the time and date of the backup. Otherwise, you would always get a backup file with the exact same file name each time you run the script, which is not very helpful if it overwrites old backups you want to keep. It also then delays a few seconds and then deletes the backup file so that you will not end of filling up your router file system with backup files. Lastly, it will write an entry to the system log to tell you that it actually executed the script.
/system script add name=ebackup source={/system backup save name=([/system identity get name] . "-" . [:pick [/system clock get date] 7 11] . [:pick [/system clock get date] 0 3] . [:pick [/system clock get date] 4 6]); /tool e-mail send to="youremail@yourdomain.com" subject=([/system identity get name] . " Backup " . [/system clock get date]) file=([/system identity get name] . "-" . [:pick [/system clock get date] 7 11] . [:pick [/system clock get date] 0 3] . [:pick [/system clock get date] 4 6] . ".backup"); :delay 10; /file rem [/file find name=([/system identity get name] . "-" . [:pick [/system clock get date] 7 11] . [:pick [/system clock get date] 0 3] . [:pick [/system clock get date] 4 6] . ".backup")]; :log info ("System Backup emailed at " . [/sys cl get time] . " " . [/sys cl get date])}
Make sure to replace “youremail@yourdomain.com” in the code. Maybe I will post this to the WIKI for other to see. I believe there is the simple (example) backup script posted there.
I hope you like this script. I spent some time building it, and it makes managing recurring backup files from many different routers much easier to deal with. ![]()
Okay, I found out what the problem was with the emailing? I think, I was sending the email to my email address that uses a sercure email server then i changed it to send to the unsecure email and it seems to work fine now so awsome!! but now i loaded the script to the working router not the test router and it dosent seem to send the email we are getting in the error log: 21:49:28 system,info changed scheduled script settings by joe
21:49:56 script,info System Backup emailed at 21:49:56 may/03/2006
21:50:00 system,error Error sending e-mail: abnormal termination (timeout)
21:50:46 system,error Error sending e-mail: abnormal termination (timeout)
::::::::::::: so i was wondering is there a rule that i can add to the firewall to allow this or something? I am not sure what we block with the firewall in the MT but we dont allow anyone to access the MT from outside the network unless there IP is in a spcieal allow area? THanks joe
You may need to email MT concerning this error. I have not had it occur to me before.
I get a error: sending e-mail: invalid TO address
my e-mail is ok
Someone that nows that fail
from terminal
tool e-mail set server x.x.x.x
tool e-mal set from someone@somewhere.com
x.x.x.x is the ip address of your mail server
someone@somewhere.com is a valid account on your mail server.
tk
Thanks, it works on one board
I have 5 router board, I try to copy the script to one another.
make the change in terminal
but I get this fail: sending e-mail: invalid TO address
and the mail is the same where it works
it’s the same ver. 2.9.23
what can be my problem ??
The syntax is the same. Be careful if you copy and paste multiple lines that it does not have hidden/invisible line breaks in the text. When you copy multiline text from MT to the clipboard, it puts in hidden line breaks at the end of each line that you have to manually remove using the backspace.
The router that works, I get 2 mails from every time it backup ??
The other router I get the same fail, and I have try all. and i can’t find wath is the problem. If I cut / past you source code in. it works on the first router.
But if I do the same on the other routers, it dont work
I am losing my hair, ![]()
Make sure that you can send email from all of the different router locations. Some ISPs block port 25 and this will stop you from being able to send email from the router at all. If smtp is not blocked, also make sure to deliver the message to an email address that is “local” to the smtp server you gave the router to use to send the mail. That way, the router does not need to authenticate with the mail server.
The 2 messages thing is strange. I can only assume the script entry is listed twice in that router therefore, it runs twice.
YOu can manually test is the script works by doing a “/sys scr run X” where X is the number of the script. Then do a “/log pr” to see if the script ran and posted to the log that it finished.
This happens to us as well, I think it’s the remote server not giving back a response quick enough or something so it tries again? I think the email client is ‘thin’ and therefore it’s expected.
Sam
Very interesting. I wonder why that has never happened to any of my routers before. I can’t imagine that my mail server or its Internet connection are faster than everyone elses. Strange…
I am having the same issue with the 2 emails being sent. Only one script and it does it on every router. Not sure what the deal is.
tk
Here is the exact entry from one of my routers. Like I said, I have never received 2 emails, only one.
[admin@hypewifi0001] system script> pr
0 name="ebackup" owner="admin" policy=ftp,reboot,read,write,policy,test,winbox,password
last-started=aug/02/2006 11:15:30 run-count=1
source=/system backup save name=([/system identity get name] . "-" . [:pick [/system
clock get date] 7 11] . [:pick [/system clock get date] 0 3] . [:pick [/system
clock get date] 4 6]); /tool e-mail send to="routerbackup@hypewifi.com"
subject=([/system identity get name] . " Backup " . [/system clock get date])
file=([/system identity get name] . "-" . [:pick [/system clock get date] 7
11] . [:pick [/system clock get date] 0 3] . [:pick [/system clock get date] 4
6] . ".backup"); :delay 10; /file rem [/file find name=([/system identity get
name] . "-" . [:pick [/system clock get date] 7 11] . [:pick [/system clock
get date] 0 3] . [:pick [/system clock get date] 4 6] . ".backup")]; :log info
("System Backup emailed at " . [/sys cl get time] . " " . [/sys cl get date])
[admin@hypewifi0001] system script>
I then have a acheduler entry that looks like:
name="email-backup" on-event=ebackup start-date=dec/31/1970 start-time=01:50:00
interval=1d run-count=0
Interesting script, is there a way to only make it email when there is a router configuration change? That way you don’t have many backup files that are the same if your routers config doesn’t change in months.
Good idea. Maybe the MT guys can tell us if there is flag somewhere that is set when any changes have been made in the router since last backup or since reboot or a flag that is set if a console connection has been made to the router. Then we could check for the flag and run backup if the flag is set.
Anybody have any ideas?
Actually, I poked around a little bit in the manual, and I saw the /system history commands. It would be pretty easy to have the script check and see if any commands have been issued in the router, and if so, go ahead with the backup. The only problem is that if you have the router running automated scripts to change settings under certain network conditions for example, then even those changes would look like something that should be backed up…
Although I see that in the history, it has a “by” field which is blank if the system executed the command on its own. If you login as admin and execute commands, then the “by” field on those commands is “admin”. If someone smarter than I could tell us how to issue a “/system history print count-only” which only showed commands from user “admin” then we could use that to know that a user has logged in and issued commands and we should go ahead and run a backup for good measure.
Any MT guys have an idea on how to execute a /sys his pr count-only command which would only count entries where the “by:” field is set to admin?
Thanks
I have found the fail, the identity name have special chart ![]()
So just so I understand, if the system identity has special characters in it, then it sends out the email twice. Is that what you meant?