Merge branch 'backup-partition' into next
This commit is contained in:
commit
96ea39b7cd
5 changed files with 66 additions and 4 deletions
|
|
@ -15,10 +15,29 @@
|
|||
:do {
|
||||
:local ScriptName [ :jobname ];
|
||||
|
||||
:global BackupPartitionCopyBeforeFeatureUpdate;
|
||||
:global PackagesUpdateBackupFailure;
|
||||
|
||||
:global LogPrint;
|
||||
:global ScriptFromTerminal;
|
||||
:global ScriptLock;
|
||||
:global VersionToNum;
|
||||
|
||||
:local CopyTo do={
|
||||
:local ScriptName [ :tostr $1 ];
|
||||
:local FallbackTo [ :tostr $2 ];
|
||||
|
||||
:global LogPrint;
|
||||
|
||||
:do {
|
||||
/partitions/copy-to $FallbackTo;
|
||||
$LogPrint info $ScriptName ("Copied RouterOS to partition '" . $FallbackTo . "'.");
|
||||
:return true;
|
||||
} on-error={
|
||||
$LogPrint error $ScriptName ("Failed copying RouterOS to partition '" . $FallbackTo . "'!");
|
||||
:return false;
|
||||
}
|
||||
}
|
||||
|
||||
:if ([ $ScriptLock $ScriptName ] = false) do={
|
||||
:set PackagesUpdateBackupFailure true;
|
||||
|
|
@ -41,6 +60,29 @@
|
|||
|
||||
:local FallbackTo [ /partitions/get $ActiveRunning fallback-to ];
|
||||
|
||||
:if ([ /partitions/get $ActiveRunning version ] != [ /partitions/get $FallbackTo version]) do={
|
||||
:if ([ $ScriptFromTerminal $ScriptName ] = true) do={
|
||||
:put ("The partitions have different RouterOS versions. Copy over to '" . $FallbackTo . "'? [y/N]");
|
||||
:if (([ /terminal/inkey timeout=60 ] % 32) = 25) do={
|
||||
:if ([ $CopyTo $ScriptName $FallbackTo ] = false) do={
|
||||
:set PackagesUpdateBackupFailure true;
|
||||
:error false;
|
||||
}
|
||||
}
|
||||
} else={
|
||||
:local Update [ /system/package/update/get ];
|
||||
:local NumInstalled [ $VersionToNum ($Update->"installed-version") ];
|
||||
:local NumLatest [ $VersionToNum ($Update->"latest-version") ];
|
||||
:if ($BackupPartitionCopyBeforeFeatureUpdate = true && $NumLatest > 0 && \
|
||||
($NumInstalled & 0xffff0000) != ($NumLatest & 0xffff0000)) do={
|
||||
:if ([ $CopyTo $ScriptName $FallbackTo ] = false) do={
|
||||
:set PackagesUpdateBackupFailure true;
|
||||
:error false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
:do {
|
||||
/system/scheduler/add start-time=startup name="running-from-backup-partition" \
|
||||
on-event=(":log warning (\"Running from partition '\" . " . \
|
||||
|
|
|
|||
|
|
@ -18,6 +18,8 @@ Description
|
|||
|
||||
This script saves the current configuration to fallback
|
||||
[partition](https://wiki.mikrotik.com/wiki/Manual:Partitions).
|
||||
It can also copy-over the RouterOS installation when run interactively
|
||||
or just before a feature update.
|
||||
|
||||
For this to work you need a device with sufficient flash storage that is
|
||||
properly partitioned.
|
||||
|
|
@ -26,9 +28,9 @@ To make you aware of a possible issue a scheduler logging a warning is
|
|||
added in the backup partition's configuration. You may want to use
|
||||
[log-forward](log-forward.md) to be notified.
|
||||
|
||||
> ⚠️ **Warning**: Only the configuration is saved to backup partition.
|
||||
> Every now and then you should copy your installation over for a recent
|
||||
> RouterOS version!
|
||||
> ⚠️ **Warning**: By default only the configuration is saved to backup
|
||||
> partition. Every now and then you should copy your installation over
|
||||
> for a recent RouterOS version! See below for options.
|
||||
|
||||
Requirements and installation
|
||||
-----------------------------
|
||||
|
|
@ -37,6 +39,18 @@ Just install the script:
|
|||
|
||||
$ScriptInstallUpdate backup-partition;
|
||||
|
||||
Configuration
|
||||
-------------
|
||||
|
||||
The configuration goes to `global-config-overlay`, the only parameter is:
|
||||
|
||||
* `BackupPartitionCopyBeforeFeatureUpdate`: copy-over the RouterOS
|
||||
installation when a feature update is pending
|
||||
|
||||
> ℹ️ **Info**: Copy relevant configuration from
|
||||
> [`global-config`](../global-config.rsc) (the one without `-overlay`) to
|
||||
> your local `global-config-overlay` and modify it to your specific needs.
|
||||
|
||||
Usage and invocation
|
||||
--------------------
|
||||
|
||||
|
|
@ -44,6 +58,9 @@ Just run the script:
|
|||
|
||||
/system/script/run backup-partition;
|
||||
|
||||
When run interactively from terminal it supports to copy-over the RouterOS
|
||||
installation when versions differ.
|
||||
|
||||
Creating a scheduler may be an option:
|
||||
|
||||
/system/scheduler/add interval=1w name=backup-partition on-event="/system/script/run backup-partition;" start-time=09:30:00;
|
||||
|
|
|
|||
|
|
@ -85,6 +85,8 @@
|
|||
:global BackupUploadUrl "sftp://example.com/backup/";
|
||||
:global BackupUploadUser "mikrotik";
|
||||
:global BackupUploadPass "v3ry-s3cr3t";
|
||||
# Copy the RouterOS installation to backup partition before feature update.
|
||||
:global BackupPartitionCopyBeforeFeatureUpdate false;
|
||||
|
||||
# This defines the settings for firewall address-lists (fw-addr-lists).
|
||||
:global FwAddrLists {
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@
|
|||
:local ScriptName [ :jobname ];
|
||||
|
||||
# expected configuration version
|
||||
:global ExpectedConfigVersion 128;
|
||||
:global ExpectedConfigVersion 129;
|
||||
|
||||
# global variables not to be changed by user
|
||||
:global GlobalFunctionsReady false;
|
||||
|
|
|
|||
|
|
@ -53,6 +53,7 @@
|
|||
126="Made 'telegram-chat' capable of handling large command output. Telegram messages still limit the size, so it is truncated now.";
|
||||
127="Added support for authentication to Ntfy notification module.";
|
||||
128="Added another list from blocklist.de to default configuration for 'fw-addr-lists'.";
|
||||
129="Extended 'backup-partition' to support RouterOS copy-over - interactively or before feature update.";
|
||||
};
|
||||
|
||||
# Migration steps to be applied on script updates
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue