diff options
-rw-r--r-- | backup-cloud.rsc | 17 | ||||
-rw-r--r-- | doc/backup-cloud.md | 8 | ||||
-rw-r--r-- | global-functions.rsc | 2 | ||||
-rw-r--r-- | news-and-changes.rsc | 1 |
4 files changed, 20 insertions, 8 deletions
diff --git a/backup-cloud.rsc b/backup-cloud.rsc index 418e68d..5dd4bf1 100644 --- a/backup-cloud.rsc +++ b/backup-cloud.rsc @@ -15,7 +15,6 @@ :local Main do={ :local ScriptName [ :tostr $1 ]; - :global BackupPassword; :global BackupRandomDelay; :global Identity; @@ -23,11 +22,13 @@ :global FormatLine; :global HumanReadableNum; :global LogPrintExit2; + :global MkDir; :global RandomDelay; :global ScriptFromTerminal; :global ScriptLock; :global SendNotification2; :global SymbolForNotification; + :global WaitForFile; :global WaitFullyConnected; :if ([ $ScriptLock $ScriptName ] = false) do={ @@ -39,7 +40,12 @@ $RandomDelay $BackupRandomDelay; } - :do { + :if ([ $MkDir ("tmpfs/backup-cloud") ] = false) do={ + $LogPrintExit2 error $ScriptName ("Failed creating directory!") true; + } + + :execute { + :global BackupPassword; # we are not interested in output, but print is # required to fetch information from cloud /system/backup/cloud/print as-value; @@ -50,6 +56,10 @@ /system/backup/cloud/upload-file action=create-and-upload \ password=$BackupPassword; } + /file/add name="tmpfs/backup-cloud/done"; + } as-string; + + :if ([ $WaitForFile "tmpfs/backup-cloud/done" ] = true) do={ :local Cloud [ /system/backup/cloud/get ([ find ]->0) ]; $SendNotification2 ({ origin=$ScriptName; \ @@ -59,12 +69,13 @@ [ $FormatLine "Name" ($Cloud->"name") ] . "\n" . \ [ $FormatLine "Size" ([ $HumanReadableNum ($Cloud->"size") 1024 ] . "iB") ] . "\n" . \ [ $FormatLine "Download key" ($Cloud->"secret-download-key") ]); silent=true }); - } on-error={ + } else={ $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 $ScriptName ("Failed uploading backup for " . $Identity . " to cloud!") true; } + /file/remove "tmpfs/backup-cloud"; } $Main [ :jobname ]; diff --git a/doc/backup-cloud.md b/doc/backup-cloud.md index f084d5b..ac7edb7 100644 --- a/doc/backup-cloud.md +++ b/doc/backup-cloud.md @@ -12,10 +12,10 @@ Description This script uploads [binary backup to Mikrotik cloud](https://wiki.mikrotik.com/wiki/Manual:IP/Cloud#Backup). -> ⚠️ **Warning**: The used command can hit errors that a script can not handle. -> This may result in script termination (where no notification is sent) or -> malfunction of fetch command (where all up- and downloads break) for some -> time. Failed notifications are queued then. +> ⚠️ **Warning**: The used command can hit errors that a script can with +> workaround only. A notification *should* be sent anyway. But it can result +> in malfunction of fetch command (where all up- and downloads break) for +> some time. Failed notifications are queued then. ### Sample notification diff --git a/global-functions.rsc b/global-functions.rsc index 6ddcbd3..9b5b0b0 100644 --- a/global-functions.rsc +++ b/global-functions.rsc @@ -12,7 +12,7 @@ :local ScriptName [ :jobname ]; # expected configuration version -:global ExpectedConfigVersion 119; +:global ExpectedConfigVersion 120; # global variables not to be changed by user :global GlobalFunctionsReady false; diff --git a/news-and-changes.rsc b/news-and-changes.rsc index d0e9938..c260427 100644 --- a/news-and-changes.rsc +++ b/news-and-changes.rsc @@ -44,6 +44,7 @@ [ $IfThenElse ($Resource->"free-hdd-space" > 4000000) ("(Your " . $Resource->"board-name" . " does not suffer this issue.) ") ] ] . \ "Huge configuration and lots of scripts give an extra risk. Take care!"); 119="Added support for IPv6 to script 'fw-addr-lists'."; + 120="Implemented a workaround in 'backup-cloud'. Now script should no longer just crash, but send notification with error."; }; # Migration steps to be applied on script updates |