Page 1 of 1

Backup schedule

Posted: Fri Apr 21, 2006 10:51 pm
by EbeltoftsNet
How can I make backup schedule of the system and send the backup file to a mail adresse

ver. 2.9.8

Posted: Fri Apr 21, 2006 11:05 pm
by butche
There are some examples here:
http://www.mikrotik.com/docs/ros/2.8/ap ... g1.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

Posted: Tue May 02, 2006 5:17 am
by hecklertm
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. 8)

Posted: Thu May 04, 2006 8:59 am
by jhydzik
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

Posted: Thu May 04, 2006 3:47 pm
by hecklertm
You may need to email MT concerning this error. I have not had it occur to me before.

Posted: Sat Jul 29, 2006 2:45 am
by EbeltoftsNet
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. 8)
I get a error: sending e-mail: invalid TO address
my e-mail is ok
:?: Someone that nows that fail

Posted: Sat Jul 29, 2006 5:48 am
by tlkhorses
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

Posted: Mon Jul 31, 2006 1:59 pm
by EbeltoftsNet
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 ??

Posted: Mon Jul 31, 2006 6:22 pm
by hecklertm
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.

Posted: Tue Aug 01, 2006 3:12 pm
by EbeltoftsNet
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, :?

Posted: Tue Aug 01, 2006 6:03 pm
by hecklertm
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.

Posted: Tue Aug 01, 2006 7:49 pm
by changeip
The 2 messages thing is strange. I can only assume the script entry is listed twice in that router therefore, it runs twice.
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

Posted: Tue Aug 01, 2006 7:57 pm
by hecklertm
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...

Posted: Wed Aug 02, 2006 5:27 pm
by tlkhorses
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

Posted: Wed Aug 02, 2006 6:24 pm
by hecklertm
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

Posted: Fri Aug 04, 2006 7:34 pm
by voip4life
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.

Posted: Sun Aug 06, 2006 12:30 am
by hecklertm
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?

Posted: Sun Aug 06, 2006 5:25 am
by hecklertm
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

Posted: Thu Aug 17, 2006 9:11 pm
by EbeltoftsNet
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.
I have found the fail, the identity name have special chart :lol:

Posted: Thu Aug 17, 2006 9:53 pm
by hecklertm
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?

Posted: Fri Aug 18, 2006 12:25 am
by EbeltoftsNet
No, I use the same script on 5 routerboards, but it it don't work on all
and that was the problem with identity name.

and I post it wrong :shock:

Posted: Thu Aug 31, 2006 12:41 am
by luka5z
Hmm, ill start with simple question +/- in good topic... is there any program to read backup file... to see all config file of system !? I dont wanna backup notepad tree :P

Just say yes and paste the url to program, or just name of it, or say noooo
:?

Posted: Thu Aug 31, 2006 7:08 am
by tlkhorses
still getting two emails from most of my towers. Can't figure out why.

tk

Posted: Fri Sep 22, 2006 10:26 am
by invisible
the script working fine to mee

Posted: Fri Sep 22, 2006 10:27 am
by invisible
I use script on 7 MT alll of them working good

Posted: Tue Apr 24, 2007 7:05 am
by hecklertm
This is an update of my original post here. I have not had time to update my backup scripts since way back when I asked MT to add a find command to the system history command. Well, in 2.9.29, they added it for me, so now my backup script is able to determine whether the "admin" user has logged in and executed commands on the router and if so, it will do a backup that night, but if not, it just writes a log entry that a backup was not necessary. This way, you are not getting a backup every night when you really haven't changed anything.

Here is the updated code, you will note the differences revolving around the system history command and the setting of a counter to determine if new commands have been issued by user admin. I hope you like and all enjoy! I will update the wiki entry soon.
/system script add name=ebackup source={:global h ($h + 1 - 1); :if([:len [/sys history find by="admin"]] > $h) do {/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]); :global h [:len [/sys history find by="admin"]]} else {/tool e-mail send to="youremail@yourdomain.com" subject=([/system identity get name] . " Backup " . [/system clock get date]) body="No manual changes made. Backup not necessary"; :log info ("System Backup not necessary at " . [/sys cl get time] . " " . [/sys cl get date])}}
BTW: I share in the MT forums because at times, I really depend on getting help from others here too. Share your examples of anyting you have figured out that's not in the manual or the WIKI. Put it in the WIKI too! As I am sure you have found, digging around the forums is like pulling teeth sometimes.

Posted: Tue Apr 24, 2007 8:17 am
by mneumark
I'm not sure if i'm crazy or what, but when I setup a email backup script. I have if working for tons of time. Then when i setup OSPF on my routers and took out the route 0.0.0.0/0 in /ip route it will no longer send out the emails and says invalid. If i add 0.0.0.0/0 back in the script works just like a charm.

Any hints on how to get around this?

Matt

Posted: Wed May 09, 2007 5:26 pm
by lcrhea25
I have got this script working fine on the first unit I put it on. But the rest are giving me this error in the log. Error sending e-mail: error talking to server. They are all running the same version. Does anybody have any ideas for me on this?

Thank you

Larry

Posted: Wed May 09, 2007 5:38 pm
by hecklertm
Can't tell off hand. It sounds like the settings under "/tool e-mail" may not be the same, or you have a firewall issue.

Posted: Thu May 10, 2007 1:46 am
by mneumark
I have got this script working fine on the first unit I put it on. But the rest are giving me this error in the log. Error sending e-mail: error talking to server. They are all running the same version. Does anybody have any ideas for me on this?

Thank you

Larry
Larry,

I have the same issue when i don't have the route 0.0.0.0/0 in my routing table. The only reason i don't have one in my routing table is due to ospf. I put on in and it works great.

Matt

Posted: Thu May 10, 2007 4:46 am
by hecklertm
If that fix does work, I would suggest you send support a request to examine the problem for a real fix.

Re:

Posted: Mon Aug 06, 2007 1:07 pm
by Jrslick22
This is an update of my original post here. I have not had time to update my backup scripts since way back when I asked MT to add a find command to the system history command. Well, in 2.9.29, they added it for me, so now my backup script is able to determine whether the "admin" user has logged in and executed commands on the router and if so, it will do a backup that night, but if not, it just writes a log entry that a backup was not necessary. This way, you are not getting a backup every night when you really haven't changed anything.

Here is the updated code, you will note the differences revolving around the system history command and the setting of a counter to determine if new commands have been issued by user admin. I hope you like and all enjoy! I will update the wiki entry soon.
/system script add name=ebackup source={:global h ($h + 1 - 1); :if([:len [/sys history find by="admin"]] > $h) do {/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]); :global h [:len [/sys history find by="admin"]]} else {/tool e-mail send to="youremail@yourdomain.com" subject=([/system identity get name] . " Backup " . [/system clock get date]) body="No manual changes made. Backup not necessary"; :log info ("System Backup not necessary at " . [/sys cl get time] . " " . [/sys cl get date])}}
BTW: I share in the MT forums because at times, I really depend on getting help from others here too. Share your examples of anyting you have figured out that's not in the manual or the WIKI. Put it in the WIKI too! As I am sure you have found, digging around the forums is like pulling teeth sometimes.
i pasted this script into 2.9.41 no prob, i notice it wont go into 3.0, any ideas?

also when i run the script the log shows, Error sending e-mail: error connecting to server
System Backup emailed at 10:01:10 aug/06/2007

am i to assume i need to set up a smtp server? where whould i do this?

thanks

Re: Backup schedule

Posted: Mon Aug 06, 2007 1:19 pm
by Jrslick22
found it.


thanks anyway, great script.

Re: Backup schedule

Posted: Tue Aug 07, 2007 5:34 am
by hecklertm
No prob.

Re: Backup schedule

Posted: Tue Aug 07, 2007 6:30 am
by EbeltoftsNet
Hi
Have try to run on ver. 2.9.44
it don't work, I cant see anything that happens in my log
I try to run the script, nothing happens. The old backup was fine

any one that now what that can be the problem

Thanks

Re: Backup schedule

Posted: Sat May 03, 2008 4:51 pm
by azspvdip
I have the same problem the system responds : system,e-mail,error Error sending e-mail: abnormal termination (timeout)
I use OSPF routig but if i use ping tool the smtp server reply is ok....
my software version is 3.0

HELP help help :(