aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--backup-partition.rsc42
-rw-r--r--doc/backup-partition.md23
-rw-r--r--global-config.rsc2
-rw-r--r--global-functions.rsc2
-rw-r--r--news-and-changes.rsc1
5 files changed, 66 insertions, 4 deletions
diff --git a/backup-partition.rsc b/backup-partition.rsc
index fc186c0..3c883f7 100644
--- a/backup-partition.rsc
+++ b/backup-partition.rsc
@@ -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 '\" . " . \
diff --git a/doc/backup-partition.md b/doc/backup-partition.md
index ba20657..1cef2c9 100644
--- a/doc/backup-partition.md
+++ b/doc/backup-partition.md
@@ -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;
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 {
diff --git a/global-functions.rsc b/global-functions.rsc
index 3800ad5..96ed71d 100644
--- a/global-functions.rsc
+++ b/global-functions.rsc
@@ -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;
diff --git a/news-and-changes.rsc b/news-and-changes.rsc
index 13a358f..b20bbaf 100644
--- a/news-and-changes.rsc
+++ b/news-and-changes.rsc
@@ -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