Community discussions

 
EbeltoftsNet
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 90
Joined: Wed Mar 15, 2006 4:35 pm
Location: Denmark

Backup schedule

Fri Apr 21, 2006 10:51 pm

How can I make backup schedule of the system and send the backup file to a mail adresse

ver. 2.9.8
 
User avatar
butche
Trainer
Trainer
Posts: 428
Joined: Fri May 28, 2004 6:14 pm
Location: Missouri, USA
Contact:

Fri Apr 21, 2006 11:05 pm

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
--
Butch Evans
Mikrotik Certified Trainer
Mikrotik Certified Consultant
BLOG: blog.butchevans.com
http://store.wispgear.net/
 
User avatar
hecklertm
Member Candidate
Member Candidate
Posts: 165
Joined: Fri Jun 24, 2005 5:12 am
Location: US

Tue May 02, 2006 5:17 am

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)
 
jhydzik
just joined
Posts: 16
Joined: Sat Dec 17, 2005 10:29 am

Thu May 04, 2006 8:59 am

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
 
User avatar
hecklertm
Member Candidate
Member Candidate
Posts: 165
Joined: Fri Jun 24, 2005 5:12 am
Location: US

Thu May 04, 2006 3:47 pm

You may need to email MT concerning this error. I have not had it occur to me before.
 
EbeltoftsNet
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 90
Joined: Wed Mar 15, 2006 4:35 pm
Location: Denmark

Sat Jul 29, 2006 2:45 am

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
 
tlkhorses
Frequent Visitor
Frequent Visitor
Posts: 82
Joined: Wed Jun 22, 2005 11:06 pm

Sat Jul 29, 2006 5:48 am

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
Terri Kelley
Farm to Market LP
Broadband Wireless
 
EbeltoftsNet
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 90
Joined: Wed Mar 15, 2006 4:35 pm
Location: Denmark

Mon Jul 31, 2006 1:59 pm

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 ??
 
User avatar
hecklertm
Member Candidate
Member Candidate
Posts: 165
Joined: Fri Jun 24, 2005 5:12 am
Location: US

Mon Jul 31, 2006 6:22 pm

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.
 
EbeltoftsNet
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 90
Joined: Wed Mar 15, 2006 4:35 pm
Location: Denmark

Tue Aug 01, 2006 3:12 pm

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, :?
 
User avatar
hecklertm
Member Candidate
Member Candidate
Posts: 165
Joined: Fri Jun 24, 2005 5:12 am
Location: US

Tue Aug 01, 2006 6:03 pm

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.
 
changeip
Forum Guru
Forum Guru
Posts: 3803
Joined: Fri May 28, 2004 5:22 pm

Tue Aug 01, 2006 7:49 pm

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
 
User avatar
hecklertm
Member Candidate
Member Candidate
Posts: 165
Joined: Fri Jun 24, 2005 5:12 am
Location: US

Tue Aug 01, 2006 7:57 pm

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...
 
tlkhorses
Frequent Visitor
Frequent Visitor
Posts: 82
Joined: Wed Jun 22, 2005 11:06 pm

Wed Aug 02, 2006 5:27 pm

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
Terri Kelley
Farm to Market LP
Broadband Wireless
 
User avatar
hecklertm
Member Candidate
Member Candidate
Posts: 165
Joined: Fri Jun 24, 2005 5:12 am
Location: US

Wed Aug 02, 2006 6:24 pm

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
 
voip4life
Frequent Visitor
Frequent Visitor
Posts: 52
Joined: Fri Dec 16, 2005 11:52 pm
Location: US

Fri Aug 04, 2006 7:34 pm

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.
 
User avatar
hecklertm
Member Candidate
Member Candidate
Posts: 165
Joined: Fri Jun 24, 2005 5:12 am
Location: US

Sun Aug 06, 2006 12:30 am

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?
 
User avatar
hecklertm
Member Candidate
Member Candidate
Posts: 165
Joined: Fri Jun 24, 2005 5:12 am
Location: US

