backup-partition: :do ... on-error=... -> :onerror ... do=...

This commit is contained in:
Christian Hesse 2025-05-07 17:59:20 +02:00
parent 6691e2e765
commit c3fce37066

View file

@ -32,14 +32,15 @@
:global LogPrint; :global LogPrint;
:do { :onerror Err {
/partitions/copy-to $FallbackTo; /partitions/copy-to $FallbackTo;
$LogPrint info $ScriptName ("Copied RouterOS to partition '" . $FallbackToName . "'."); $LogPrint info $ScriptName ("Copied RouterOS to partition '" . $FallbackToName . "'.");
:return true; } do={
} on-error={ $LogPrint error $ScriptName ("Failed copying RouterOS to partition '" . \
$LogPrint error $ScriptName ("Failed copying RouterOS to partition '" . $FallbackToName . "'!"); $FallbackToName . "': " . $Err);
:return false; :return false;
} }
:return true;
} }
:if ([ $ScriptLock $ScriptName ] = false) do={ :if ([ $ScriptLock $ScriptName ] = false) do={
@ -107,16 +108,17 @@
} }
} }
:do { :onerror Err {
/system/scheduler/add start-time=startup name="running-from-backup-partition" \ /system/scheduler/add start-time=startup name="running-from-backup-partition" \
on-event=(":log warning (\"Running from partition '\" . " . \ on-event=(":log warning (\"Running from partition '\" . " . \
"[ /partitions/get [ find where running ] name ] . \"'!\")"); "[ /partitions/get [ find where running ] name ] . \"'!\")");
/partitions/save-config-to $FallbackTo; /partitions/save-config-to $FallbackTo;
/system/scheduler/remove "running-from-backup-partition"; /system/scheduler/remove "running-from-backup-partition";
$LogPrint info $ScriptName ("Saved configuration to partition '" . $FallbackToName . "'."); $LogPrint info $ScriptName ("Saved configuration to partition '" . $FallbackToName . "'.");
} on-error={ } do={
/system/scheduler/remove [ find where name="running-from-backup-partition" ]; /system/scheduler/remove [ find where name="running-from-backup-partition" ];
$LogPrint error $ScriptName ("Failed saving configuration to partition '" . $FallbackToName . "'!"); $LogPrint error $ScriptName ("Failed saving configuration to partition '" . \
$FallbackToName . "': " . $Err);
:set PackagesUpdateBackupFailure true; :set PackagesUpdateBackupFailure true;
:set ExitOK true; :set ExitOK true;
:error false; :error false;