mirror of
https://github.com/beeyev/Mikrotik-RouterOS-automatic-backup-and-update.git
synced 2025-07-15 16:34:34 +02:00
96 lines
4.3 KiB
Text
96 lines
4.3 KiB
Text
|
# Script name: BackupAndUpdate
|
||
|
#
|
||
|
#----------SCRIPT INFORMATION---------------------------------------------------
|
||
|
#
|
||
|
# Script: Mikrotik RouterOS automatic backup & update
|
||
|
# Version: 24.06.04
|
||
|
# Created: 07/08/2018
|
||
|
# Updated: 04/06/2024
|
||
|
# Author: Alexander Tebiev
|
||
|
# Website: https://github.com/beeyev
|
||
|
# You can contact me by e-mail at tebiev@mail.com
|
||
|
#
|
||
|
# IMPORTANT!
|
||
|
# Minimum supported RouterOS version is v6.43.7
|
||
|
#
|
||
|
#----------MODIFY THIS SECTION AS NEEDED----------------------------------------
|
||
|
## Notification e-mail
|
||
|
## (Make sure you have configured Email settings in Tools -> Email)
|
||
|
:local emailAddress "zzt.tzz@gmail.com";
|
||
|
|
||
|
## Script mode, possible values: backup, osupdate, osnotify.
|
||
|
# backup - Only backup will be performed. (default value, if none provided)
|
||
|
#
|
||
|
# osupdate - The script will install a new RouterOS version if it is available.
|
||
|
# It will also create backups before and after update process (it does not matter what value `forceBackup` is set to)
|
||
|
# Email will be sent only if a new RouterOS version is available.
|
||
|
# Change parameter `forceBackup` if you need the script to create backups every time when it runs (even when no updates were found).
|
||
|
#
|
||
|
# osnotify - The script will send email notifications only (without backups) if a new RouterOS update is available.
|
||
|
# Change parameter `forceBackup` if you need the script to create backups every time when it runs.
|
||
|
:local scriptMode "osupdate";
|
||
|
|
||
|
## Additional parameter if you set `scriptMode` to `osupdate` or `osnotify`
|
||
|
# Set `true` if you want the script to perform backup every time its fired, whatever script mode is set.
|
||
|
:local forceBackup false;
|
||
|
|
||
|
## Backup encryption password, no encryption if no password.
|
||
|
:local backupPassword "";
|
||
|
|
||
|
## If true, passwords will be included in exported config.
|
||
|
:local sensitiveDataInConfig true;
|
||
|
|
||
|
## Update channel. Possible values: stable, long-term, testing, development
|
||
|
:local updateChannel "stable";
|
||
|
|
||
|
## Installs only patch versions of RouterOS updates.
|
||
|
## Works only if you set scriptMode to "osupdate"
|
||
|
## Means that new update will be installed only if MAJOR and MINOR version numbers remained the same as currently installed RouterOS.
|
||
|
## Example: v6.43.6 => major.minor.PATCH
|
||
|
## Script will send information if new version is greater than just patch.
|
||
|
:local installOnlyPatchUpdates false;
|
||
|
|
||
|
## If true, device public IP address information will be included into the email message
|
||
|
:local detectPublicIpAddress true;
|
||
|
|
||
|
## Allow anonymous statistics collection. (script mode, device model, OS version)
|
||
|
:local allowAnonymousStatisticsCollection true;
|
||
|
|
||
|
##------------------------------------------------------------------------------------------##
|
||
|
# !!!! DO NOT CHANGE ANYTHING BELOW THIS LINE, IF YOU ARE NOT SURE WHAT YOU ARE DOING !!!! #
|
||
|
##------------------------------------------------------------------------------------------##
|
||
|
|
||
|
#Script messages prefix
|
||
|
:local SMP "Bkp&Upd:"
|
||
|
|
||
|
:log info "\n$SMP script \"Mikrotik RouterOS automatic backup & update\" started.";
|
||
|
:log info "$SMP Script Mode: $scriptMode, forceBackup: $forceBackup";
|
||
|
|
||
|
|
||
|
# Check email settings
|
||
|
:if ([:len $emailAddress] = 0) do={
|
||
|
:log error ("$SMP \$emailAddress variable is empty. Script stopped.");
|
||
|
: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" or [:len $emailServer] = 0) do={
|
||
|
:log error ("$SMP Email server address is not configured or is invalid. Please configure it in Tools -> Email and try again. Script stopped.");
|
||
|
:error "$SMP bye!";
|
||
|
}
|
||
|
:if ([:len [/tool e-mail get from]] = 0 or [/tool e-mail get from] = "<>" or [:find [/tool e-mail get from] "@"] = -1) do={
|
||
|
:log error ("$SMP Email configuration FROM address is missing or invalid. Please configure it in Tools -> Email and try again. Script stopped.");
|
||
|
:error "$SMP bye!";
|
||
|
}
|
||
|
|
||
|
|
||
|
#Check if proper identity name is set
|
||
|
if ([:len [/system identity get name]] = 0 or [/system identity get name] = "MikroTik") do={
|
||
|
:log warning ("$SMP Please set identity name of your device (System -> Identity), keep it short and informative.");
|
||
|
};
|