From 0e8262ab05b14b867a694ff51793708be570d60e Mon Sep 17 00:00:00 2001 From: Joerg Reuter Date: Sun, 17 Mar 2024 16:26:51 +0100 Subject: [PATCH] Add optional configuration options for additional parameters to restic calls, $AdditionalParameters and $SelfUpdateParameters and make self update of restic binary configurable via $AllowResticSelfUpdate config option --- backup.ps1 | 30 ++++++++++++++++-------------- config.ps1 | 3 +++ install.ps1 | 6 ++++-- 3 files changed, 23 insertions(+), 16 deletions(-) diff --git a/backup.ps1 b/backup.ps1 index 16e1f2b..470d699 100644 --- a/backup.ps1 +++ b/backup.ps1 @@ -79,10 +79,10 @@ function Set-BackupState { function Invoke-Unlock { Param($SuccessLog, $ErrorLog) - $locks = & $ResticExe list locks --no-lock -q 3>&1 2>> $ErrorLog + $locks = & $ResticExe $AdditionalParameters list locks --no-lock -q 3>&1 2>> $ErrorLog if($locks.Length -gt 0) { # unlock the repository (assumes this machine is the only one that will ever use it) - & $ResticExe unlock 3>&1 2>> $ErrorLog | Out-File -Append $SuccessLog + & $ResticExe $AdditionalParameters unlock 3>&1 2>> $ErrorLog | Out-File -Append $SuccessLog "[[Unlock]] Repository was locked. Unlocking." | Tee-Object -Append $ErrorLog | Out-File -Append $SuccessLog Start-Sleep 120 } @@ -127,7 +127,7 @@ function Invoke-Maintenance { # forget snapshots based upon the retention policy "[[Maintenance]] Start forgetting..." | Out-File -Append $SuccessLog - & $ResticExe forget $SnapshotRetentionPolicy 3>&1 2>> $ErrorLog | Out-File -Append $SuccessLog + & $ResticExe $AdditionalParameters forget $SnapshotRetentionPolicy 3>&1 2>> $ErrorLog | Out-File -Append $SuccessLog if(-not $?) { "[[Maintenance]] Forget operation completed with errors" | Tee-Object -Append $ErrorLog | Out-File -Append $SuccessLog $maintenance_success = $false @@ -136,7 +136,7 @@ function Invoke-Maintenance { # prune (remove) data from the backup step. Running this separate from `forget` because # `forget` only prunes when it detects removed snapshots upon invocation, not previously removed "[[Maintenance]] Start pruning..." | Out-File -Append $SuccessLog - & $ResticExe prune $SnapshotPrunePolicy 3>&1 2>> $ErrorLog | Out-File -Append $SuccessLog + & $ResticExe $AdditionalParameters prune $SnapshotPrunePolicy 3>&1 2>> $ErrorLog | Out-File -Append $SuccessLog if(-not $?) { "[[Maintenance]] Prune operation completed with errors" | Tee-Object -Append $ErrorLog | Out-File -Append $SuccessLog $maintenance_success = $false @@ -163,21 +163,23 @@ function Invoke-Maintenance { $Script:ResticStateLastDeepMaintenance = Get-Date } - & $ResticExe check @data_check 3>&1 2>> $ErrorLog | Out-File -Append $SuccessLog + & $ResticExe $AdditionalParameters check @data_check 3>&1 2>> $ErrorLog | Out-File -Append $SuccessLog if(-not $?) { "[[Maintenance]] Check completed with errors" | Tee-Object -Append $ErrorLog | Out-File -Append $SuccessLog $maintenance_success = $false } - # check for updated restic version - "[[Maintenance]] Checking for new version of restic..." | Out-File -Append $SuccessLog - & $ResticExe self-update 3>&1 2>> $ErrorLog | Out-File -Append $SuccessLog - if(-not $?) { - "[[Maintenance]] Self-update of restic.exe completed with errors" | Tee-Object -Append $ErrorLog | Out-File -Append $SuccessLog - $maintenance_success = $false - } + if($AllowResticSelfUpdate -eq $true) { + # check for updated restic version + "[[Maintenance]] Checking for new version of restic..." | Out-File -Append $SuccessLog + & $ResticExe $SelfUpdateParameters self-update 3>&1 2>> $ErrorLog | Out-File -Append $SuccessLog + if(-not $?) { + "[[Maintenance]] Self-update of restic.exe completed with errors" | Tee-Object -Append $ErrorLog | Out-File -Append $SuccessLog + $maintenance_success = $false + } - "[[Maintenance]] End $(Get-Date)" | Out-File -Append $SuccessLog + "[[Maintenance]] End $(Get-Date)" | Out-File -Append $SuccessLog + } if($maintenance_success -eq $true) { $Script:ResticStateLastMaintenance = Get-Date @@ -278,7 +280,7 @@ function Invoke-Backup { } else { # Launch Restic - & $ResticExe backup $folder_list $vss_option --tag "$tag" --exclude-file=$WindowsExcludeFile --exclude-file=$LocalExcludeFile $AdditionalBackupParameters 3>&1 2>> $ErrorLog | Out-File -Append $SuccessLog + & $ResticExe $AdditionalParameters backup $folder_list $vss_option --tag "$tag" --exclude-file=$WindowsExcludeFile --exclude-file=$LocalExcludeFile $AdditionalBackupParameters 3>&1 2>> $ErrorLog | Out-File -Append $SuccessLog if(-not $?) { "[[Backup]] Completed with errors" | Tee-Object -Append $ErrorLog | Out-File -Append $SuccessLog $return_value = $false diff --git a/config.ps1 b/config.ps1 index c990bce..048ff5e 100644 --- a/config.ps1 +++ b/config.ps1 @@ -1,5 +1,8 @@ # backup configuration $ExeName = "restic.exe" +$AdditionalParameters = @() +$SelfUpdateParameters = @() +$AllowResticSelfUpdate = $true $InstallPath = "C:\restic" $ResticExe = Join-Path $InstallPath $ExeName $StateFile = Join-Path $InstallPath "state.xml" diff --git a/install.ps1 b/install.ps1 index 85cbaf0..1365b3d 100644 --- a/install.ps1 +++ b/install.ps1 @@ -18,7 +18,9 @@ if(-not (Test-Path $ResticExe)) { } # Invoke restic self-update to check for a newer version -& $ResticExe self-update +if($AllowResticSelfUpdate -eq $true) { + & $ResticExe $SelfUpdateParameters self-update +} # Create log directory if it doesn't exit if(-not (Test-Path $LogPath)) { @@ -32,7 +34,7 @@ if(-not (Test-Path $LocalExcludeFile)) { } # Initialize the restic repository -& $ResticExe --verbose init +& $ResticExe $AdditionalParameters --verbose init if($?) { Write-Output "[[Init]] Repository successfully initialized." }