Witam. Nowy skrypt do wysyłania backup konfiguracji systemu MikroTik na adres e-mail. Skrypt działa na wersji systemu MikroTik 7.14.3 . Skrypt zawiera trzy rodzaje backupu, plik .backup, plik export.rsc oraz export_compact.rsc.
Poniżej zamieszczam skrypt który można modyfikować według własnego uznania.
W skrypcie należy zmienić adres e-mail na który będą przychodziły pliki backup.
Skrypt
:log info "Starting Automatic Email Backup Script Configure By PGKOMP.PL"
:local date "$[/system clock get date]";
:local filename "";
:local filename2 "";
:local filename3 "";
:for i from=0 to=([:len $date] - 1) do={
:local char [:pick $date $i];
:if ($char = "/") do={
:set $char "-";
}
:set filename ($filename.$char);
:set filename2 ($filename2.$char);
:set filename3 ($filename3.$char);
}
:set filename ("$[/system identity get name]-".$filename);
:set filename2 ("$[/system identity get name]_export-".$filename2);
:set filename3 ("$[/system identity get name]_export_compact-".$filename3);
#backup
:log info "Backup Please wait...!!!"
/system backup save name=$filename;
:delay 5s;
:set filename ($filename.".backup");
:log info "Sending Backup Mikrotik to Email Address............."
/tool e-mail send file="$filename" to="spam@pgkomp.pl" subject="$[/system identity get name] $[/system resource get board-name] $[/system clock get date]" body="$[/system clock get date] $[/system clock get time] $[/system identity get name] automatyczny backup konfiguracji systemu MikroTik. (.backup)\r\r\nUptime: $[/system resource get uptime]\r\nVersion: $[/system resource get version]\r\nCpu-count: $[/system resource get cpu-count]\r\nCpu-frequency: $[/system resource get cpu-frequency]\r\nFree-hdd-space: $[/system resource get free-hdd-space]\r\nArchitecture-name: $[/system resource get architecture-name]\r\nBoard-name: $[/system resource get board-name]\r\nPlatform: $[/system resource get platform]"
:delay 5s;
:log info "Deleting Backup Files........"
/file remove $filename;
#export
:log info "Export Please wait...!!!"
/export file=$filename2;
:delay 5s;
:set filename2 ($filename2.".rsc");
:log info "Sending Export Mikrotik to Email Address............."
/tool e-mail send file="$filename2" to="spam@pgkomp.pl" subject="$[/system identity get name] $[/system resource get board-name] $[/system clock get date]" body="$[/system clock get date] $[/system clock get time] $[/system identity get name] automatyczny backup konfiguracji systemu MikroTik. (export)\r\r\nUptime: $[/system resource get uptime]\r\nVersion: $[/system resource get version]\r\nCpu-count: $[/system resource get cpu-count]\r\nCpu-frequency: $[/system resource get cpu-frequency]\r\nFree-hdd-space: $[/system resource get free-hdd-space]\r\nArchitecture-name: $[/system resource get architecture-name]\r\nBoard-name: $[/system resource get board-name]\r\nPlatform: $[/system resource get platform]"
:delay 5s;
:log info "Deleting Export Files........"
/file remove $filename2;
#export_compact
:log info "Export Compact Please wait...!!!"
/export compact file=$filename3;
:delay 5s;
:set filename3 ($filename3.".rsc");
:log info "Sending Export Compact Mikrotik to Email Address............."
/tool e-mail send file="$filename3" to="spam@pgkomp.pl" subject="$[/system identity get name] $[/system resource get board-name] $[/system clock get date]" body="$[/system clock get date] $[/system clock get time] $[/system identity get name] automatyczny backup konfiguracji systemu MikroTik. (compact export)\r\r\nUptime: $[/system resource get uptime]\r\nVersion: $[/system resource get version]\r\nCpu-count: $[/system resource get cpu-count]\r\nCpu-frequency: $[/system resource get cpu-frequency]\r\nFree-hdd-space: $[/system resource get free-hdd-space]\r\nArchitecture-name: $[/system resource get architecture-name]\r\nBoard-name: $[/system resource get board-name]\r\nPlatform: $[/system resource get platform]"
:delay 5s;
:log info "Deleting Export Compact Files........"
/file remove $filename3;
:log info "Finished PGKOMP.PL Email Backup Script...!!!!"
MikroTik musi mieć ustawiony adres e-mail do wysyłki plików backup. Adres e-mail możemy dodać za pomocą polecenia w terminalu:
/tool e-mail
set address=[adres serwera smtp] from=[adres email] password=[haslo] user=\
[nazwa uzytkownika]