Advertisement
toperx

Untitled

Feb 8th, 2018
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1. # automated backup export ftp
  2. # ftp configuration
  3. :local ftphost "айпишнег"
  4. :local ftpuser "йузер"
  5. :local ftppassword "пароль"
  6. :local ftppath "/"
  7. # months array
  8. :local months ("jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec");
  9. # get time
  10. :local ts [/system clock get time]
  11. :set ts ([:pick $ts 0 2].[:pick $ts 3 5].[:pick $ts 6 8])
  12. # get Date
  13. :local ds [/system clock get date]
  14. # convert name of month to number
  15. :local month [ :pick $ds 0 3 ];
  16. :local mm ([ :find $months $month -1 ] + 1);
  17. :if ($mm < 10) do={ :set mm ("0" . $mm); }
  18. # set $ds to format YYYY-MM-DD
  19. :set ds ([:pick $ds 7 11] . $mm . [:pick $ds 4 6])
  20. # file name for system backup - file name will be Mikrotik-servername-date-time.backup
  21. :local fname1 ("/Mikrotik-".[/system identity get name]."-".$ds."-".$ts.".backup")
  22. # file name for config export - file name will be Mikrotik-servername-date-time.rsc
  23. :local fname2 ("/Mikrotik-".[/system identity get name]."-".$ds."-".$ts.".rsc")
  24. # backup the data
  25. /system backup save name=$fname1
  26. :log info message="System backup finished (1/2).";
  27. /export compact file=$fname2
  28. :log info message="Config export finished (2/2)."
  29. # upload the user manager backup
  30. :log info message="Uploading system backup (1/2)."
  31. /tool fetch address="$ftphost" src-path=$fname1 user="$ftpuser" mode=ftp password="$ftppassword" dst-path="$ftppath/$fname1" upload=yes
  32. # upload the config export
  33. :log info message="Uploading config export (2/2)."
  34. /tool fetch address="$ftphost" src-path=$fname2 user="$ftpuser" mode=ftp password="$ftppassword" dst-path="$ftppath/$fname2" upload=yes
  35. # delay time to finish the upload - increase it if your backup file is big
  36. :delay 30s;
  37. # find file name start with Mikrotik- then remove
  38. :foreach i in=[/file find] do={ :if ([:typeof [:find [/file get $i name] "Mikrotik-"]]!="nil") do={/file remove $i}; }
  39. :log warning message="Configuration backup finished.";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement