From 8c39f41ffcf3af7fe6d8b4091db5791756f59879 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Wed, 5 Jan 2022 22:36:49 +0100 Subject: rename script cloud-backup -> backup-cloud --- README.md | 2 +- backup-cloud | 58 ++++++++++ cloud-backup | 58 +--------- doc/backup-cloud.d/notification.svg | 216 ++++++++++++++++++++++++++++++++++++ doc/backup-cloud.md | 54 +++++++++ doc/cloud-backup.d/notification.svg | 216 ------------------------------------ doc/cloud-backup.md | 55 +-------- doc/email-backup.md | 2 +- doc/log-forward.d/notification.svg | 2 +- doc/upload-backup.md | 2 +- 10 files changed, 334 insertions(+), 331 deletions(-) create mode 100644 backup-cloud create mode 100644 doc/backup-cloud.d/notification.svg create mode 100644 doc/backup-cloud.md delete mode 100644 doc/cloud-backup.d/notification.svg diff --git a/README.md b/README.md index f55a14b..f14403d 100644 --- a/README.md +++ b/README.md @@ -185,6 +185,7 @@ Available scripts ----------------- * [Find and remove access list duplicates](doc/accesslist-duplicates.md) +* [Upload backup to Mikrotik cloud](doc/backup-cloud.md) * [Download packages for CAP upgrade from CAPsMAN](doc/capsman-download-packages.md) * [Run rolling CAP upgrades from CAPsMAN](doc/capsman-rolling-upgrade.md) * [Renew locally issued certificates](doc/certificate-renew-issued.md) @@ -192,7 +193,6 @@ Available scripts * [Notify about health state](doc/check-health.md) * [Notify on LTE firmware upgrade](doc/check-lte-firmware-upgrade.md) * [Notify on RouterOS update](doc/check-routeros-update.md) -* [Upload backup to Mikrotik cloud](doc/cloud-backup.md) * [Collect MAC addresses in wireless access list](doc/collect-wireless-mac.md) * [Use wireless network with daily psk](doc/daily-psk.md) * [Comment DHCP leases with info from access list](doc/dhcp-lease-comment.md) diff --git a/backup-cloud b/backup-cloud new file mode 100644 index 0000000..d1d9f14 --- /dev/null +++ b/backup-cloud @@ -0,0 +1,58 @@ +#!rsc by RouterOS +# RouterOS script: backup-cloud +# Copyright (c) 2013-2022 Christian Hesse +# https://git.eworm.de/cgit/routeros-scripts/about/COPYING.md +# +# provides: backup-script +# +# upload backup to MikroTik cloud +# https://git.eworm.de/cgit/routeros-scripts/about/doc/backup-cloud.md + +:local 0 "backup-cloud"; +:global GlobalFunctionsReady; +:while ($GlobalFunctionsReady != true) do={ :delay 500ms; } + +:global BackupPassword; +:global BackupRandomDelay; +:global Identity; + +:global DeviceInfo; +:global LogPrintExit2; +:global RandomDelay; +:global ScriptFromTerminal; +:global SendNotification2; +:global SymbolForNotification; +:global WaitFullyConnected; + +$WaitFullyConnected; + +:if ([ $ScriptFromTerminal $0 ] = false && $BackupRandomDelay > 0) do={ + $RandomDelay $BackupRandomDelay; +} + +:do { + # we are not interested in output, but print is + # required to fetch information from cloud + / system backup cloud print as-value; + :if ([ :len [ / system backup cloud find ] ] > 0) do={ + / system backup cloud upload-file action=create-and-upload \ + password=$BackupPassword replace=[ get ([ find ]->0) name ]; + } else={ + / system backup cloud upload-file action=create-and-upload \ + password=$BackupPassword; + } + :local Cloud [ / system backup cloud get ([ find ]->0) ]; + + $SendNotification2 ({ origin=$0; \ + subject=([ $SymbolForNotification "floppy-disk,cloud" ] . "Cloud backup"); \ + message=("Uploaded backup for " . $Identity . " to cloud.\n\n" . \ + [ $DeviceInfo ] . "\n\n" . \ + "Name: " . $Cloud->"name" . "\n" . \ + "Size: " . $Cloud->"size" . " B (" . ($Cloud->"size" / 1024) . " KiB)\n" . \ + "Download key: " . $Cloud->"secret-download-key"); silent=true }); +} on-error={ + $SendNotification2 ({ origin=$0; \ + subject=([ $SymbolForNotification "warning-sign" ] . "Cloud backup failed"); \ + message=("Failed uploading backup for " . $Identity . " to cloud!\n\n" . [ $DeviceInfo ]) }); + $LogPrintExit2 error $0 ("Failed uploading backup for " . $Identity . " to cloud!") true; +} diff --git a/cloud-backup b/cloud-backup index ab2cf7c..2c48f07 100644 --- a/cloud-backup +++ b/cloud-backup @@ -1,58 +1,2 @@ #!rsc by RouterOS -# RouterOS script: cloud-backup -# Copyright (c) 2013-2022 Christian Hesse -# https://git.eworm.de/cgit/routeros-scripts/about/COPYING.md -# -# provides: backup-script -# -# upload backup to MikroTik cloud -# https://git.eworm.de/cgit/routeros-scripts/about/doc/cloud-backup.md - -:local 0 "cloud-backup"; -:global GlobalFunctionsReady; -:while ($GlobalFunctionsReady != true) do={ :delay 500ms; } - -:global BackupPassword; -:global BackupRandomDelay; -:global Identity; - -:global DeviceInfo; -:global LogPrintExit2; -:global RandomDelay; -:global ScriptFromTerminal; -:global SendNotification2; -:global SymbolForNotification; -:global WaitFullyConnected; - -$WaitFullyConnected; - -:if ([ $ScriptFromTerminal $0 ] = false && $BackupRandomDelay > 0) do={ - $RandomDelay $BackupRandomDelay; -} - -:do { - # we are not interested in output, but print is - # required to fetch information from cloud - / system backup cloud print as-value; - :if ([ :len [ / system backup cloud find ] ] > 0) do={ - / system backup cloud upload-file action=create-and-upload \ - password=$BackupPassword replace=[ get ([ find ]->0) name ]; - } else={ - / system backup cloud upload-file action=create-and-upload \ - password=$BackupPassword; - } - :local Cloud [ / system backup cloud get ([ find ]->0) ]; - - $SendNotification2 ({ origin=$0; \ - subject=([ $SymbolForNotification "floppy-disk,cloud" ] . "Cloud backup"); \ - message=("Uploaded backup for " . $Identity . " to cloud.\n\n" . \ - [ $DeviceInfo ] . "\n\n" . \ - "Name: " . $Cloud->"name" . "\n" . \ - "Size: " . $Cloud->"size" . " B (" . ($Cloud->"size" / 1024) . " KiB)\n" . \ - "Download key: " . $Cloud->"secret-download-key"); silent=true }); -} on-error={ - $SendNotification2 ({ origin=$0; \ - subject=([ $SymbolForNotification "warning-sign" ] . "Cloud backup failed"); \ - message=("Failed uploading backup for " . $Identity . " to cloud!\n\n" . [ $DeviceInfo ]) }); - $LogPrintExit2 error $0 ("Failed uploading backup for " . $Identity . " to cloud!") true; -} +# dummy for migration diff --git a/doc/backup-cloud.d/notification.svg b/doc/backup-cloud.d/notification.svg new file mode 100644 index 0000000..b023e50 --- /dev/null +++ b/doc/backup-cloud.d/notification.svg @@ -0,0 +1,216 @@ + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + [MikroTik] 💾☁ Cloud backup + +Uploaded backup for MikroTik to cloud. + +Hostname: MikroTik +Board name: CHR +Architecture: x86_64 +RouterOS: + Channel: stable + Installed: 6.48.3 +RouterOS-Scripts: + Current: 55 + +Name: cloud-20210614-092419 +Size: 370767 B (362 KiB) +Download key: LLDBfPcWXxmSetWilqeJX5V + + diff --git a/doc/backup-cloud.md b/doc/backup-cloud.md new file mode 100644 index 0000000..18b9ec1 --- /dev/null +++ b/doc/backup-cloud.md @@ -0,0 +1,54 @@ +Upload backup to Mikrotik cloud +=============================== + +[◀ Go back to main README](../README.md) + +🛈 This script can not be used on its own but requires the base installation. +See [main README](../README.md) for details. + +Description +----------- + +This script uploads [binary backup to Mikrotik cloud](https://wiki.mikrotik.com/wiki/Manual:IP/Cloud#Backup). + +### Sample notification + +![backup-cloud notification](backup-cloud.d/notification.svg) + +Requirements and installation +----------------------------- + +Just install the script: + + $ScriptInstallUpdate backup-cloud; + +Configuration +------------- + +The configuration goes to `global-config-overlay`, these are the parameters: + +* `BackupPassword`: password to encrypt the backup with +* `BackupRandomDelay`: delay up to amount of seconds when run from scheduler + +Also notification settings are required for e-mail, matrix and/or telegram. + +Usage and invocation +-------------------- + +Just run the script: + + / system script run backup-cloud; + +Creating a scheduler may be an option: + + / system scheduler add interval=1w name=backup-cloud on-event="/ system script run backup-cloud;" start-time=09:20:00; + +See also +-------- + +* [Send backup via e-mail](email-backup.md) +* [Upload backup to server](upload-backup.md) + +--- +[◀ Go back to main README](../README.md) +[▲ Go back to top](#top) diff --git a/doc/cloud-backup.d/notification.svg b/doc/cloud-backup.d/notification.svg deleted file mode 100644 index 8b84b8f..0000000 --- a/doc/cloud-backup.d/notification.svg +++ /dev/null @@ -1,216 +0,0 @@ - - - - - - - - - - - - image/svg+xml - - - - - - - - - - - - - - - - - - - - - - - [MikroTik] 💾☁ Cloud backup - -Uploaded backup for MikroTik to cloud. - -Hostname: MikroTik -Board name: CHR -Architecture: x86_64 -RouterOS: - Channel: stable - Installed: 6.48.3 -RouterOS-Scripts: - Current: 55 - -Name: cloud-20210614-092419 -Size: 370767 B (362 KiB) -Download key: LLDBfPcWXxmSetWilqeJX5V - - diff --git a/doc/cloud-backup.md b/doc/cloud-backup.md index 7522bc1..e161cfa 100644 --- a/doc/cloud-backup.md +++ b/doc/cloud-backup.md @@ -1,54 +1 @@ -Upload backup to Mikrotik cloud -=============================== - -[◀ Go back to main README](../README.md) - -🛈 This script can not be used on its own but requires the base installation. -See [main README](../README.md) for details. - -Description ------------ - -This script uploads [binary backup to Mikrotik cloud](https://wiki.mikrotik.com/wiki/Manual:IP/Cloud#Backup). - -### Sample notification - -![cloud-backup notification](cloud-backup.d/notification.svg) - -Requirements and installation ------------------------------ - -Just install the script: - - $ScriptInstallUpdate cloud-backup; - -Configuration -------------- - -The configuration goes to `global-config-overlay`, these are the parameters: - -* `BackupPassword`: password to encrypt the backup with -* `BackupRandomDelay`: delay up to amount of seconds when run from scheduler - -Also notification settings are required for e-mail, matrix and/or telegram. - -Usage and invocation --------------------- - -Just run the script: - - / system script run cloud-backup; - -Creating a scheduler may be an option: - - / system scheduler add interval=1w name=cloud-backup on-event="/ system script run cloud-backup;" start-time=09:20:00; - -See also --------- - -* [Send backup via e-mail](email-backup.md) -* [Upload backup to server](upload-backup.md) - ---- -[◀ Go back to main README](../README.md) -[▲ Go back to top](#top) +This script has been renamed. Please see [backup-cloud](backup-cloud.md). diff --git a/doc/email-backup.md b/doc/email-backup.md index 85d50bd..bb48e9d 100644 --- a/doc/email-backup.md +++ b/doc/email-backup.md @@ -46,7 +46,7 @@ Creating a scheduler may be an option: See also -------- -* [Upload backup to Mikrotik cloud](cloud-backup.md) +* [Upload backup to Mikrotik cloud](backup-cloud.md) * [Upload backup to server](upload-backup.md) --- diff --git a/doc/log-forward.d/notification.svg b/doc/log-forward.d/notification.svg index b3389fe..373144b 100644 --- a/doc/log-forward.d/notification.svg +++ b/doc/log-forward.d/notification.svg @@ -170,7 +170,7 @@ ● 13:24:02 script;error cloud-backup: Failed uploading backup ● 13:24:02 script;error backup-cloud: Failed uploading backup for MikroTik to cloud! diff --git a/doc/upload-backup.md b/doc/upload-backup.md index 9566853..203f7f6 100644 --- a/doc/upload-backup.md +++ b/doc/upload-backup.md @@ -63,7 +63,7 @@ See also -------- * [Send backup via e-mail](email-backup.md) -* [Upload backup to Mikrotik cloud](cloud-backup.md) +* [Upload backup to Mikrotik cloud](backup-cloud.md) --- [◀ Go back to main README](../README.md) -- cgit v1.2.3-54-g00ecf