routeros-scripts/cloud-backup

57 lines
2 KiB
Text
Raw Normal View History

#!rsc by RouterOS
# RouterOS script: cloud-backup
2021-01-01 20:33:52 +00:00
# Copyright (c) 2013-2021 Christian Hesse <mail@eworm.de>
# https://git.eworm.de/cgit/routeros-scripts/about/COPYING.md
#
# upload backup to MikroTik cloud
2020-03-27 20:42:33 +00:00
# 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;
2020-02-28 14:26:26 +00:00
:global Identity;
:global DeviceInfo;
:global LogPrintExit2;
:global RandomDelay;
:global ScriptFromTerminal;
2021-04-27 18:53:54 +00:00
: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; \
2021-04-29 20:25:30 +00:00
subject=([ $SymbolForNotification "floppy-disk,cloud" ] . "Cloud backup"); \
2021-04-27 18:53:54 +00:00
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" . \
2021-04-27 18:53:54 +00:00
"Download key: " . $Cloud->"secret-download-key"); silent=true });
} on-error={
$SendNotification2 ({ origin=$0; \
subject=([ $SymbolForNotification "warning-sign" ] . "Cloud backup failed"); \
2021-04-27 18:53:54 +00:00
message=("Failed uploading backup for " . $Identity . " to cloud!\n\n" . [ $DeviceInfo ]) });
$LogPrintExit2 error $0 ("Failed uploading backup for " . $Identity . " to cloud!") true;
}