Backup Mikrotik config to FTP server

Set your ftpuser, ftppassword, ftppath, ftpserver accordingly

/system scheduler
add name=FTPBackup on-event=FTPBackup policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive start-date=jan/01/1970 start-time=00:00:00
/system script
add name=FTPBackup owner=admin policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive source=”:local hostname [/system identity get name];\r\
    \n:local ftppassword \”password\”\r\
    \n:local ftpuser \”ftp\”\r\
    \n:local ftppath \”/\”\r\
    \n:local ftpserver \”10.0.10.113\”\r\
    \n\r\
    \n:local date [/system clock get date]\r\
    \n# convert name of month to number\r\
    \n:local months (\”jan\”,\”feb\”,\”mar\”,\”apr\”,\”may\”,\”jun\”,\”jul\”,\”aug\”,\”sep\”,\”oct\”,\”nov\”,\”dec\”);\r\
    \n:local month [ :pick \$date 0 3 ];\r\
    \n:local mm ([ :find \$months \$month -1 ] + 1);\r\
    \n:if (\$mm < 10) do={ :set mm (\”0\” . \$mm); }\r\
    \n# set \$date to format DDMMYYYY\r\
    \n:set date ([:pick \$date 4 6] . \$mm . [:pick \$date 7 11])\r\
    \n\r\
    \n:local filename \”\$hostname-\$date\”;\r\
    \nexport compact file=\”\$filename\”\r\
    \n/system backup save name=\”\$filename\”\r\
    \n:log info \”Backup Created Successfully\”\r\
    \n/tool fetch address=\$ftpserver src-path=\”\$filename.rsc\” \\\r\
    \nuser=\$ftpuser mode=ftp password=\$ftppassword \\\r\
    \ndst-path=\”\$ftppath/\$filename.rsc\” upload=yes\r\
    \n/tool fetch address=\$ftpserver src-path=\”\$filename.backup\” \\\r\
    \nuser=\$ftpuser mode=ftp password=\$ftppassword \\\r\
    \ndst-path=\”\$ftppath/\$filename.backup\” upload=yes\r\
    \n:log info \”Backup Uploaded Successfully\”\r\
    \n/file remove \”\$filename.rsc\”\r\
    \n/file remove \”\$filename.backup\”\r\
    \n:log info \”Local Backup Files Deleted Successfully\””
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s