Guest User

Untitled

a guest
Nov 19th, 2017
369
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.10 KB | None | 0 0
  1. :local saveUserDB true
  2. :local saveSysBackup true
  3. :local encryptSysBackup false
  4. :local saveRawExport true
  5.  
  6. :local FTPServer "ftp.domain.tld"
  7. :local FTPPort 21
  8. :local FTPUser "mikrotik"
  9. :local FTPPass "secretpass"
  10.  
  11. :local mailaddr "mikrotik@domain.tld"
  12. :local mailserver "mail.domain.tld"
  13. :local mailto "admin@domain.tld"
  14.  
  15. #date transformation as MikroTiK has ugly date
  16. :local ds [/system clock get date ]
  17. :local months ("jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec");
  18. :local date1month [ :pick $ds 0 3 ];
  19. :local mm ([ :find $months $date1month -1 ] + 1);
  20. :if ($mm < 10) do={
  21. :set date1month ("0" . $mm);
  22. } else={
  23. :set date1month $mm;
  24. }
  25. :local ts [/system clock get time]
  26. :set ts ([:pick $ts 0 2].[:pick $ts 3 5].[:pick $ts 6 8])
  27. :set ds ([:pick $ds 7 11].$mm.[:pick $ds 4 6])
  28. :local filename ("/backup-".[/system identity get name]."-"."$ds.$ts")
  29.  
  30. # System backup
  31. :if ($saveSysBackup) do={
  32. :if ($encryptSysBackup = true) do={ /system backup save name=($filename.".backup") }
  33. :if ($encryptSysBackup = false) do={ /system backup save dont-encrypt=yes name=($filename.".backup") }
  34. :log info message="System Backup Finished"
  35. }
  36. # Export
  37. if ($saveRawExport) do={
  38. /export file=($filename.".export")
  39. :log info message="Raw configuration export finished"
  40. }
  41. #zero variable
  42. :local backupFileName ""
  43. #Upload
  44. :foreach backupFile in=[/file find] do={
  45. :set backupFileName ("/".[/file get $backupFile name])
  46. :if ([:typeof [:find $backupFileName $filename]] != "nil") do={
  47. /tool fetch address=$FTPServer port=$FTPPort src-path=$backupFileName user=$FTPUser mode=ftp password=$FTPPass dst-path=$backupFileName upload=yes
  48. }
  49. }
  50. :delay 5s
  51. #Local cleanup
  52. :foreach backupFile in=[/file find] do={
  53. :if ([:typeof [:find [/file get $backupFile name] "BACKUP-"]]!="nil") do={
  54. /file remove $backupFile
  55. }
  56. }
  57. :log info message="Successfully removed Temporary Backup Files"
  58. :log info message="Automatic Backup Completed Successfully"
  59. # Email notify
  60. :local subject ([/system identity get name]." daily backup")
  61. /tool e-mail send from=($mailaddr) server=($mailserver) subject=($subject) body=("Done ".$ds."-".$ts) to=($mailto)
Add Comment
Please, Sign In to add comment