aboutsummaryrefslogtreecommitdiffstats
path: root/backup-upload.rsc
diff options
context:
space:
mode:
Diffstat (limited to 'backup-upload.rsc')
-rw-r--r--backup-upload.rsc61
1 files changed, 39 insertions, 22 deletions
diff --git a/backup-upload.rsc b/backup-upload.rsc
index 1dc98d5..e6b9f92 100644
--- a/backup-upload.rsc
+++ b/backup-upload.rsc
@@ -1,18 +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.13
+# 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
+# https://rsc.eworm.de/doc/backup-upload.md
-:global GlobalFunctionsReady;
-:while ($GlobalFunctionsReady != true) do={ :delay 500ms; }
-
-:do {
+:local ExitOK false;
+: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;
@@ -33,6 +35,8 @@
:global LogPrint;
:global MkDir;
:global RandomDelay;
+ :global RmDir;
+ :global RmFile;
:global ScriptFromTerminal;
:global ScriptLock;
:global SendNotification2;
@@ -43,13 +47,23 @@
:if ($BackupSendBinary != true && \
$BackupSendExport != true) do={
$LogPrint error $ScriptName ("Configured to send neither backup nor config export.");
+ :set ExitOK true;
:error false;
}
:if ([ $ScriptLock $ScriptName ] = false) do={
:set PackagesUpdateBackupFailure true;
+ :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={
@@ -67,6 +81,7 @@
:if ([ $MkDir $DirName ] = false) do={
$LogPrint error $ScriptName ("Failed creating directory!");
+ :set ExitOK true;
:error false;
}
@@ -75,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
@@ -94,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
@@ -115,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={
@@ -157,5 +172,7 @@
:if ($Failed = 1) do={
:set PackagesUpdateBackupFailure true;
}
- /file/remove $DirName;
-} on-error={ }
+ $RmDir $DirName;
+} do={
+ :global ExitError; $ExitError $ExitOK [ :jobname ] $Err;
+}