introduce backup-partition

This commit is contained in:
Christian Hesse 2022-03-30 18:03:50 +02:00
parent 2aa93a0671
commit 71b69fc189
11 changed files with 91 additions and 4 deletions

View file

@ -177,6 +177,7 @@ Available scripts
* [Find and remove access list duplicates](doc/accesslist-duplicates.md) * [Find and remove access list duplicates](doc/accesslist-duplicates.md)
* [Upload backup to Mikrotik cloud](doc/backup-cloud.md) * [Upload backup to Mikrotik cloud](doc/backup-cloud.md)
* [Send backup via e-mail](doc/backup-email.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) * [Upload backup to server](doc/backup-upload.md)
* [Download packages for CAP upgrade from CAPsMAN](doc/capsman-download-packages.md) * [Download packages for CAP upgrade from CAPsMAN](doc/capsman-download-packages.md)
* [Run rolling CAP upgrades from CAPsMAN](doc/capsman-rolling-upgrade.md) * [Run rolling CAP upgrades from CAPsMAN](doc/capsman-rolling-upgrade.md)

36
backup-partition Normal file
View file

@ -0,0 +1,36 @@
#!rsc by RouterOS
# RouterOS script: backup-partition
# Copyright (c) 2022 Christian Hesse <mail@eworm.de>
# 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;
}

View file

@ -55,6 +55,7 @@ See also
-------- --------
* [Send backup via e-mail](backup-email.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) * [Upload backup to server](backup-upload.md)
--- ---

View file

@ -46,6 +46,7 @@ See also
-------- --------
* [Upload backup to Mikrotik cloud](backup-cloud.md) * [Upload backup to Mikrotik cloud](backup-cloud.md)
* [Save configuration to fallback partition](doc/backup-partition.md)
* [Upload backup to server](backup-upload.md) * [Upload backup to server](backup-upload.md)
--- ---

45
doc/backup-partition.md Normal file
View file

@ -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)

View file

@ -69,8 +69,9 @@ Creating a scheduler may be an option:
See also See also
-------- --------
* [Send backup via e-mail](backup-email.md)
* [Upload backup to Mikrotik cloud](backup-cloud.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) [◀ Go back to main README](../README.md)

View file

@ -43,6 +43,7 @@ See also
* [Notify on RouterOS update](check-routeros-update.md) * [Notify on RouterOS update](check-routeros-update.md)
* [Upload backup to Mikrotik cloud](backup-cloud.md) * [Upload backup to Mikrotik cloud](backup-cloud.md)
* [Send backup via e-mail](backup-email.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) * [Upload backup to server](backup-upload.md)
* [Automatically upgrade firmware and reboot](firmware-upgrade-reboot.md) * [Automatically upgrade firmware and reboot](firmware-upgrade-reboot.md)

View file

@ -8,7 +8,7 @@
# Make sure all configuration properties are up to date and this # Make sure all configuration properties are up to date and this
# value is in sync with value in script 'global-functions'! # value is in sync with value in script 'global-functions'!
:global GlobalConfigVersion 78; :global GlobalConfigVersion 79;
# This is used for DNS and backup file. # This is used for DNS and backup file.
:global Domain "example.com"; :global Domain "example.com";

View file

@ -8,7 +8,7 @@
# Make sure all configuration properties are up to date and this # Make sure all configuration properties are up to date and this
# value is in sync with value in script 'global-functions'! # value is in sync with value in script 'global-functions'!
# Comment or remove to disable news and change notifications. # Comment or remove to disable news and change notifications.
:global GlobalConfigVersion 78; :global GlobalConfigVersion 79;
# Copy configuration from global-config here and modify it. # Copy configuration from global-config here and modify it.

View file

@ -87,6 +87,7 @@
76="Added an option to suppress notifications on host down with 'netwatch-notify'."; 76="Added an option to suppress notifications on host down with 'netwatch-notify'.";
77="Introduced new script 'firmware-upgrade-reboot'. Handle with care!"; 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."; 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 # Migration steps to be applied on script updates

View file

@ -8,7 +8,7 @@
# https://git.eworm.de/cgit/routeros-scripts/about/ # https://git.eworm.de/cgit/routeros-scripts/about/
# expected configuration version # expected configuration version
:global ExpectedConfigVersion 78; :global ExpectedConfigVersion 79;
# global variables not to be changed by user # global variables not to be changed by user
:global GlobalFunctionsReady false; :global GlobalFunctionsReady false;