mirror of
https://git.eworm.de/cgit/routeros-scripts
synced 2025-07-26 05:44:39 +02:00
backup-cloud: move code into function
This commit is contained in:
parent
efc2e75f01
commit
33d129496c
1 changed files with 47 additions and 42 deletions
|
@ -9,10 +9,12 @@
|
|||
# upload backup to MikroTik cloud
|
||||
# https://git.eworm.de/cgit/routeros-scripts/about/doc/backup-cloud.md
|
||||
|
||||
:local 0 [ :jobname ];
|
||||
:global GlobalFunctionsReady;
|
||||
:while ($GlobalFunctionsReady != true) do={ :delay 500ms; }
|
||||
|
||||
:local Main do={
|
||||
:local ScriptName [ :tostr $1 ];
|
||||
|
||||
:global BackupPassword;
|
||||
:global BackupRandomDelay;
|
||||
:global Identity;
|
||||
|
@ -28,10 +30,10 @@
|
|||
:global SymbolForNotification;
|
||||
:global WaitFullyConnected;
|
||||
|
||||
$ScriptLock $0;
|
||||
$ScriptLock $ScriptName;
|
||||
$WaitFullyConnected;
|
||||
|
||||
:if ([ $ScriptFromTerminal $0 ] = false && $BackupRandomDelay > 0) do={
|
||||
:if ([ $ScriptFromTerminal $ScriptName ] = false && $BackupRandomDelay > 0) do={
|
||||
$RandomDelay $BackupRandomDelay;
|
||||
}
|
||||
|
||||
|
@ -48,7 +50,7 @@ $WaitFullyConnected;
|
|||
}
|
||||
:local Cloud [ /system/backup/cloud/get ([ find ]->0) ];
|
||||
|
||||
$SendNotification2 ({ origin=$0; \
|
||||
$SendNotification2 ({ origin=$ScriptName; \
|
||||
subject=([ $SymbolForNotification "floppy-disk,cloud" ] . "Cloud backup"); \
|
||||
message=("Uploaded backup for " . $Identity . " to cloud.\n\n" . \
|
||||
[ $DeviceInfo ] . "\n\n" . \
|
||||
|
@ -56,8 +58,11 @@ $WaitFullyConnected;
|
|||
[ $FormatLine "Size" ([ $HumanReadableNum ($Cloud->"size") 1024 ] . "iB") ] . "\n" . \
|
||||
[ $FormatLine "Download key" ($Cloud->"secret-download-key") ]); silent=true });
|
||||
} on-error={
|
||||
$SendNotification2 ({ origin=$0; \
|
||||
$SendNotification2 ({ origin=$ScriptName; \
|
||||
subject=([ $SymbolForNotification "floppy-disk,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;
|
||||
$LogPrintExit2 error $ScriptName ("Failed uploading backup for " . $Identity . " to cloud!") true;
|
||||
}
|
||||
}
|
||||
|
||||
$Main [ :jobname ];
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue