aboutsummaryrefslogtreecommitdiffstats
path: root/backup-upload.rsc
diff options
context:
space:
mode:
Diffstat (limited to 'backup-upload.rsc')
-rw-r--r--backup-upload.rsc57
1 files changed, 34 insertions, 23 deletions
diff --git a/backup-upload.rsc b/backup-upload.rsc
index 12698e9..e6b9f92 100644
--- a/backup-upload.rsc
+++ b/backup-upload.rsc
@@ -1,19 +1,20 @@
#!rsc by RouterOS
# RouterOS script: backup-upload
-# Copyright (c) 2013-2024 Christian Hesse <mail@eworm.de>
-# https://git.eworm.de/cgit/routeros-scripts/about/COPYING.md
+# Copyright (c) 2013-2025 Christian Hesse <mail@eworm.de>
+# https://rsc.eworm.de/COPYING.md
#
# provides: backup-script, order=50
-# requires RouterOS, version=7.14
+# requires RouterOS, version=7.15
+# requires device-mode, fetch
#
# create and upload backup and config file
-# https://git.eworm.de/cgit/routeros-scripts/about/doc/backup-upload.md
-
-:global GlobalFunctionsReady;
-:while ($GlobalFunctionsReady != true) do={ :delay 500ms; }
+# https://rsc.eworm.de/doc/backup-upload.md
:local ExitOK false;
-:do {
+:onerror Err {
+ :global GlobalConfigReady; :global GlobalFunctionsReady;
+ :retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \
+ do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50;
:local ScriptName [ :jobname ];
:global BackupPassword;
@@ -34,6 +35,8 @@
:global LogPrint;
:global MkDir;
:global RandomDelay;
+ :global RmDir;
+ :global RmFile;
:global ScriptFromTerminal;
:global ScriptLock;
:global SendNotification2;
@@ -53,6 +56,14 @@
:set ExitOK true;
:error false;
}
+
+ :if ([ :len [ /system/scheduler/find where name="running-from-backup-partition" ] ] > 0) do={
+ $LogPrint warning $ScriptName ("Running from backup partition, refusing to act.");
+ :set PackagesUpdateBackupFailure true;
+ :set ExitOK true;
+ :error false;
+ }
+
$WaitFullyConnected;
:if ([ $ScriptFromTerminal $ScriptName ] = false && $BackupRandomDelay > 0) do={
@@ -79,18 +90,18 @@
/system/backup/save encryption=aes-sha256 name=$FilePath password=$BackupPassword;
$WaitForFile ($FilePath . ".backup");
- :do {
+ :onerror Err {
/tool/fetch upload=yes url=($BackupUploadUrl . "/" . $FileName . ".backup") \
user=$BackupUploadUser password=$BackupUploadPass src-path=($FilePath . ".backup");
:set BackupFile [ /file/get ($FilePath . ".backup") ];
:set ($BackupFile->"name") ($FileName . ".backup");
- } on-error={
- $LogPrint error $ScriptName ("Uploading backup file failed!");
+ } do={
+ $LogPrint error $ScriptName ("Uploading backup file failed: " . $Err);
:set BackupFile "failed";
:set Failed 1;
}
- /file/remove ($FilePath . ".backup");
+ $RmFile ($FilePath . ".backup");
}
# create configuration export
@@ -98,18 +109,18 @@
/export terse show-sensitive file=$FilePath;
$WaitForFile ($FilePath . ".rsc");
- :do {
+ :onerror Err {
/tool/fetch upload=yes url=($BackupUploadUrl . "/" . $FileName . ".rsc") \
user=$BackupUploadUser password=$BackupUploadPass src-path=($FilePath . ".rsc");
:set ExportFile [ /file/get ($FilePath . ".rsc") ];
:set ($ExportFile->"name") ($FileName . ".rsc");
- } on-error={
- $LogPrint error $ScriptName ("Uploading configuration export failed!");
+ } do={
+ $LogPrint error $ScriptName ("Uploading configuration export failed: " . $Err);
:set ExportFile "failed";
:set Failed 1;
}
- /file/remove ($FilePath . ".rsc");
+ $RmFile ($FilePath . ".rsc");
}
# global-config-overlay
@@ -119,18 +130,18 @@
file=($FilePath . ".conf\00");
$WaitForFile ($FilePath . ".conf");
- :do {
+ :onerror Err {
/tool/fetch upload=yes url=($BackupUploadUrl . "/" . $FileName . ".conf") \
user=$BackupUploadUser password=$BackupUploadPass src-path=($FilePath . ".conf");
:set ConfigFile [ /file/get ($FilePath . ".conf") ];
:set ($ConfigFile->"name") ($FileName . ".conf");
- } on-error={
- $LogPrint error $ScriptName ("Uploading global-config-overlay failed!");
+ } do={
+ $LogPrint error $ScriptName ("Uploading global-config-overlay failed: " . $Err);
:set ConfigFile "failed";
:set Failed 1;
}
- /file/remove ($FilePath . ".conf");
+ $RmFile ($FilePath . ".conf");
}
:local FileInfo do={
@@ -161,7 +172,7 @@
:if ($Failed = 1) do={
:set PackagesUpdateBackupFailure true;
}
- /file/remove $DirName;
-} on-error={
- :global ExitError; $ExitError $ExitOK [ :jobname ];
+ $RmDir $DirName;
+} do={
+ :global ExitError; $ExitError $ExitOK [ :jobname ] $Err;
}