Merge pull request #96 from woelfisch/main

Add optional configuration options for additional parameters to resti…
This commit is contained in:
Kevin Woley
2025-01-26 00:03:30 -08:00
committed by GitHub
3 changed files with 23 additions and 16 deletions

View File

@@ -79,10 +79,10 @@ function Set-BackupState {
function Invoke-Unlock { function Invoke-Unlock {
Param($SuccessLog, $ErrorLog) 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) { if($locks.Length -gt 0) {
# unlock the repository (assumes this machine is the only one that will ever use it) # 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 "[[Unlock]] Repository was locked. Unlocking." | Tee-Object -Append $ErrorLog | Out-File -Append $SuccessLog
Start-Sleep 120 Start-Sleep 120
} }
@@ -127,7 +127,7 @@ function Invoke-Maintenance {
# forget snapshots based upon the retention policy # forget snapshots based upon the retention policy
"[[Maintenance]] Start forgetting..." | Out-File -Append $SuccessLog "[[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 $?) { if(-not $?) {
"[[Maintenance]] Forget operation completed with errors" | Tee-Object -Append $ErrorLog | Out-File -Append $SuccessLog "[[Maintenance]] Forget operation completed with errors" | Tee-Object -Append $ErrorLog | Out-File -Append $SuccessLog
$maintenance_success = $false $maintenance_success = $false
@@ -136,7 +136,7 @@ function Invoke-Maintenance {
# prune (remove) data from the backup step. Running this separate from `forget` because # 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 # `forget` only prunes when it detects removed snapshots upon invocation, not previously removed
"[[Maintenance]] Start pruning..." | Out-File -Append $SuccessLog "[[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 $?) { if(-not $?) {
"[[Maintenance]] Prune operation completed with errors" | Tee-Object -Append $ErrorLog | Out-File -Append $SuccessLog "[[Maintenance]] Prune operation completed with errors" | Tee-Object -Append $ErrorLog | Out-File -Append $SuccessLog
$maintenance_success = $false $maintenance_success = $false
@@ -163,21 +163,23 @@ function Invoke-Maintenance {
$Script:ResticStateLastDeepMaintenance = Get-Date $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 $?) { if(-not $?) {
"[[Maintenance]] Check completed with errors" | Tee-Object -Append $ErrorLog | Out-File -Append $SuccessLog "[[Maintenance]] Check completed with errors" | Tee-Object -Append $ErrorLog | Out-File -Append $SuccessLog
$maintenance_success = $false $maintenance_success = $false
} }
# check for updated restic version if($AllowResticSelfUpdate -eq $true) {
"[[Maintenance]] Checking for new version of restic..." | Out-File -Append $SuccessLog # check for updated restic version
& $ResticExe self-update 3>&1 2>> $ErrorLog | Out-File -Append $SuccessLog "[[Maintenance]] Checking for new version of restic..." | Out-File -Append $SuccessLog
if(-not $?) { & $ResticExe $SelfUpdateParameters self-update 3>&1 2>> $ErrorLog | Out-File -Append $SuccessLog
"[[Maintenance]] Self-update of restic.exe completed with errors" | Tee-Object -Append $ErrorLog | Out-File -Append $SuccessLog if(-not $?) {
$maintenance_success = $false "[[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) { if($maintenance_success -eq $true) {
$Script:ResticStateLastMaintenance = Get-Date $Script:ResticStateLastMaintenance = Get-Date
@@ -278,7 +280,7 @@ function Invoke-Backup {
} }
else { else {
# Launch Restic # 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 backup $folder_list $vss_option --tag $tag --exclude-file=$WindowsExcludeFile --exclude-file=$LocalExcludeFile $AdditionalParameters $AdditionalBackupParameters 3>&1 2>> $ErrorLog | Out-File -Append $SuccessLog
if(-not $?) { if(-not $?) {
"[[Backup]] Completed with errors" | Tee-Object -Append $ErrorLog | Out-File -Append $SuccessLog "[[Backup]] Completed with errors" | Tee-Object -Append $ErrorLog | Out-File -Append $SuccessLog
$return_value = $false $return_value = $false

View File

@@ -1,5 +1,8 @@
# backup configuration # backup configuration
$ExeName = "restic.exe" $ExeName = "restic.exe"
$AdditionalParameters = @()
$SelfUpdateParameters = @()
$AllowResticSelfUpdate = $true
$InstallPath = "C:\restic" $InstallPath = "C:\restic"
$ResticExe = Join-Path $InstallPath $ExeName $ResticExe = Join-Path $InstallPath $ExeName
$StateFile = Join-Path $InstallPath "state.xml" $StateFile = Join-Path $InstallPath "state.xml"

View File

@@ -18,7 +18,9 @@ if(-not (Test-Path $ResticExe)) {
} }
# Invoke restic self-update to check for a newer version # 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 # Create log directory if it doesn't exit
if(-not (Test-Path $LogPath)) { if(-not (Test-Path $LogPath)) {
@@ -32,7 +34,7 @@ if(-not (Test-Path $LocalExcludeFile)) {
} }
# Initialize the restic repository # Initialize the restic repository
& $ResticExe --verbose init & $ResticExe $AdditionalParameters --verbose init
if($?) { if($?) {
Write-Output "[[Init]] Repository successfully initialized." Write-Output "[[Init]] Repository successfully initialized."
} }