Page 1 of 1

Script to email configuration backup

Posted: Thu Feb 18, 2010 8:38 am
by bokad
I have a script that exports the current config and then e-mails it to me. This script is called from the scheduler. In v3.13 everything worked fine. In v3.28 this stopped working. The script still works when run manually but no longer works when called from the scheduler. I see from that run count that the scheduler is in fact calling the scipt but for some reason the script never creates the backup file when called from the scheduler. Any ideas?

/system scheduler
add comment="" disabled=no interval=5m name="conf exp test" on-event=\
"/system script run \"Config Export\"" policy=\
reboot,read,write,policy,test,password,sniff,sensitive start-date=\
jan/01/1970 start-time=03:00:00

In brief:
/system script run "Config Export"


/system script
add name="Config Export" policy=\
ftp,reboot,read,write,policy,test,winbox,password,sniff,sensitive source="\
/export file=daily_export\r\
\n/tool e-mail send to=\"me@here.org\" subject=([/system iden\
tity get name] . \" \" . [/system clock get time] . \" \" . [/system clock\
\_get date] . \" Export\") file=daily_export.rsc\r\
\n\r\
\n"

In brief:
/export file=daily_export
/tool e-mail send to="me@here.org" subject=([/system identity get name] . " " . [/system clock get time] . " " . [/system clock get date] . " Export") file=daily_export.rsc

Re: Script to email configuration backup

Posted: Sun Feb 21, 2010 8:06 am
by bokad
I'm willing to pay a consultant for help if someone has the answer...

Re: Script to email configuration backup

Posted: Sun Feb 21, 2010 1:22 pm
by SurferTim
Does it send the email if run by the scheduler? Or does it fail completely.
In the scheduler, I use just the script name in the on-event entry. Like "on-event=ConfigExport". The system scheduler knows to run it with the script interpreter.

Re: Script to email configuration backup

Posted: Tue Mar 09, 2010 11:05 pm
by nest
maybe because the email is being sent before the exported file has been closed, therefore it does not send it? Try changing it two scheduled scripts, one minute apart, one to create the export, one to send it. See if it then works?

Re: Script to email configuration backup

Posted: Wed Mar 10, 2010 12:37 am
by Rattlehead
I know this is a stupid question, but does it have to be written via the CLI?
I had a huge amount of problem running and getting mine to work, but I ended using winbox and the scheduler and scripts in there, it worked pertectly

Re: Script to email configuration backup

Posted: Wed Mar 10, 2010 7:16 pm
by nest
Rattlehead; I don't see anywhere here where it says you have to do this via the CLI. So of course, you can use winbox to create schedules and scripts.

Re: Script to email configuration backup

Posted: Thu Mar 11, 2010 5:10 pm
by Rattlehead
OK
Well look into Winbox
CREATE THE FILE BACKUP
System>Scripts>Add.
Call Script : "backupscript"
Policy: Choose All
in the sourcebox type :
/system backup save name=xxxxx
// This of course can be anything you want it to be
Click Apply

Click Add again
CREATE THE MAIL SCRIPT
Call Script : "mailscript"
Policy: Choose All
in the sourcebox type :
/tool e-mail send file=xxxxx.backup to=xxxx@xxxxxx.ie subject=[/system identity get name]
Click Apply

There you have your two scripts so now you need to make a schedule of these.

Again in Winbox
CREATE THE SCHEDULE TO RUN THESE ABOVE SCRIPTS
System>Scheduler>Add
Name this one "Backup&MailScript"
The time and all that you can set yourself
In the OnEvents filed type
/system script run backupscript
/system script run mailscript
Set the Policies on that to all options and apply.

There you go, mine is currently sending me backups on a daily basics at 07:30 to my work mail account. I hope this helps