small improvements

This commit is contained in:
Alexander Tebiev 2023-11-11 19:50:38 +01:00
parent a320983b8f
commit 65afc007ca

View File

@ -60,11 +60,28 @@
:log info "\r\n$SMP script \"Mikrotik RouterOS automatic backup & update\" started."; :log info "\r\n$SMP script \"Mikrotik RouterOS automatic backup & update\" started.";
:log info "$SMP Script Mode: $scriptMode, forceBackup: $forceBackup"; :log info "$SMP Script Mode: $scriptMode, forceBackup: $forceBackup";
#Check proper email config # Check email settings
:if ([:len $emailAddress] = 0 or [:len [/tool e-mail get address]] = 0 or [:len [/tool e-mail get from]] = 0) do={ :if ([:len $emailAddress] = 0) do={
:log error ("$SMP Email configuration is not correct, please check Tools -> Email. Script stopped."); :log error ("$SMP \$emailAddress variable is empty. Script stopped.");
:error "$SMP bye!"; :error "$SMP bye!";
} }
:local emailServer ""
:do {
:set emailServer [/tool e-mail get server];
} on-error={
# Old of getting email server before the RouterOS v7.12
:log info "$SMP Checking email server using old command `/tool e-mail get address`";
:set emailServer [/tool e-mail get address];
}
:if ($emailServer = "0.0.0.0") do={
:log error ("$SMP Email server address is not correct, please check Tools -> Email. Script stopped.");
:error "$SMP bye!";
}
:if ([:len [/tool e-mail get from]] = 0 or [/tool e-mail get from] = "<>") do={
:log error ("$SMP Email configuration FROM address is not correct, please check Tools -> Email. Script stopped.");
:error "$SMP bye!";
}
#Check if proper identity name is set #Check if proper identity name is set
if ([:len [/system identity get name]] = 0 or [/system identity get name] = "MikroTik") do={ if ([:len [/system identity get name]] = 0 or [/system identity get name] = "MikroTik") do={
@ -156,12 +173,14 @@ if ([:len [/system identity get name]] = 0 or [/system identity get name] = "Mik
## Export config file ## Export config file
:if ($sensitiveDataInConfig = true) do={ :if ($sensitiveDataInConfig = true) do={
# Since RouterOS v7 it needs to be explicitly set that we want to export sensitive data :do {
:if ([:pick [/system package update get installed-version] 0 1] < 7) do={ # Since RouterOS v7 it needs to be explicitly set that we want to export sensitive data
:execute "/export compact terse file=$backupName"; /export compact show-sensitive terse file=$backupName;
} else={ } on-error={
:execute "/export compact show-sensitive terse file=$backupName"; :log info "$SMP Exporting config file with sensitive data using old way `/export compact terse file`";
/export compact terse file=$backupName;
} }
} else={ } else={
/export compact hide-sensitive terse file=$backupName; /export compact hide-sensitive terse file=$backupName;
} }
@ -177,13 +196,24 @@ if ([:len [/system identity get name]] = 0 or [/system identity get name] = "Mik
:local scriptVersion "22.11.12"; :local scriptVersion "22.11.12";
#Current date time in format: yyyymmmdd-hhMMss. E.g. 2020jan15-221324 # Current time `hhMMss`
:local dateTime ([:pick [/system clock get date] 7 11] . [:pick [/system clock get date] 0 3] . [:pick [/system clock get date] 4 6] . "-" . [:pick [/system clock get time] 0 2] . [:pick [/system clock get time] 3 5] . [:pick [/system clock get time] 6 8]); :local currentTime ([:pick [/system clock get time] 0 2] . [:pick [/system clock get time] 3 5] . [:pick [/system clock get time] 6 8]);
:local currentDateTime ("-" . $currentTime);
# Detect old date format, Example: `nov/11/2023`
:if ([:len [:tonum [:pick [/system clock get date] 0 1]]] = 0) do={
:set currentDateTime ([:pick [/system clock get date] 7 11] . [:pick [/system clock get date] 0 3] . [:pick [/system clock get date] 4 6] . "-" . $currentTime);
}
# New date format, Example: `nov/11/2023`
else={
:set currentDateTime ([/system clock get date] . "-" . $currentTime);
};
:local isSoftBased false; :local isSoftBased false;
:if ([/system resource get board-name] = "CHR" or [/system resource get board-name] = "x86") do={ :if ([/system resource get board-name] = "CHR" or [/system resource get board-name] = "x86") do={
:set isSoftBased true; :set isSoftBased true;
} };
:local deviceOsVerInst [/system package update get installed-version]; :local deviceOsVerInst [/system package update get installed-version];
:local deviceOsVerInstNum [$buGlobalFuncGetOsVerNum paramOsVer=$deviceOsVerInst]; :local deviceOsVerInstNum [$buGlobalFuncGetOsVerNum paramOsVer=$deviceOsVerInst];
@ -218,7 +248,7 @@ if ([:len [/system identity get name]] = 0 or [/system identity get name] = "Mik
:local mailBodyCopyright "\r\n\r\nMikrotik RouterOS automatic backup & update (ver. $scriptVersion) \r\nhttps://github.com/beeyev/Mikrotik-RouterOS-automatic-backup-and-update"; :local mailBodyCopyright "\r\n\r\nMikrotik RouterOS automatic backup & update (ver. $scriptVersion) \r\nhttps://github.com/beeyev/Mikrotik-RouterOS-automatic-backup-and-update";
:local changelogUrl ("Check RouterOS changelog: https://mikrotik.com/download/changelogs/" . $updateChannel . "-release-tree"); :local changelogUrl ("Check RouterOS changelog: https://mikrotik.com/download/changelogs/" . $updateChannel . "-release-tree");
:local backupName "v$deviceOsVerInst_$deviceUpdateChannel_$dateTime"; :local backupName "v$deviceOsVerInst_$deviceUpdateChannel_$currentDateTime";
:local backupNameBeforeUpd "backup_before_update_$backupName"; :local backupNameBeforeUpd "backup_before_update_$backupName";
:local backupNameAfterUpd "backup_after_update_$backupName"; :local backupNameAfterUpd "backup_after_update_$backupName";