add custom actions configuration to enable invoking scripts other commands on script start and end. Defined by $CustomAction* config variables.

This commit is contained in:
Kevin Woley
2025-02-08 00:29:06 -08:00
parent 7c0111308a
commit eaf97cd2d7
2 changed files with 29 additions and 1 deletions

View File

@@ -546,6 +546,11 @@ function Invoke-Main {
exit 1
}
# custom start action
if($null -ne $CustomActionStart) {
Invoke-Expression $CustomActionStart
}
$error_count = 0
$backup_success = $false
$maintenance_success = $false
@@ -671,6 +676,20 @@ function Invoke-Main {
}
}
# custom end actions
if((-not $backup_success) -or ($maintenance_needed -and -not $maintenance_success)) {
# call the custom error action if backup failed and/or maintenance was needed and failed
if($null -ne $CustomActionEndError) {
Invoke-Expression $CustomActionEndError
}
}
else {
# call custom success action if backup & maintenance were successful
if($null -ne $CustomActionEndSuccess) {
Invoke-Expression $CustomActionEndSuccess
}
}
# Save state to file
Set-BackupState

View File

@@ -40,4 +40,13 @@ $SnapshotMaintenanceDays = 30
$SnapshotDeepMaintenanceDays = 90
# restic.exe self update configuration
$SelfUpdateEnabled = $true
$SelfUpdateEnabled = $true
# (optional) custom actions
# Define commands to pass to Invoke-Expression at script start and end
# note: Errors will only be reported if the script does not eventually succeed. Errors
# from unsuccessful attempts to backup or maintain the repository will not result
# in the custom error action being called unless all attempts failed.
$CustomActionStart = $null
$CustomActionEndError = $null
$CustomActionEndSuccess = $null