SCRIPT - Backup to FTP

Here’s a script I just wrote for backing up a .rsc and .backup file to FTP. Currently only tested on ROS 6.6.

# Set local variables. Change the value in "" to reflect your environment.

:local hostname "router_hostname";
:local password "changeme"
:local username "changeme"
:local ftpserver "ftp.example.com"

# Set Filename variables. Do not change this unless you want to edit the format of the filename.

:local time [/system clock get time];
:local date ([:pick [/system clock get date] 0 3]  \
. [:pick [/system clock get date] 4 6] \
. [:pick [/system clock get date] 7 11]);
:local filename "$hostname-$date-$time";

# Create backup file and export the config.

export compact file="$filename"
/system backup save name="$filename"

:log info "Backup Created Successfully"

# Upload config file to FTP server.

/tool fetch address=$ftpserver src-path="$filename.rsc" \
user=$username mode=ftp password=$password \
dst-path="/Backups/$filename.rsc" upload=yes

# Upload backup file to FTP server.

/tool fetch address=$ftpserver src-path="$filename.backup" \
user=$username mode=ftp password=$password \
dst-path="$filename.backup" upload=yes

:log info "Backup Uploaded Successfully"

# Delete created backup files once they have been uploaded
# so they don't accumulate and fill up storage space on the router.

/file remove "$filename.rsc"
/file remove "$filename.backup"

:log info "Local Backup Files Deleted Successfully"

You just made my day, been fighting for a long time trying to make upload to ftp.

THANK YOU :smiley: