aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Christian Hesse <mail@eworm.de>2024-05-22 12:03:53 +0200
committerGravatar Christian Hesse <mail@eworm.de>2024-05-23 12:03:13 +0200
commit8dabdcbf782e0d4b1772dbc1dc9367cdeb9e4c4a (patch)
treef26e9229fe2129cffc8315a0909bb5e03f18380f
parent6824644ac58d2c3cd8c9ba3d59e0814bad96a050 (diff)
backup-partition: support copy before feature update
-rw-r--r--backup-partition.rsc13
-rw-r--r--doc/backup-partition.md18
-rw-r--r--global-config.rsc2
3 files changed, 30 insertions, 3 deletions
diff --git a/backup-partition.rsc b/backup-partition.rsc
index a72dd0b..3c883f7 100644
--- a/backup-partition.rsc
+++ b/backup-partition.rsc
@@ -15,11 +15,13 @@
:do {
:local ScriptName [ :jobname ];
+ :global BackupPartitionCopyBeforeFeatureUpdate;
:global PackagesUpdateBackupFailure;
:global LogPrint;
:global ScriptFromTerminal;
:global ScriptLock;
+ :global VersionToNum;
:local CopyTo do={
:local ScriptName [ :tostr $1 ];
@@ -67,6 +69,17 @@
: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;
+ }
+ }
}
}
diff --git a/doc/backup-partition.md b/doc/backup-partition.md
index 8996203..1cef2c9 100644
--- a/doc/backup-partition.md
+++ b/doc/backup-partition.md
@@ -18,7 +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.
+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.
@@ -29,8 +30,7 @@ added in the backup partition's configuration. You may want to use
> ⚠️ **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! For that run the script from terminal
-> manually.
+> for a recent RouterOS version! See below for options.
Requirements and installation
-----------------------------
@@ -39,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
--------------------
diff --git a/global-config.rsc b/global-config.rsc
index 646eddb..8a42b81 100644
--- a/global-config.rsc
+++ b/global-config.rsc
@@ -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 {