воскресенье, 18 сентября 2016 г.

mikrotik script FTP Backup


  # ftp configuration
  :local ftphost "192.168.99.88"
  :local ftpuser "noc"
  :local ftppassword "Pa$$w0rd"
  :local ftppath "./backup/"
 
  # months array
  :local months ("nul","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];
  # 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 ("/EDAY-".[/system identity get name]."-".$ds."-".$ts.".backup")
  # file name for config export - file name will be servername-date-time.rsc
  :local fname2 ("/EDAY-".[/system identity get name]."-".$ds."-".$ts.".rsc")
 
  # backup the data
  /system backup save name=$fname1
  /export file=$fname2
 
  # upload the user manager backup
  /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=$fname2 user="$ftpuser" mode=ftp password="$ftppassword" dst-path="$ftppath/$fname2" upload=yes
  :delay 15
  # find file name EDAY
  :foreach i in=[/file find] do={ :if ([:typeof [:find [/file get $i name] "EDAY-"]]!="nil") do={/file remove $i}; }



3 комментария:

  1. в версии 6.40.4
    :local fname1 ("/EDAY-".[/system identity get name]."-".$ds."-".$ts.".backup")

    # /EDAY- не нужна косая (/) в версии 6.40.4
    "/EDAY-"

    ОтветитьУдалить
  2. Ответы
    1. Вас благодарю за поправку, от версии версии порой синтаксис немного изменяется.

      Удалить