Sun Aug 06, 2006 5:25 am

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
 
EbeltoftsNet
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 90
Joined: Wed Mar 15, 2006 4:35 pm
Location: Denmark

Thu Aug 17, 2006 9:11 pm

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:
 
User avatar
hecklertm
Member Candidate
Member Candidate
Posts: 165
Joined: Fri Jun 24, 2005 5:12 am
Location: US

Thu Aug 17, 2006 9:53 pm

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?
 
EbeltoftsNet
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 90
Joined: Wed Mar 15, 2006 4:35 pm
Location: Denmark

Fri Aug 18, 2006 12:25 am

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:
 
luka5z
just joined
Posts: 12
Joined: Sat Aug 26, 2006 11:50 pm

Thu Aug 31, 2006 12:41 am

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
:?
 
tlkhorses
Frequent Visitor
Frequent Visitor
Posts: 82
Joined: Wed Jun 22, 2005 11:06 pm

Thu Aug 31, 2006 7:08 am

still getting two emails from most of my towers. Can't figure out why.

tk
Terri Kelley
Farm to Market LP
Broadband Wireless
 
invisible
just joined
Posts: 9
Joined: Thu Sep 14, 2006 1:35 pm
Contact:

Fri Sep 22, 2006 10:26 am

the script working fine to mee
 
invisible
just joined
Posts: 9
Joined: Thu Sep 14, 2006 1:35 pm
Contact:

Fri Sep 22, 2006 10:27 am

I use script on 7 MT alll of them working good
 
User avatar
hecklertm
Member Candidate
Member Candidate
Posts: 165
Joined: Fri Jun 24, 2005 5:12 am
Location: US

Tue Apr 24, 2007 7:05 am

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.
Last edited by hecklertm on Fri Apr 27, 2007 6:55 am, edited 1 time in total.
 
User avatar
mneumark
Member
Member
Posts: 375
Joined: Thu Jun 08, 2006 7:20 am
Location: Escalon, CA
Contact:

Tue Apr 24, 2007 8:17 am

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
 
lcrhea25
Member Candidate
Member Candidate
Posts: 114
Joined: Wed Nov 29, 2006 4:30 pm

Wed May 09, 2007 5:26 pm

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
 
User avatar
hecklertm
Member Candidate
Member Candidate
Posts: 165
Joined: Fri Jun 24, 2005 5:12 am
Location: US

Wed May 09, 2007 5:38 pm

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.
 
User avatar
mneumark
Member
Member
Posts: 375
Joined: Thu Jun 08, 2006 7:20 am
Location: Escalon, CA
Contact:

Thu May 10, 2007 1:46 am

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
 
User avatar
hecklertm
Member Candidate
Member Candidate
Posts: 165
Joined: Fri Jun 24, 2005 5:12 am
Location: US

Thu May 10, 2007 4:46 am

If that fix does work, I would suggest you send support a request to examine the problem for a real fix.
 
Jrslick22
Member Candidate
Member Candidate
Posts: 167
Joined: Sun Feb 06, 2005 3:25 am

Re:

Mon Aug 06, 2007 1:07 pm

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
 
Jrslick22
Member Candidate
Member Candidate
Posts: 167
Joined: Sun Feb 06, 2005 3:25 am

Re: Backup schedule

Mon Aug 06, 2007 1:19 pm

found it.


thanks anyway, great script.
 
User avatar
hecklertm
Member Candidate
Member Candidate
Posts: 165
Joined: Fri Jun 24, 2005 5:12 am
Location: US

Re: Backup schedule

Tue Aug 07, 2007 5:34 am

No prob.
 
EbeltoftsNet
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 90
Joined: Wed Mar 15, 2006 4:35 pm
Location: Denmark

Re: Backup schedule

Tue Aug 07, 2007 6:30 am

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
 
azspvdip
just joined
Posts: 2
Joined: Sat May 03, 2008 4:44 pm

Re: Backup schedule

Sat May 03, 2008 4:51 pm

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 :(

Who is online

Users browsing this forum: No registered users and 10 guests