I searched for this script on the forum, but I found only few pieces tat didn't fit exactly what I was looking for.
I'm posting here only for you reference, maybe it could be helpfull to someone. We have it in production since a couple of weeks.
The following script is creating a local backup and export (we launch it daily), then upload these files to and external FTP server adding the date to the filename. It let a local version of the files that are replaced every day to avoid lots of files and running out of space (if you want you can uncomment 3 lines and delete the local backup).
Copy and paste this in your script text.
--------------
Code: Select all
### Set local variables. Change the value between "" to reflect your environment. Do not delete quotation marks.
:local ftpserver "FTP-SERVER-FQDN_or_IP-ADDRESS"
:local username "FTP-SERVER-USERNAME"
:local password "FTP-SERVER-PASSWORD"
### Set Local and Remote Filename variables. Do not change this unless you want to edit the format of the filename.
### Default "local file name" is always the same to avoid lots of files and running out of space, "remote file name" uploaded to FTP has the date
:local hostname [/system identity get name]
:local date ([:pick [/system clock get date] 7 11] \
. [:pick [/system clock get date] 0 3] \
. [:pick [/system clock get date] 4 6]);
:local localfilename "$hostname-Backup-Daily";
:local remotefilename "$hostname-$date";
### Enable for Debug removing staing hash in the following lines
:log info "$localfilename";
:log info "$remotefilename";
:log info "$hostname";
:log info "$date";
### Stating the Backup
:log info "STARTING BACKUP";
### Create backup file and export the config.
export compact file="$localfilename"
/system backup save name="$localfilename"
:log info "Backup Created Successfully"
### Upload config file to FTP server.
/tool fetch address=$ftpserver src-path="$localfilename.backup" \
user=$username mode=ftp password=$password \
dst-path="$remotefilename.backup" upload=yes
:log info "Config Uploaded Successfully"
### Upload backup file to FTP server.
/tool fetch address=$ftpserver src-path="$localfilename.rsc" \
user=$username mode=ftp password=$password \
dst-path="$remotefilename.rsc" upload=yes
:log info "Backup Uploaded Successfully"
### Wait 2 second before doing anything
delay 2;
### Remove starting hash in the following lines to delete created backup files once they have been uploaded. I usually let them there because it's useful having them ready.
#/file remove "$localfilename.backup"
#/file remove "$localfilename.rsc"
#:log info "Local Backup Files Deleted Successfully"
### Finishing the Backup
:log info "BACKUP FINISHED";
Code: Select all
/system scheduler
add interval=1d name=Backup_Daily on-event="/system script run Backup_Daily" \
policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon \
start-date=jan/01/1970 start-time=22:00:00
/system script
add dont-require-permissions=no name=Backup_Daily owner=admin policy=\
ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon source="#\
## Set local variables. Change the value between \"\" to reflect your envi\
ronment. Do not delete quotation marks. \r\
\n:local ftpserver \"FTP-SERVER-FQDN_or_IP-ADDRESS\"\r\
\n:local username \"FTP-SERVER-USERNAME\"\r\
\n:local password \"FTP-SERVER-PASSWORD\"\r\
\n\r\
\n### Set Local Filename and Remote Filename variables. Do not change this\
\_unless you want to edit the format of the filename.\r\
\n### Default \"local file name\" is always the same to avoid lots of file\
s and running out of space\r\
\n:local hostname [/system identity get name]\r\
\n:local date ([:pick [/system clock get date] 7 11] \\\r\
\n. [:pick [/system clock get date] 0 3] \\\r\
\n. [:pick [/system clock get date] 4 6]);\r\
\n:local localfilename \"\$hostname-Backup-Daily\";\r\
\n:local remotefilename \"\$hostname-\$date\";\r\
\n\r\
\n### Enable for Debug removing staing hash in the following lines\r\
\n:log info \"\$localfilename\";\r\
\n:log info \"\$remotefilename\";\r\
\n:log info \"\$hostname\";\r\
\n:log info \"\$date\";\r\
\n\r\
\n### Stating the Backup\r\
\n:log info \"STARTING BACKUP\";\r\
\n\r\
\n# Create backup file and export the config.\r\
\nexport compact file=\"\$localfilename\"\r\
\n/system backup save name=\"\$localfilename\"\r\
\n:log info \"Backup Created Successfully\"\r\
\n\r\
\n# Upload config file to FTP server.\r\
\n/tool fetch address=\$ftpserver src-path=\"\$localfilename.backup\" \\\r\
\nuser=\$username mode=ftp password=\$password \\\r\
\ndst-path=\"\$remotefilename.backup\" upload=yes\r\
\n:log info \"Config Uploaded Successfully\"\r\
\n\r\
\n# Upload backup file to FTP server.\r\
\n/tool fetch address=\$ftpserver src-path=\"\$localfilename.rsc\" \\\r\
\nuser=\$username mode=ftp password=\$password \\\r\
\ndst-path=\"\$remotefilename.rsc\" upload=yes\r\
\n:log info \"Backup Uploaded Successfully\"\r\
\n\r\
\n### Wait 2 second before doing anything\r\
\ndelay 2;\r\
\n\r\
\n### Remove starting hash in the following lines to delete created backup\
\_files once they have been uploaded\r\
\n#/file remove \"\$localfilename.backup\"\r\
\n#/file remove \"\$localfilename.rsc\"\r\
\n#:log info \"Local Backup Files Deleted Successfully\"\r\
\n\r\
\n### Finishing the Backup\r\
\n:log info \"BACKUP FINISHED\";\r\
\n"
Hope it will be useful to everyone.
Francesco Capuano