From 71b69fc1898babf490b7dc8e7b0769022d5a2f79 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Wed, 30 Mar 2022 18:03:50 +0200 Subject: introduce backup-partition --- README.md | 1 + backup-partition | 36 ++++++++++++++++++++++++++++++++++++ doc/backup-cloud.md | 1 + doc/backup-email.md | 1 + doc/backup-partition.md | 45 +++++++++++++++++++++++++++++++++++++++++++++ doc/backup-upload.md | 3 ++- doc/packages-update.md | 1 + global-config | 2 +- global-config-overlay | 2 +- global-config.changes | 1 + global-functions | 2 +- 11 files changed, 91 insertions(+), 4 deletions(-) create mode 100644 backup-partition create mode 100644 doc/backup-partition.md diff --git a/README.md b/README.md index a3da7e7..361dbd5 100644 --- a/README.md +++ b/README.md @@ -177,6 +177,7 @@ Available scripts * [Find and remove access list duplicates](doc/accesslist-duplicates.md) * [Upload backup to Mikrotik cloud](doc/backup-cloud.md) * [Send backup via e-mail](doc/backup-email.md) +* [Save configuration to fallback partition](doc/backup-partition.md) * [Upload backup to server](doc/backup-upload.md) * [Download packages for CAP upgrade from CAPsMAN](doc/capsman-download-packages.md) * [Run rolling CAP upgrades from CAPsMAN](doc/capsman-rolling-upgrade.md) diff --git a/backup-partition b/backup-partition new file mode 100644 index 0000000..c72c7f9 --- /dev/null +++ b/backup-partition @@ -0,0 +1,36 @@ +#!rsc by RouterOS +# RouterOS script: backup-partition +# Copyright (c) 2022 Christian Hesse +# https://git.eworm.de/cgit/routeros-scripts/about/COPYING.md +# +# provides: backup-script +# +# save configuration to fallback partition +# https://git.eworm.de/cgit/routeros-scripts/about/doc/backup-partition.md + +:local 0 "backup-partition"; +:global GlobalFunctionsReady; +:while ($GlobalFunctionsReady != true) do={ :delay 500ms; } + +:global LogPrintExit2; + +:if ([ :len [ / partitions find ] ] < 2) do={ + $LogPrintExit2 error $0 ("Device does not have a fallback partition.") true; +} + +:local ActiveRunning [ / partitions find where active running ]; + +:if ([ :len $ActiveRunning ] < 1) do={ + $LogPrintExit2 error $0 ("Device is not running from active partition.") true; +} + +:local ActiveRunningVar [ / partitions get $ActiveRunning ]; + +:do { + / partitions save-config-to ($ActiveRunningVar->"fallback-to"); + $LogPrintExit2 info $0 ("Saved configuration to partition '" . \ + ($ActiveRunningVar->"fallback-to") . "'.") false; +} on-error={ + $LogPrintExit2 error $0 ("Failed saving configuration to partition '" . \ + ($ActiveRunningVar->"fallback-to") . "'!") true; +} diff --git a/doc/backup-cloud.md b/doc/backup-cloud.md index f3631ad..6a15688 100644 --- a/doc/backup-cloud.md +++ b/doc/backup-cloud.md @@ -55,6 +55,7 @@ See also -------- * [Send backup via e-mail](backup-email.md) +* [Save configuration to fallback partition](doc/backup-partition.md) * [Upload backup to server](backup-upload.md) --- diff --git a/doc/backup-email.md b/doc/backup-email.md index 19bbeee..701f10a 100644 --- a/doc/backup-email.md +++ b/doc/backup-email.md @@ -46,6 +46,7 @@ See also -------- * [Upload backup to Mikrotik cloud](backup-cloud.md) +* [Save configuration to fallback partition](doc/backup-partition.md) * [Upload backup to server](backup-upload.md) --- diff --git a/doc/backup-partition.md b/doc/backup-partition.md new file mode 100644 index 0000000..c31c780 --- /dev/null +++ b/doc/backup-partition.md @@ -0,0 +1,45 @@ +Save configuration to fallback partition +======================================== + +[◀ Go back to main README](../README.md) + +> ℹ️ **Info**: This script can not be used on its own but requires the base +> installation. See [main README](../README.md) for details. + +Description +----------- + +This script saves the current configuration to fallback +[partition](https://wiki.mikrotik.com/wiki/Manual:Partitions). + +For this to work you need a device with sufficient flash storage that is +properly partitioned. + +Requirements and installation +----------------------------- + +Just install the script: + + $ScriptInstallUpdate backup-partition; + +Usage and invocation +-------------------- + +Just run the script: + + / system script run backup-partition; + +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; + +See also +-------- + +* [Upload backup to Mikrotik cloud](backup-cloud.md) +* [Send backup via e-mail](backup-email.md) +* [Upload backup to server](backup-upload.md) + +--- +[◀ Go back to main README](../README.md) +[▲ Go back to top](#top) diff --git a/doc/backup-upload.md b/doc/backup-upload.md index a4d2bc7..a3620c4 100644 --- a/doc/backup-upload.md +++ b/doc/backup-upload.md @@ -69,8 +69,9 @@ Creating a scheduler may be an option: See also -------- -* [Send backup via e-mail](backup-email.md) * [Upload backup to Mikrotik cloud](backup-cloud.md) +* [Send backup via e-mail](backup-email.md) +* [Save configuration to fallback partition](doc/backup-partition.md) --- [◀ Go back to main README](../README.md) diff --git a/doc/packages-update.md b/doc/packages-update.md index 0007acc..243e72b 100644 --- a/doc/packages-update.md +++ b/doc/packages-update.md @@ -43,6 +43,7 @@ See also * [Notify on RouterOS update](check-routeros-update.md) * [Upload backup to Mikrotik cloud](backup-cloud.md) * [Send backup via e-mail](backup-email.md) +* [Save configuration to fallback partition](doc/backup-partition.md) * [Upload backup to server](backup-upload.md) * [Automatically upgrade firmware and reboot](firmware-upgrade-reboot.md) diff --git a/global-config b/global-config index 3ae4557..ea5176e 100644 --- a/global-config +++ b/global-config @@ -8,7 +8,7 @@ # Make sure all configuration properties are up to date and this # value is in sync with value in script 'global-functions'! -:global GlobalConfigVersion 78; +:global GlobalConfigVersion 79; # This is used for DNS and backup file. :global Domain "example.com"; diff --git a/global-config-overlay b/global-config-overlay index 7d0c83d..d5df364 100644 --- a/global-config-overlay +++ b/global-config-overlay @@ -8,7 +8,7 @@ # Make sure all configuration properties are up to date and this # value is in sync with value in script 'global-functions'! # Comment or remove to disable news and change notifications. -:global GlobalConfigVersion 78; +:global GlobalConfigVersion 79; # Copy configuration from global-config here and modify it. diff --git a/global-config.changes b/global-config.changes index 7e029be..7183619 100644 --- a/global-config.changes +++ b/global-config.changes @@ -87,6 +87,7 @@ 76="Added an option to suppress notifications on host down with 'netwatch-notify'."; 77="Introduced new script 'firmware-upgrade-reboot'. Handle with care!"; 78="New documentation is online for notifications via Telegram & Matrix, variable inspection, ip address calculation and running scripts once."; + 79="Introduced new script 'backup-partition' to save configuration to fallback partition."; }; # Migration steps to be applied on script updates diff --git a/global-functions b/global-functions index af617b3..96a5ce8 100644 --- a/global-functions +++ b/global-functions @@ -8,7 +8,7 @@ # https://git.eworm.de/cgit/routeros-scripts/about/ # expected configuration version -:global ExpectedConfigVersion 78; +:global ExpectedConfigVersion 79; # global variables not to be changed by user :global GlobalFunctionsReady false; -- cgit v1.2.3-54-g00ecf