Schedule auto backup and rsc files from a Mikrotik using FTP

Last Updated or created 2024-03-14

Schedule below script after changing the first few lines

### Set local variables. Change the value between "" to reflect your environment. Do not delete quotation marks. 
:local ftpserver "ftpserver"
:local username "ftpuser"
:local password "ftppass"
:local ftppath "mikrotik/hapac2"

:local hostname [/system identity get name]
:local localfilename "$hostname-Backup-Daily";
:global thisdate [/system clock get date]
:global thistime [/system clock get time]
:global date ([:pick $thisdate 0 10])
:local remotebackup ([/system identity get name]."-".$date.".backup")
:local remotersc ([/system identity get name]."-".$date.".rsc")

### 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=($ftppath."/".$remotebackup) 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=($ftppath."/".$remotersc) upload=yes
:log info "Backup Uploaded Successfully"

Files are written on the FTP server like this:

MikroTikHAP1-2024-03-14.backup
MikroTikHAP1-2024-03-14.rsc

Spread the love

2 thoughts on “Schedule auto backup and rsc files from a Mikrotik using FTP”

  1. Great script, much respect to you. Let me make a correction: The script does not have a port for connection. Someone may want to specify a different port and it won’t work. The script works on version 7, but on version 6 the script works, but does not send via FTP, the data does not come.

    1. I’m running 7.x on all my mikrotiks, checked one with 7.17
      Uploads fine.
      Is your FTP configured correctly?

Leave a Reply

Your email address will not be published. Required fields are marked *