Mainos / Advertisement:

Ero sivun ”RouterOS Backup” versioiden välillä

Kohteesta Taisto
Siirry navigaatioon Siirry hakuun
 
(8 välissä olevaa versiota samalta käyttäjältä ei näytetä)
Rivi 1: Rivi 1:
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.  
+
<languages/>
 +
<translate>
 +
 
 +
== 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ä:
 
Muokkaa seuraavasta scriptistä:
Rivi 17: Rivi 23:
 
   /system script add name=autobackup source="liitä tähän alla oleva koodi"
 
   /system script add name=autobackup source="liitä tähän alla oleva koodi"
  
 +
 +
<syntaxhighlight lang="lua">
  
 
   # automated backup 2 External ftp.
 
   # automated backup 2 External ftp.
Rivi 51: Rivi 59:
 
   # backup the data
 
   # backup the data
 
   /system backup save name=$fname1
 
   /system backup save name=$fname1
   :log info message="System backup finished (2/3).";
+
   :log info message="System backup finished (1/2).";
 
   /export compact file=$fname2
 
   /export compact file=$fname2
   :log info message="Config export finished (3/3)."
+
   :log info message="Config export finished (2/2)."
 
    
 
    
 
   # upload the system backup
 
   # upload the system backup
   :log info message="Uploading system backup (2/3)."
+
   :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
 
   /tool fetch address="$ftphost" src-path=$fname1 user="$ftpuser" mode=ftp password="$ftppassword" dst-path="$ftppath/$fname1" upload=yes
 
   # upload the config export
 
   # upload the config export
   :log info message="Uploading config export (3/3)."
+
   :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
 
   /tool fetch address="$ftphost" src-path=$fname2 user="$ftpuser" mode=ftp password="$ftppassword" dst-path="$ftppath/$fname2" upload=yes
 
    
 
    
Rivi 78: Rivi 86:
  
 
Lähde: http://harry.subnetworx.de/2013/12/27/automated-routeros-backup-ftp/
 
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 "[email protected]"
 +
 +
#The From address (you can use your own address if you want)
 +
:local fromemail "[email protected]"
 +
 +
#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
 +
 +
</syntaxhighlight>
 +
 +
 +
Lähde: http://www.mikrotik-routeros.com/2014/04/gmail-google-drive-mikrotik-scripting-automated-backups-folder/
 +
 +
</translate>
 +
 +
[[Category:RouterOS]]
 +
[[Category:Backup]]

Nykyinen versio 25. elokuuta 2015 kello 19.20


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 "[email protected]"
 
 #The From address (you can use your own address if you want)
 :local fromemail "[email protected]"
 
 #A mail server your machines can send through
 :local emailserver "smtp.example.com"
 
 ############## Dont 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: