Skip to content

Commit 164246a

Browse files
bugfixes
1 parent 14097a4 commit 164246a

File tree

1 file changed

+32
-12
lines changed

1 file changed

+32
-12
lines changed

BackupAndUpdate.rsc

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
#----------SCRIPT INFORMATION---------------------------------------------------
44
#
55
# Script: Mikrotik RouterOS automatic backup & update
6-
# Version: 22.07.15
6+
# Version: 22.11.12
77
# Created: 07/08/2018
8-
# Updated: 15/07/2022
8+
# Updated: 12/11/2022
99
# Author: Alexander Tebiev
1010
# Website: https://github.com/beeyev
1111
# You can contact me by e-mail at tebiev@mail.com
@@ -175,23 +175,37 @@ if ([:len [/system identity get name]] = 0 or [/system identity get name] = "Mik
175175
:global buGlobalVarUpdateStep;
176176
############### ^^^^^^^^^ GLOBALS ^^^^^^^^^ ###############
177177

178-
:local scriptVersion "22.07.15";
178+
:local scriptVersion "22.11.12";
179179

180180
#Current date time in format: 2020jan15-221324
181181
: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]);
182182

183+
:local isSoftBased false;
184+
:if ([/system resource get board-name] = "CHR" or [/system resource get board-name] = "x86") do={
185+
:set isSoftBased true;
186+
}
187+
183188
:local deviceOsVerInst [/system package update get installed-version];
184189
:local deviceOsVerInstNum [$buGlobalFuncGetOsVerNum paramOsVer=$deviceOsVerInst];
185190
:local deviceOsVerAvail "";
186191
:local deviceOsVerAvailNum 0;
187-
:local deviceRbModel [/system routerboard get model];
188-
:local deviceRbSerialNumber [/system routerboard get serial-number];
189-
:local deviceRbCurrentFw [/system routerboard get current-firmware];
190-
:local deviceRbUpgradeFw [/system routerboard get upgrade-firmware];
191192
:local deviceIdentityName [/system identity get name];
192193
:local deviceIdentityNameShort [:pick $deviceIdentityName 0 18]
193194
:local deviceUpdateChannel [/system package update get channel];
194195

196+
197+
:local deviceRbModel "CloudHostedRouter";
198+
:local deviceRbSerialNumber "--";
199+
:local deviceRbCurrentFw "--";
200+
:local deviceRbUpgradeFw "--";
201+
202+
:if ($isSoftBased = false) do={
203+
:set deviceRbModel [/system routerboard get model];
204+
:set deviceRbSerialNumber [/system routerboard get serial-number];
205+
:set deviceRbCurrentFw [/system routerboard get current-firmware];
206+
:set deviceRbUpgradeFw [/system routerboard get upgrade-firmware];
207+
};
208+
195209
:local isOsUpdateAvailable false;
196210
:local isOsNeedsToBeUpdated false;
197211

@@ -289,7 +303,7 @@ if ([:len [/system identity get name]] = 0 or [/system identity get name] = "Mik
289303
if ($isOsNeedsToBeUpdated = true) do={
290304
:log info ("$SMP New RouterOS is going to be installed! v.$deviceOsVerInst -> v.$deviceOsVerAvail");
291305
:set mailSubject ($mailSubject . " New RouterOS is going to be installed! v.$deviceOsVerInst -> v.$deviceOsVerAvail.");
292-
:set mailBody ($mailBody . "Your Mikrotik will be updated to the new RouterOS version from v.$deviceOsVerInst to v.$deviceOsVerAvail (Update channel: $updateChannel) \r\nFinal report with the detailed information will be sent when update process is completed. \r\nIf you have not received second email in the next 5 minutes, then probably something went wrong. (Check your device logs)");
306+
:set mailBody ($mailBody . "Your Mikrotik will be updated to the new RouterOS version from v.$deviceOsVerInst to v.$deviceOsVerAvail (Update channel: $updateChannel) \r\nFinal report with the detailed information will be sent when update process is completed. \r\nIf you have not received second email in the next 10 minutes, then probably something went wrong. (Check your device logs)");
293307
#!! There is more code connected to this part and first step at the end of the script.
294308
}
295309

@@ -398,12 +412,18 @@ if ([:len [/system identity get name]] = 0 or [/system identity get name] = "Mik
398412
# Fire RouterOs update process
399413
if ($isOsNeedsToBeUpdated = true) do={
400414

401-
## Set scheduled task to upgrade routerboard firmware on the next boot, task will be deleted when upgrade is done. (That is why you should keep original script name)
402-
/system scheduler add name=BKPUPD-UPGRADE-ON-NEXT-BOOT on-event=":delay 5s; /system scheduler remove BKPUPD-UPGRADE-ON-NEXT-BOOT; :global buGlobalVarUpdateStep 2; :delay 10s; /system script run BackupAndUpdate;" start-time=startup interval=0;
415+
:if ($isSoftBased = false) do={
416+
## Set scheduled task to upgrade routerboard firmware on the next boot, task will be deleted when upgrade is done. (That is why you should keep original script name)
417+
/system scheduler add name=BKPUPD-UPGRADE-ON-NEXT-BOOT on-event=":delay 5s; /system scheduler remove BKPUPD-UPGRADE-ON-NEXT-BOOT; :global buGlobalVarUpdateStep 2; :delay 10s; /system script run BackupAndUpdate;" start-time=startup interval=0;
418+
} else= {
419+
## If the scrip is executed on CHR, step 2 will be skipped
420+
/system scheduler add name=BKPUPD-UPGRADE-ON-NEXT-BOOT on-event=":delay 5s; /system scheduler remove BKPUPD-UPGRADE-ON-NEXT-BOOT; :global buGlobalVarUpdateStep 3; :delay 10s; /system script run BackupAndUpdate;" start-time=startup interval=0;
421+
};
422+
403423

404-
:log info "$SMP everything is ready to install new RouterOS, going to reboot in a moment!"
424+
:log info "$SMP everything is ready to install new RouterOS, going to reboot in a moment!"
405425
## command is reincarnation of the "upgrade" command - doing exactly the same but under a different name
406426
/system package update install;
407427
}
408428

409-
:log info "$SMP script \"Mikrotik RouterOS automatic backup & update\" completed it's job.\r\n";
429+
:log info "$SMP script \"Mikrotik RouterOS automatic backup & update\" completed it's job.\r\n";

0 commit comments

Comments
 (0)