Community discussions

MikroTik App
 
mattsawatzky
newbie
Topic Author
Posts: 41
Joined: Wed Oct 27, 2010 12:43 am

SCRIPT - Backup to FTP

Wed Nov 27, 2013 10:43 pm

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"
 
googlebot
just joined
Posts: 1
Joined: Fri Feb 20, 2015 11:33 pm

Re: SCRIPT - Backup to FTP

Fri Feb 20, 2015 11:44 pm

i have been googling for a good backup script and this one is by far the best one i have found

Who is online

Users browsing this forum: beeyev and 24 guests