Site Overlay

Backup Config Mikrotik ke Email


Environment:

Mikrotik Version: 6.43.2

Mikrotik Series: RB20011UiAS


Backup akan dijalankan sesuai interval yang diinginkan menggunakan scheduler dan otomatis dikirmkan ke email, berikut script yang digunakan:

:local saveUserDb false
:local saveSysBackup true
:local encryptSysBackup true
:local saveRawExport true

:local mailTo "xxxxxxx@xxxx"

:local ts [/system clock get time]
:set ts ([:pick $ts 0 2].[:pick $ts 3 5].[:pick $ts 6 8])

:local ds [/system clock get date]
:set ds ([:pick $ds 7 11].[:pick $ds 0 3].[:pick $ds 4 6])

:local fname ("BACKUP_RB-".[/system identity get name]."-".$ds."-".$ts)
:local sfname ("/".$fname)

:if ($saveUserDb) do={
  /tool user-manager database save name=($sfname.".umb")
  :log info message="User Manager DB Backup Finished"
}

:if ($saveSysBackup) do={
  :if ($encryptSysBackup) do={
    /system backup save name=($sfname.".backup")
  } else={
    /system backup save dont-encrypt=yes name=($sfname.".backup")
  }
  :log info message="System Backup Finished"
}

if ($saveRawExport) do={
  /export file=($sfname.".rsc")
  :log info message="Raw configuration script export Finished"
}

:delay 5s

:foreach backupFile in=[/file find] do={
  :set $backupFileName ("/".[/file get $backupFile name])
  :if ([:typeof [:find $backupFileName $sfname]] != "nil") do={
    /tool e-mail send subject=([:pick $backupFileName 1 [:len $backupFileName]]) to=$mailTo file=([:pick $backupFileName 1 [:len $backupFileName]]) 
  }
}

:delay 300s

:foreach backupFile in=[/file find] do={
  :if ([:typeof [:find [/file get $backupFile name] "BACKUP_RB-"]] != "nil") do={
    /file remove $backupFile
    :log info message="Successfully removed Temporary Backup Files"
  }
}

:log info message="Automatic Backup Completed Successfully"

Note:

  1. Setelah menambahkan script tersebut, buat Scheduler (System – Scheduler) untuk menjalankan sesuai intervel yang diinginkan
  2. Pastikan pengaturan Email Settings (Tools – Email) sudah berfungsi dengan baik.
  3. Hasil backupnya adalah file .rsc dan .backup

Done…

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll Up