/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])}
I get a error: sending e-mail: invalid TO addressHere 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.
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.Code: Select all/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])}
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.
The router that works, I get 2 mails from every time it backup ??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.
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.The 2 messages thing is strange. I can only assume the script entry is listed twice in that router therefore, it runs twice.
[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>
name="email-backup" on-event=ebackup start-date=dec/31/1970 start-time=01:50:00
interval=1d run-count=0
I have found the fail, the identity name have special chartMake 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.
/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])}}
Larry,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
i pasted this script into 2.9.41 no prob, i notice it wont go into 3.0, any ideas?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.
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.Code: Select all/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])}}