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"
 
hawkn
just joined
Posts: 5
Joined: Fri Dec 23, 2016 8:43 pm

Re: SCRIPT - Backup to FTP

Thu Jun 10, 2021 12:16 am

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

THANK YOU :D

Who is online

Users browsing this forum: No registered users and 19 guests