Администрирование
May 28

Бэкап Микротика скриптом

Добавляем скрипт в раздел System → Scripts ( на примере бэкапа для микротика Mikrotik_MY)

Резервирование происходит по протоколу FTP, поэтому нужны — ip сервера ftp, логин (mikrotik_backup) и пароль для доступа.

#pull date

: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])

#FTP access

:local myname "Mikrotik_MY"
:local fname ($myname."_".$date);
:local bname ($myname."_".$date.".backup");
:local ename ($myname."_".$date.".rsc");
:local ftpuser "mikrotik_backup";
:local ftppass "Пароль_mikrotik_backup";
:local ftpaddr "IP_сервера_FTP";

#create backup

/system backup save name=$fname password=;
:delay 10;
/export file=$fname
:delay 10;

#pull backup 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
:delay 15;

#delete files on mikrotik

/file remove $bname;
/file remove $ename;