Guest User

Untitled

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