Community discussions

MikroTik App
 
14m3r
just joined
Topic Author
Posts: 1
Joined: Wed Sep 01, 2021 11:12 am

Backup via FTP using separate directories

Wed Sep 01, 2021 11:50 am

There is a script that copies the config file to ftp. It's necessary to modify it in such a way that when uploading, a new catalog with month and year is automatically created, for example sep-2021/object_name.rsc or 09-2021/object_name.rsc. If someone knows a solution, please help modify the script.
# Get the date in the format dd-mm-yyyy
:local tmpdate [/system clock get date];
:local months ("jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec");
:local month [ :pick $tmpdate 0 3 ];
:local mm ([ :find $months $month -1 ] + 1);
:if ($mm < 10) do={ :set mm ("0" . $mm); }
:local date ([:pick $tmpdate 4 6] ."-" . $mm ."-" . [:pick $tmpdate 7 11])

# Set params for FTP
:local myname "object_name"
:local fname ($myname."_".$date);
#:local bname ($myname."_".$date.".backup");
:local ename ($myname."_".$date.".rsc");
:local ftpuser "user";
:local ftppass "pwd";
:local ftpaddr "192.168.0.123";

# Backup settings
#/system backup save name=$fname dont=yes;
#:delay 10;
/export file=$fname
:delay 10;

# Upload files to FTP
#/tool fetch address=$ftpaddr src-path=$bname user=$ftpuser password=$ftppass port=21 upload=yes mode=ftp dst-path=$bname
#:delay 15;
/tool fetch address=$ftpaddr src-path=$ename user=$ftpuser password=$ftppass port=21 upload=yes mode=ftp dst-path=$ename

# Remove files from device
#/file remove $bname;
/file remove $ename;
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Backup via FTP using separate directories

Wed Sep 01, 2021 3:17 pm

Better use ISO standard yyyy-mm-dd
When sorted on name, are sorted....

Do not schedule the backup of dozen of device at same time...

The "export" do not save certificates, ssh host key, dude database, user-manager database, internal files for hotspot.

Some aspect of coding fixed:
# Get the date in the format yyyy-mm-dd
:local tmpdate [/system clock get date]
:local months {jan="01";feb="02";mar="03";apr="04";may="05";jun="06";jul="07";aug="08";sep="09";oct="10";nov="11";dec="12"}
:local date "$[:pick $tmpdate 7 11]-$($months->[ :pick $tmpdate 0 3 ])-$[:pick $tmpdate 4 6]"
# Set params for FTP
:local myname  "object_name"
:local fname   "$myname_$date"
# :local bname   "$myname_$date.backup"
:local ename   "$myname_$date.rsc"
:local ftpuser "user"
:local ftppass "pwd"
:local ftpaddr "192.168.0.123"

# Backup settings
# /system backup save dont-encrypt=yes name=$fname 
# :delay 10s
/export file=$fname
:delay 10s

# Upload files to FTP
# /tool fetch address=$ftpaddr src-path=$bname user=$ftpuser password=$ftppass port=21 upload=yes mode=ftp dst-path=$bname
# :delay 15s
/tool fetch address=$ftpaddr src-path=$ename user=$ftpuser password=$ftppass port=21 upload=yes mode=ftp dst-path=$ename

# Remove files from device
# /file remove [find where name=$bname]
/file remove [find where name=$ename]

If the ftp destination is a one non-smips Routerboard, the creation of folders can be scheduled on remote device.

Who is online

Users browsing this forum: No registered users and 8 guests