Mainos / Advertisement:

RouterOS Backup

Kohteesta Taisto
Loikkaa: valikkoon, hakuun
Tämä sivu sisältää muutoksia, joita ei ole merkitty käännettäväksi.


FTP

Tässä on esimerkki backup scripti joka luo automaattisesti laitteen nimellä, aika ja päivämäärän mukaan kaksi backup tiedostoa Exportattu ja .backup tiedoston. Lisäksi tämä scripti lähettää ne FTP yhteydellä määritetylle palvelimelle. Tämä scripti on testattu RouterOS 6.26.


Muokkaa seuraavasta scriptistä:

ftphost = FTP palvelimen IP-osoite
ftpuser = FTP palvelimen käyttäjänimi, jolla oikeus lukea sekä kirjoittaa palvelimelle
ftppassword = FTP palvelimen käyttäjänimen salasana.
ftppath = FTP palvelimen hakemisto jonne tallennetaan. Esimerkiksi root / tai /files alihakemisto.

Scriptin ajettua palvelimelle tallentuu esimerkiksi:

 UMDB-MikroTik-20150314-234109.rsc
 UMDB-MikroTik-20150314-234109.backup

Kopioi alla oleva script (ehkä helpompi graafisena)

 /system script add name=autobackup source="liitä tähän alla oleva koodi"


  # automated backup 2 External ftp.
  
  # ftp configuration
  :local ftphost "10.0.0.52"
  :local ftpuser "mikrotik"
  :local ftppassword "password"
  :local ftppath "/"
  
  # 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 user manager backup - file name will be UMDB-servername-date-time.umb
  :local fname ("/UMDB-".[/system identity get name]."-".$ds."-".$ts.".umb")
  # file name for system backup - file name will be UMDB-servername-date-time.backup
  :local fname1 ("/UMDB-".[/system identity get name]."-".$ds."-".$ts.".backup")
  # file name for config export - file name will be UMDB-servername-date-time.rsc
  :local fname2 ("/UMDB-".[/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/2)."
  /tool fetch address="$ftphost" src-path=$fname1 user="$ftpuser" mode=ftp password="$ftppassword" dst-path="$ftppath/$fname1" upload=yes
  # upload the config export
  :log info message="Uploading config export (2/2)."
  /tool fetch address="$ftphost" src-path=$fname2 user="$ftpuser" mode=ftp password="$ftppassword" dst-path="$ftppath/$fname2" upload=yes
  
  # 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] "UMDB-"]]!="nil") do={/file remove $i}; }
  :log info message="Configuration backup finished.";


Kokeile ajaa backup scripti

  /system script run autobackup

Ajastettuna, esimerkiksi joka päivä ajettuna kello 24:

 /system scheduler add name=autobackup start-time=startup on-event="liitä tähän koodi tai scripti" disabled=no interval=1d 00:00:00

Lähde: http://harry.subnetworx.de/2013/12/27/automated-routeros-backup-ftp/

== Sähköposti ==

 ### Modify these values to match your requirements ####
 
 #Your email address to receive the backups
 :local toemail "you@example.com"
 
 #The From address (you can use your own address if you want)
 :local fromemail "mikrotik@example.com"
 
 #A mail server your machines can send through
 :local emailserver "smtp.example.com"
 
 ############## Don’t edit below this line ##############
   
 :local sysname [/system identity get name]
 :local textfilename
 :local backupfilename
 :local time [/system clock get time]
 :local date [/system clock get date]
 :local newdate "";
 :for i from=0 to=([:len $date]-1) do={ :local tmp [:pick $date $i];
 :if ($tmp !="/") do={ :set newdate "$newdate$tmp" }
 :if ($tmp ="/") do={}
 }
 #check for spaces in system identity to replace with underscores
 :if ([:find $sysname " "] !=0) do={
 :local name $sysname;
 :local newname "";
 :for i from=0 to=([:len $name]-1) do={ :local tmp [:pick $name $i];
 :if ($tmp !=" ") do={ :set newname "$newname$tmp" }
 :if ($tmp =" ") do={ :set newname "$newname_" }
 }
 :set sysname $newname;
 }
 :set textfilename ($"newdate" . "-" . $"sysname" . ".rsc")
 :set backupfilename ($"newdate" . "-" . $"sysname" . ".backup")
 :execute [/export file=$"textfilename"]
 :execute [/system backup save name=$"backupfilename"]
 #Allow time for export to complete
 :delay 2s
 
 #email copies
 :log info "Emailing backups"
 /tool e-mail send to=$"toemail" from=$"fromemail" server=[:resolve $emailserver] port=25 subject="[Config Backup] $sysname $time" file=$"textfilename"
 #Send as different subjects to force GMail to treat as new message thread.
 :local time [/system clock get time]
 /tool e-mail send to=$"toemail" from=$"fromemail" server=[:resolve $emailserver] port=25 subject="[Config Backup] $sysname $time"  file=$"backupfilename"
  
 #Allow time to send
 :delay 10s
 
 #delete copies
 /file remove $textfilename
 /file remove $backupfilename


Lähde: http://www.mikrotik-routeros.com/2014/04/gmail-google-drive-mikrotik-scripting-automated-backups-folder/

Mainos / Advertisement: