Back-up automat mikrotik

Configurare noua (How To)

Situatie

Facem back-up automat la mikrotik

Solutie

Pasi de urmat

Avem urmatorul Script.

# automated backup 2 External ftp

 

# ftp configuration

:local ftphost “<<FTP IP>>”

:local ftpuser “<<FTP USERNAME>>”

:local ftppassword “<<FTP PASSWORD>>”

:local ftppath “<<FTP PATH>>”

 

# months array

:local months (“jan”,”feb”,”mar”,”apr”,”may”,”jun”,”jul”,”aug”,”sep”,”oct”,”nov”,”dec”);

 

# get time

:local ts [/system clock get time]

:set ts ([:pick $ts 0 2].[:pick $ts 3 5].[:pick $ts 6 8])

 

# get Date

:local ds [/system clock get date]

# convert name of month to number

:local month [ :pick $ds 0 3 ];

:local mm ([ :find $months $month -1 ] + 1);

:if ($mm < 10) do={ :set mm (“0″ . $mm); }

# set $ds to format YYYY-MM-DD

:set ds ([:pick $ds 7 11] . $mm . [:pick $ds 4 6])

 

# file name for system backup – file name will be servername-date-time.backup

:local fname1 ([/system identity get name].”-“.$ds.”-“.$ts.”.backup”)

# file name for config export – file name will be servername-date-time.rsc

:local fname2 ([/system identity get name].”-“.$ds.”-“.$ts.”.rsc”)

 

# backup the data

/system backup save name=$fname1

:log info message=”System backup finished (1/2).”;

/export compact file=$fname2

:log info message=”Config export finished (2/2).”

 

# upload the system backup

:log info message=”Uploading system backup (1/4).”

/tool fetch address=”$ftphost” src-path=$fname1 user=”$ftpuser” mode=ftp password=”$ftppassword” dst-path=”$ftppath/$fname1″ upload=yes

:log info message=”System backup uploaded (2/4).”

# upload the config export

:log info message=”Uploading config export (3/4).”

/tool fetch address=”$ftphost” src-path=$fname2 user=”$ftpuser” mode=ftp password=”$ftppassword” dst-path=”$ftppath/$fname2″ upload=yes

:log info message=”Config export uploaded (4/4).”

 

# delay time to finish the upload – increase it if your backup file is big

:delay 60s;

# find file name start with UMDB- then remove

:foreach i in=[/file find] do={ :if ([:typeof [:find [/file get $i name] ([/system identity get name].”-“.$ds.”-“.$ts)]]!=”nil”) do={/file remove $i}; }

:log info message=”Configuration backup finished;

Se urmeaza calea

System > Scripts > Add Script (+)

Modificam numele cu “Script-FTP-AutoBackup” la fel ca in poza.

Si modificam la script aceste linii cu datele de logare.

Se acceseaza urmatoarea cale.

System > Scheduler > New Schedule (+)

Punem un nume, o data la care sa inceapa , ora la care incepe, si intervalul de timp in care se face backup.

Dupa care punem numele scriptului.

Si se va efectua backup-ul automat.

Tip solutie

Permanent

Voteaza

(31 din 75 persoane apreciaza acest articol)

Despre Autor