Merge pull request #77 from beeyev/ver-26.02.22

This commit is contained in:
Alexander Tebiev 2026-02-22 22:42:13 +01:00 committed by GitHub
commit 2b4f233d59
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 34 additions and 42 deletions

2
.gitignore vendored
View file

@ -1,3 +1,3 @@
ignore/ .ignore/
.idea/ .idea/
.vscode/ .vscode/

View file

@ -3,9 +3,9 @@
# SCRIPT INFORMATION # SCRIPT INFORMATION
# #
# Script: Mikrotik RouterOS automatic backup & update # Script: Mikrotik RouterOS automatic backup & update
# Version: 25.04.15 # Version: 26.02.22
# Created: 07/08/2018 # Created: 07/08/2018
# Updated: 15/04/2025 # Updated: 22/02/2026
# Author: Alexander Tebiev # Author: Alexander Tebiev
# Website: https://github.com/beeyev # Website: https://github.com/beeyev
# You can contact me by e-mail at tebiev@mail.com # You can contact me by e-mail at tebiev@mail.com
@ -16,7 +16,7 @@
# --- MODIFY THIS SECTION AS NEEDED --- # --- MODIFY THIS SECTION AS NEEDED ---
# Notification e-mail # Notification e-mail
# (Make sure you have configured Email settings in Tools -> Email) # (Make sure you have configured Email settings in Tools -> Email)
:local emailAddress "yourmail@example.com"; :local emailAddress "yourmail@example.com"
# Script mode, possible values: backup, osupdate, osnotify. # Script mode, possible values: backup, osupdate, osnotify.
# backup - Only backup will be performed. (default value, if none provided) # backup - Only backup will be performed. (default value, if none provided)
@ -56,7 +56,7 @@
# !!! DO NOT EDIT BELOW THIS LINE UNLESS YOU KNOW WHAT YOURE DOING !!! # !!! DO NOT EDIT BELOW THIS LINE UNLESS YOU KNOW WHAT YOURE DOING !!!
:local scriptVersion "25.04.15" :local scriptVersion "26.02.22"
# default and fallback public IP detection services # default and fallback public IP detection services
:local ipAddressDetectServiceDefault "https://ipv4.mikrotik.ovh/" :local ipAddressDetectServiceDefault "https://ipv4.mikrotik.ovh/"
@ -112,26 +112,18 @@
:local ver1 $1 :local ver1 $1
:local ver2 $2 :local ver2 $2
# Extract the major and minor components from a version # Extract "major.minor" prefix from each version by finding the second dot
:local extractMajorMinor do={ :local dot1 [:find $ver1 "."]
:local ver $1 :if ([:len $dot1] = 0) do={ :return ($ver1 = $ver2) }
:local dot1 [:find $ver "."] :local end1 [:find $ver1 "." ($dot1 + 1)]
:if ($dot1 = -1) do={ :return $ver } :if ([:len $end1] = 0) do={ :set end1 [:len $ver1] }
:local major [:pick $ver 0 $dot1] :local dot2 [:find $ver2 "."]
:local rest [:pick $ver ($dot1 + 1) [:len $ver]] :if ([:len $dot2] = 0) do={ :return ($ver1 = $ver2) }
:local dot2 [:find $rest "."] :local end2 [:find $ver2 "." ($dot2 + 1)]
:local minor $rest :if ([:len $end2] = 0) do={ :set end2 [:len $ver2] }
:if ($dot2 >= 0) do={ :set minor [:pick $rest 0 $dot2] }
:return ($major . "." . $minor) :return ([:pick $ver1 0 $end1] = [:pick $ver2 0 $end2])
}
# Compare the major and minor components of both version strings
:if ([$extractMajorMinor $ver1] = [$extractMajorMinor $ver2]) do={
:return true
}
:return false
} }
# Creates backups and returns array of names # Creates backups and returns array of names
@ -315,11 +307,11 @@
:set emailServer [/tool e-mail get address] :set emailServer [/tool e-mail get address]
} }
:if ($emailServer = "0.0.0.0") do={ :if ($emailServer = "0.0.0.0") do={
:log error ("$SMP Email server address is not correct: `$emailServer`, check `Tools -> Email`. Script stopped."); :log error ("$SMP Email server address is not correct: `$emailServer`, check `Tools -> Email`. Script stopped.")
:error $exitErrorMessage :error $exitErrorMessage
} }
:if ([:len $emailFromAddress] < 3) do={ :if ([:len $emailFromAddress] < 3) do={
:log error ("$SMP Email configuration FROM address is not correct: `$emailFromAddress`, check `Tools -> Email`. Script stopped."); :log error ("$SMP Email configuration FROM address is not correct: `$emailFromAddress`, check `Tools -> Email`. Script stopped.")
:error $exitErrorMessage :error $exitErrorMessage
} }
@ -376,15 +368,15 @@
:local deviceBoardName [/system resource get board-name] :local deviceBoardName [/system resource get board-name]
## Check if it's a cloud hosted router ## Check if it's a cloud hosted router
:local isCloudHostedRouter false; :local isCloudHostedRouter false
:if ([:pick $deviceBoardName 0 3] = "CHR" or [:pick $deviceBoardName 0 3] = "x86") do={ :if ([:pick $deviceBoardName 0 3] = "CHR" or [:pick $deviceBoardName 0 3] = "x86") do={
:set isCloudHostedRouter true; :set isCloudHostedRouter true
}; }
:local deviceIdentityName [/system identity get name]; :local deviceIdentityName [/system identity get name]
:local deviceIdentityNameShort [:pick $deviceIdentityName 0 18] :local deviceIdentityNameShort [:pick $deviceIdentityName 0 18]
:local deviceRbModel "CloudHostedRouter"; :local deviceRbModel "CloudHostedRouter"
:local deviceRbSerialNumber "--" :local deviceRbSerialNumber "--"
:local deviceRbCurrentFw "--" :local deviceRbCurrentFw "--"
:local deviceRbUpgradeFw "--" :local deviceRbUpgradeFw "--"
@ -394,7 +386,7 @@
:set deviceRbSerialNumber [/system routerboard get serial-number] :set deviceRbSerialNumber [/system routerboard get serial-number]
:set deviceRbCurrentFw [/system routerboard get current-firmware] :set deviceRbCurrentFw [/system routerboard get current-firmware]
:set deviceRbUpgradeFw [/system routerboard get upgrade-firmware] :set deviceRbUpgradeFw [/system routerboard get upgrade-firmware]
}; }
:local runningOsChannel [$FuncGetRunningOsChannel] :local runningOsChannel [$FuncGetRunningOsChannel]
:local runningOsVersion [$FuncGetRunningOsVersion] :local runningOsVersion [$FuncGetRunningOsVersion]
@ -481,13 +473,13 @@
# Checking for new version # Checking for new version
:if ($scriptMode = "osupdate" or $scriptMode = "osnotify") do={ :if ($scriptMode = "osupdate" or $scriptMode = "osnotify") do={
log info ("$SMP Setting update channel to `$updateChannel`") :log info ("$SMP Setting update channel to `$updateChannel`")
/system package update set channel=$updateChannel /system package update set channel=$updateChannel
log info ("$SMP Checking for new RouterOS version. Current installed version is: `$runningOsVersion`") :log info ("$SMP Checking for new RouterOS version. Current installed version is: `$runningOsVersion`")
/system package update check-for-updates /system package update check-for-updates
# Wait to allow the system to check for updates # Wait to allow the system to check for updates
:delay 5s; :delay 5s
:local packageUpdateStatus "undefined" :local packageUpdateStatus "undefined"
@ -557,7 +549,7 @@
} }
:do { :do {
:set mailAttachments [$FuncCreateBackups $backupName $backupPassword $sensitiveDataInConfig]; :set mailAttachments [$FuncCreateBackups $backupName $backupPassword $sensitiveDataInConfig]
:set mailPtSubjectBackup "Backup created" :set mailPtSubjectBackup "Backup created"
:set mailPtBodyBackup "System backups have been successfully created and attached to this email." :set mailPtBodyBackup "System backups have been successfully created and attached to this email."
@ -596,8 +588,8 @@
:if ([:len $mailAttachments] > 0) do={ :if ([:len $mailAttachments] > 0) do={
:log info "$SMP Cleaning up backup files from the file system..." :log info "$SMP Cleaning up backup files from the file system..."
/file remove $mailAttachments; /file remove $mailAttachments
:delay 2s; :delay 2s
} }
:if ($isOsNeedsToBeUpdated = true) do={ :if ($isOsNeedsToBeUpdated = true) do={
@ -640,12 +632,12 @@
/system routerboard upgrade /system routerboard upgrade
:delay 2s :delay 2s
:log info "$SMP routerboard upgrade process was completed, going to reboot in a moment!"; :log info "$SMP routerboard upgrade process was completed, going to reboot in a moment!"
## Set task to send final report on the next boot ## Set task to send final report on the next boot
/system scheduler add name=BKPUPD-NEXT-BOOT-TASK on-event=":delay 5s; /system scheduler remove BKPUPD-NEXT-BOOT-TASK; :global buGlobalVarScriptStep 3; :global buGlobalVarTargetOsVersion \"$buGlobalVarTargetOsVersion\"; :delay 10s; /system script run BackupAndUpdate;" start-time=startup interval=0 /system scheduler add name=BKPUPD-NEXT-BOOT-TASK on-event=":delay 5s; /system scheduler remove BKPUPD-NEXT-BOOT-TASK; :global buGlobalVarScriptStep 3; :global buGlobalVarTargetOsVersion \"$buGlobalVarTargetOsVersion\"; :delay 10s; /system script run BackupAndUpdate;" start-time=startup interval=0
/system reboot; /system reboot
} }
## STEP 3: Final report (after second reboot, with delay). ## STEP 3: Final report (after second reboot, with delay).
@ -670,7 +662,7 @@
:set mailStep3Body ($mailStep3Body . "\nNew RouterOS version: v.$targetOsVersion, routerboard firmware: v.$deviceRbCurrentFw") :set mailStep3Body ($mailStep3Body . "\nNew RouterOS version: v.$targetOsVersion, routerboard firmware: v.$deviceRbCurrentFw")
:set mailStep3Body ($mailStep3Body . "\n$changelogUrl\nBackups of the upgraded system are in the attachment of this email.\n\n$mailBodyDeviceInfo\n\n$mailBodyCopyright") :set mailStep3Body ($mailStep3Body . "\n$changelogUrl\nBackups of the upgraded system are in the attachment of this email.\n\n$mailBodyDeviceInfo\n\n$mailBodyCopyright")
:set mailAttachments [$FuncCreateBackups $backupNameAfterUpdate $backupPassword $sensitiveDataInConfig]; :set mailAttachments [$FuncCreateBackups $backupNameAfterUpdate $backupPassword $sensitiveDataInConfig]
} else={ } else={
:log error "$SMP Failed to verify new RouterOS version: target: `$targetOsVersion`, current: `$runningOsVersion`" :log error "$SMP Failed to verify new RouterOS version: target: `$targetOsVersion`, current: `$runningOsVersion`"
:set mailStep3Subject ($mailStep3Subject . " - Update failed") :set mailStep3Subject ($mailStep3Subject . " - Update failed")
@ -682,8 +674,8 @@
:if ([:len $mailAttachments] > 0) do={ :if ([:len $mailAttachments] > 0) do={
:log info "$SMP Cleaning up backup files from the file system..." :log info "$SMP Cleaning up backup files from the file system..."
/file remove $mailAttachments; /file remove $mailAttachments
:delay 2s; :delay 2s
} }
:log info "$SMP Final report email sent successfully, and the script has finished." :log info "$SMP Final report email sent successfully, and the script has finished."