From 626ac2a0c5e49ba9f7e9ab4f0167cabc468729e9 Mon Sep 17 00:00:00 2001 From: Phlogi Date: Mon, 26 Oct 2020 07:56:58 +0100 Subject: [PATCH 1/7] Fix URI parsing Tested only for sftp. Without the leading ..// the System.Uri will fail on the next line, as the string is empty. --- backup.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backup.ps1 b/backup.ps1 index 60a05cf..8a8db22 100644 --- a/backup.ps1 +++ b/backup.ps1 @@ -244,7 +244,7 @@ function Invoke-ConnectivityCheck { else { # parse connection string for hostname # Uri parser doesn't handle leading connection type info (s3:, sftp:, rest:) - $connection_string = $env:RESTIC_REPOSITORY -replace "^s3:" -replace "^sftp:" -replace "^rest:" + $connection_string = $env:RESTIC_REPOSITORY -replace "^s3:","s3://" -replace "^sftp:","sftp://" -replace "^rest:","rest://" $repository_host = ([System.Uri]$connection_string).host } @@ -364,4 +364,4 @@ function Invoke-Main { exit $error_count } -Invoke-Main \ No newline at end of file +Invoke-Main From 471cf57b7eb5c54a789bbe34e5799246fe5b8c52 Mon Sep 17 00:00:00 2001 From: Tony Scelfo Date: Fri, 8 Jan 2021 14:17:34 -0700 Subject: [PATCH 2/7] Add '-ExecutionPolicy Bypass' to the task scheduler arguments to avoid the issue described in https://github.com/kmwoley/restic-windows-backup/issues/27. --- install.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install.ps1 b/install.ps1 index aa8df60..ad590ea 100644 --- a/install.ps1 +++ b/install.ps1 @@ -43,7 +43,7 @@ $backup_task_name = "Restic Backup" $backup_task = Get-ScheduledTask $backup_task_name -ErrorAction SilentlyContinue if($null -eq $backup_task) { try { - $task_action = New-ScheduledTaskAction -Execute 'powershell.exe' -Argument '-NonInteractive -NoLogo -NoProfile -Command ".\backup.ps1; exit $LASTEXITCODE"' -WorkingDirectory $InstallPath + $task_action = New-ScheduledTaskAction -Execute 'powershell.exe' -Argument '-ExecutionPolicy Bypass -NonInteractive -NoLogo -NoProfile -Command ".\backup.ps1; exit $LASTEXITCODE"' -WorkingDirectory $InstallPath $task_user = New-ScheduledTaskPrincipal -UserId "NT AUTHORITY\SYSTEM" -RunLevel Highest $task_settings = New-ScheduledTaskSettingsSet -RestartCount 4 -RestartInterval (New-TimeSpan -Minutes 15) -ExecutionTimeLimit (New-TimeSpan -Days 3) -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries -DontStopOnIdleEnd -MultipleInstances IgnoreNew -IdleDuration 0 -IdleWaitTimeout 0 -StartWhenAvailable -RestartOnIdle $task_trigger = New-ScheduledTaskTrigger -Daily -At 4:00am From eaaccc4c9edf0e73f32866d815bba4f2f71e7997 Mon Sep 17 00:00:00 2001 From: Kevin Woley Date: Mon, 22 Feb 2021 04:28:20 -0800 Subject: [PATCH 3/7] remove conflicting verbose/quiet resolves #29 --- backup.ps1 | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/backup.ps1 b/backup.ps1 index dcc85d3..307b67d 100644 --- a/backup.ps1 +++ b/backup.ps1 @@ -67,7 +67,7 @@ function Invoke-Maintenance { # forget snapshots based upon the retention policy Write-Output "[[Maintenance]] Start forgetting..." | Tee-Object -Append $SuccessLog - & $ResticExe --verbose -q forget $SnapshotRetentionPolicy 3>&1 2>> $ErrorLog | Tee-Object -Append $SuccessLog + & $ResticExe forget $SnapshotRetentionPolicy 3>&1 2>> $ErrorLog | Tee-Object -Append $SuccessLog if(-not $?) { Write-Output "[[Maintenance]] Forget operation completed with errors" | Tee-Object -Append $ErrorLog | Tee-Object -Append $SuccessLog $maintenance_success = $false @@ -76,7 +76,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 Write-Output "[[Maintenance]] Start pruning..." | Tee-Object -Append $SuccessLog - & $ResticExe --verbose -q prune 3>&1 2>> $ErrorLog | Tee-Object -Append $SuccessLog + & $ResticExe prune 3>&1 2>> $ErrorLog | Tee-Object -Append $SuccessLog if(-not $?) { Write-Output "[[Maintenance]] Prune operation completed with errors" | Tee-Object -Append $ErrorLog | Tee-Object -Append $SuccessLog $maintenance_success = $false @@ -103,7 +103,7 @@ function Invoke-Maintenance { $Script:ResticStateLastDeepMaintenance = Get-Date } - & $ResticExe --verbose -q check @data_check 3>&1 2>> $ErrorLog | Tee-Object -Append $SuccessLog + & $ResticExe check @data_check 3>&1 2>> $ErrorLog | Tee-Object -Append $SuccessLog if(-not $?) { Write-Output "[[Maintenance]] Check completed with errors" | Tee-Object -Append $ErrorLog | Tee-Object -Append $SuccessLog $maintenance_success = $false @@ -113,7 +113,7 @@ function Invoke-Maintenance { if($maintenance_success -eq $true) { $Script:ResticStateLastMaintenance = Get-Date - $Script:ResticStateMaintenanceCounter = 0; + $Script:ResticStateMaintenanceCounter = 0 } } @@ -166,7 +166,7 @@ function Invoke-Backup { } # Launch Restic - & $ResticExe --verbose -q backup $folder_list --exclude-file=$WindowsExcludeFile --exclude-file=$LocalExcludeFile 3>&1 2>> $ErrorLog | Tee-Object -Append $SuccessLog + & $ResticExe backup $folder_list --exclude-file=$WindowsExcludeFile --exclude-file=$LocalExcludeFile 3>&1 2>> $ErrorLog | Tee-Object -Append $SuccessLog if(-not $?) { Write-Output "[[Backup]] Completed with errors" | Tee-Object -Append $ErrorLog | Tee-Object -Append $SuccessLog $return_value = $false From 6227786ae2a0a8d5933dd44d9566a756a0129d98 Mon Sep 17 00:00:00 2001 From: Kevin Woley Date: Mon, 22 Feb 2021 04:28:20 -0800 Subject: [PATCH 4/7] remove conflicting verbose/quiet resolves #29 --- backup.ps1 | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/backup.ps1 b/backup.ps1 index 60a05cf..b4285b5 100644 --- a/backup.ps1 +++ b/backup.ps1 @@ -67,7 +67,7 @@ function Invoke-Maintenance { # forget snapshots based upon the retention policy Write-Output "[[Maintenance]] Start forgetting..." | Tee-Object -Append $SuccessLog - & $ResticExe --verbose -q forget $SnapshotRetentionPolicy 3>&1 2>> $ErrorLog | Tee-Object -Append $SuccessLog + & $ResticExe forget $SnapshotRetentionPolicy 3>&1 2>> $ErrorLog | Tee-Object -Append $SuccessLog if(-not $?) { Write-Output "[[Maintenance]] Forget operation completed with errors" | Tee-Object -Append $ErrorLog | Tee-Object -Append $SuccessLog $maintenance_success = $false @@ -76,7 +76,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 Write-Output "[[Maintenance]] Start pruning..." | Tee-Object -Append $SuccessLog - & $ResticExe --verbose -q prune 3>&1 2>> $ErrorLog | Tee-Object -Append $SuccessLog + & $ResticExe prune 3>&1 2>> $ErrorLog | Tee-Object -Append $SuccessLog if(-not $?) { Write-Output "[[Maintenance]] Prune operation completed with errors" | Tee-Object -Append $ErrorLog | Tee-Object -Append $SuccessLog $maintenance_success = $false @@ -103,7 +103,7 @@ function Invoke-Maintenance { $Script:ResticStateLastDeepMaintenance = Get-Date } - & $ResticExe --verbose -q check @data_check 3>&1 2>> $ErrorLog | Tee-Object -Append $SuccessLog + & $ResticExe check @data_check 3>&1 2>> $ErrorLog | Tee-Object -Append $SuccessLog if(-not $?) { Write-Output "[[Maintenance]] Check completed with errors" | Tee-Object -Append $ErrorLog | Tee-Object -Append $SuccessLog $maintenance_success = $false @@ -113,7 +113,7 @@ function Invoke-Maintenance { if($maintenance_success -eq $true) { $Script:ResticStateLastMaintenance = Get-Date - $Script:ResticStateMaintenanceCounter = 0; + $Script:ResticStateMaintenanceCounter = 0 } } @@ -166,7 +166,7 @@ function Invoke-Backup { } # Launch Restic - & $ResticExe --verbose -q backup $folder_list --exclude-file=$WindowsExcludeFile --exclude-file=$LocalExcludeFile 3>&1 2>> $ErrorLog | Tee-Object -Append $SuccessLog + & $ResticExe backup $folder_list --exclude-file=$WindowsExcludeFile --exclude-file=$LocalExcludeFile 3>&1 2>> $ErrorLog | Tee-Object -Append $SuccessLog if(-not $?) { Write-Output "[[Backup]] Completed with errors" | Tee-Object -Append $ErrorLog | Tee-Object -Append $SuccessLog $return_value = $false From 6bfba97a4c6fdde60aeb8dc6ab470925b02a1ce5 Mon Sep 17 00:00:00 2001 From: Kevin Woley Date: Mon, 22 Feb 2021 05:36:53 -0800 Subject: [PATCH 5/7] reverting the fix for URL parsing --- backup.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backup.ps1 b/backup.ps1 index f398384..7cd5fa3 100644 --- a/backup.ps1 +++ b/backup.ps1 @@ -244,7 +244,7 @@ function Invoke-ConnectivityCheck { else { # parse connection string for hostname # Uri parser doesn't handle leading connection type info (s3:, sftp:, rest:) - $connection_string = $env:RESTIC_REPOSITORY -replace "^s3:","s3://" -replace "^sftp:","sftp://" -replace "^rest:","rest://" + $connection_string = $env:RESTIC_REPOSITORY -replace "^s3:" -replace "^sftp:" -replace "^rest:" $repository_host = ([System.Uri]$connection_string).host } From 1eaef5f0c86824303cd57643d004e86582a608b5 Mon Sep 17 00:00:00 2001 From: Kevin Woley Date: Mon, 22 Feb 2021 20:34:53 -0800 Subject: [PATCH 6/7] add error logging to sending emails improve general error messaging resolves #25 --- backup.ps1 | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/backup.ps1 b/backup.ps1 index 7cd5fa3..bd4ff19 100644 --- a/backup.ps1 +++ b/backup.ps1 @@ -213,7 +213,19 @@ function Send-Email { } if((($status -eq "SUCCESS") -and ($SendEmailOnSuccess -ne $false)) -or ((($status -eq "ERROR") -or $success_after_failure) -and ($SendEmailOnError -ne $false))) { $subject = "$env:COMPUTERNAME Restic Backup Report [$status]" - Send-MailMessage @ResticEmailConfig -From $ResticEmailFrom -To $ResticEmailTo -Credential $credentials -Subject $subject -Body $body @attachments + + # create a temporary error log to log errors; can't write to the same file that Send-MailMessage is reading + $temp_error_log = $ErrorLog + "_temp" + + Send-MailMessage @ResticEmailConfig -From $ResticEmailFrom -To $ResticEmailTo -Credential $credentials -Subject $subject -Body $body @attachments 3>&1 2>> $temp_error_log + + if(-not $?) { + Write-Output "[[Email]] Sending email completed with errors" | Tee-Object -Append $temp_error_log | Tee-Object -Append $SuccessLog + } + + # join error logs and remove the temporary + Get-Content $temp_error_log | Add-Content $ErrorLog + Remove-Item $temp_error_log } } @@ -337,15 +349,15 @@ function Invoke-Main { } } - Write-Warning "Errors found! Error Log: $error_log" + Write-Output "[[General]] Errors found. Log: $error_log" | Tee-Object -Append $success_log | Tee-Object -Append $error_log $error_count++ $attempt_count-- if($attempt_count -gt 0) { - Write-Output "Sleeping for 15 min and then retrying..." | Tee-Object -Append $success_log + Write-Output "[[Retry]] Sleeping for 15 min and then retrying..." | Tee-Object -Append $success_log } else { - Write-Output "Retry limit has been reached. No more attempts to backup will be made." | Tee-Object -Append $success_log + Write-Output "[[Retry]] Retry limit has been reached. No more attempts to backup will be made." | Tee-Object -Append $success_log } if($internet_available -eq $true) { Invoke-HistoryCheck $success_log $error_log From cdba59be95c8af24e5843e4ea86c78f757a49e79 Mon Sep 17 00:00:00 2001 From: Kevin Woley Date: Mon, 22 Feb 2021 21:01:20 -0800 Subject: [PATCH 7/7] Update changelog --- CHANGELOG.md | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d65f3d7..1add9d7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,16 +1,33 @@ # Changelog -## [1.2.1](https://github.com/kmwoley/restic-windows-backup/tree/HEAD) (2020-06-08) +## [1.3](https://github.com/kmwoley/restic-windows-backup/tree/HEAD) -[Full Changelog](https://github.com/kmwoley/restic-windows-backup/compare/1.1...HEAD) +[Full Changelog](https://github.com/kmwoley/restic-windows-backup/compare/1.2.1...HEAD) + +Improvements for Restic 0.12 and additional error logging. + +**Closed issues:** + +- Restic + rclone errors [\#26](https://github.com/kmwoley/restic-windows-backup/issues/26) +- FYI: Restic now has built-in VSS support [\#23](https://github.com/kmwoley/restic-windows-backup/issues/23) +- SFTP backup [\#22](https://github.com/kmwoley/restic-windows-backup/issues/22) +- Dirrectory/Folder Backup [\#21](https://github.com/kmwoley/restic-windows-backup/issues/21) +- Docker format [\#20](https://github.com/kmwoley/restic-windows-backup/issues/20) +- Filtering out errors before deciding to retry ? [\#19](https://github.com/kmwoley/restic-windows-backup/issues/19) +- Backup task stucked [\#18](https://github.com/kmwoley/restic-windows-backup/issues/18) + +## [1.2.1](https://github.com/kmwoley/restic-windows-backup/tree/1.2.1) (2020-06-08) + +[Full Changelog](https://github.com/kmwoley/restic-windows-backup/compare/1.1...1.2.1) -* Fix/improve internet connectivity checks for azure: gs: b2: * Internet connectivity test now supports more repository types (s3:, sftp:, rest:, azure:, gs:), and ignores unsupported (swift:, rclone: and local) * Add 32-bit support in the `install.ps1` +* Fix/improve internet connectivity checks for azure: gs: b2: **Closed issues:** +- azure repo could not be parsed [\#15](https://github.com/kmwoley/restic-windows-backup/issues/15) - Need to strip rest: in addition to s3: from RESTIC\_REPOSITORY [\#14](https://github.com/kmwoley/restic-windows-backup/issues/14) - Use non-s3 repos [\#10](https://github.com/kmwoley/restic-windows-backup/issues/10) - Test-Connection fails [\#9](https://github.com/kmwoley/restic-windows-backup/issues/9) @@ -19,6 +36,7 @@ **Merged pull requests:** +- Release 1 3 [\#17](https://github.com/kmwoley/restic-windows-backup/pull/17) ([kmwoley](https://github.com/kmwoley)) - 1.2 Release [\#13](https://github.com/kmwoley/restic-windows-backup/pull/13) ([kmwoley](https://github.com/kmwoley)) ## [1.1](https://github.com/kmwoley/restic-windows-backup/tree/1.1) (2020-02-15)