From 7cff028471498b1bcd156362dde6074360b9798c Mon Sep 17 00:00:00 2001 From: Kevin Woley Date: Wed, 29 Apr 2020 14:39:54 -0700 Subject: [PATCH 1/5] send email on first success after a failure (if SendEmailOnError is enabled) --- backup.ps1 | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/backup.ps1 b/backup.ps1 index dcc85d3..5f86393 100644 --- a/backup.ps1 +++ b/backup.ps1 @@ -191,9 +191,16 @@ function Send-Email { $credentials = New-Object System.Management.Automation.PSCredential ($ResticEmailUsername, $password) $status = "SUCCESS" + $success_after_failure = $false $body = "" if (($null -ne $SuccessLog) -and (Test-Path $SuccessLog) -and (Get-Item $SuccessLog).Length -gt 0) { $body = $(Get-Content -Raw $SuccessLog) + # if previous run contained an error, send the success email confirming that the error has been resolved + # (i.e. get previous error log, if it's not empty, trigger the send of the success-after-failure email) + $previous_error_log = Get-ChildItem $LogPath -Filter '*err.txt' | Sort-Object -Descending LastWriteTime | Select-Object -Skip 1 | Select-Object -First 1 + if(($null -ne $previous_error_log) -and ($previous_error_log.Length -gt 0)){ + $success_after_failure = $true + } } else { $body = "Crtical Error! Restic backup log is empty or missing. Check log file path." @@ -204,7 +211,7 @@ function Send-Email { $attachments = @{Attachments = $ErrorLog} $status = "ERROR" } - if((($status -eq "SUCCESS") -and ($SendEmailOnSuccess -ne $false)) -or (($status -eq "ERROR") -and ($SendEmailOnError -ne $false))) { + 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 } @@ -255,7 +262,7 @@ function Invoke-ConnectivityCheck { # check previous logs function Invoke-HistoryCheck { Param($SuccessLog, $ErrorLog) - $logs = Get-ChildItem $LogPath -Filter '*err.txt' | %{$_.Length -gt 0} + $logs = Get-ChildItem $LogPath -Filter '*err.txt' | ForEach-Object{$_.Length -gt 0} $logs_with_success = ($logs | Where-Object {($_ -eq $false)}).Count if($logs.Count -gt 0) { Write-Output "[[History]] Backup success rate: $logs_with_success / $($logs.Count) ($(($logs_with_success / $logs.Count).tostring("P")))" | Tee-Object -Append $SuccessLog From 63a8bb9218d897b43f5efeb9ef6931a0ad84d32d Mon Sep 17 00:00:00 2001 From: Kevin Woley Date: Thu, 30 Apr 2020 09:49:49 -0700 Subject: [PATCH 2/5] retry error messaging improvements --- backup.ps1 | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/backup.ps1 b/backup.ps1 index 5f86393..afc1d2f 100644 --- a/backup.ps1 +++ b/backup.ps1 @@ -322,13 +322,20 @@ function Invoke-Main { Write-Warning "Errors found! Error Log: $error_log" $error_count++ - Write-Output "Something went wrong. Sleeping for 15 min and then retrying..." | Tee-Object -Append $success_log + $attempt_count-- + if($attempt_count -gt 0) { + Write-Output "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 + } if($internet_available -eq $true) { Invoke-HistoryCheck $success_log $error_log Send-Email $success_log $error_log } - Start-Sleep (15*60) - $attempt_count-- + if($attempt_count -gt 0) { + Start-Sleep (15*60) + } } Set-BackupState From 69e8a23b36e3f9b229bbd66f0183cb84ca30d76f Mon Sep 17 00:00:00 2001 From: Kevin Woley Date: Mon, 8 Jun 2020 07:48:57 -0700 Subject: [PATCH 3/5] remove azure, gs, and b2 from connectivity check --- backup.ps1 | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/backup.ps1 b/backup.ps1 index afc1d2f..7acb3d0 100644 --- a/backup.ps1 +++ b/backup.ps1 @@ -219,15 +219,20 @@ function Send-Email { function Invoke-ConnectivityCheck { Param($SuccessLog, $ErrorLog) - # Skip the internet connectivity check unsupported repo types (i.e. swift:, rclone:, or local ) - if(($env:RESTIC_REPOSITORY -match "^swift:") -or ($env:RESTIC_REPOSITORY -match "^rclone:") -or (Test-Path $env:RESTIC_REPOSITORY)) { + # Skip the internet connectivity check for unsupported repo types (e.g. swift:, rclone:, local, etc. ) + if(($env:RESTIC_REPOSITORY -match "^swift:") -or + ($env:RESTIC_REPOSITORY -match "^rclone:") -or + ($env:RESTIC_REPOSITORY -match "^b2:") -or + ($env:RESTIC_REPOSITORY -match "^azure:") -or + ($env:RESTIC_REPOSITORY -match "^gs:") -or + (Test-Path $env:RESTIC_REPOSITORY)) { Write-Output "[[Internet]] Skipping internet connectivity check." | Tee-Object -Append $SuccessLog return $true } # parse connection string for hostname - # Uri parser doesn't handle leading connection type info (s3:, sftp:, rest:, azure:, gs:) - $connection_string = $env:RESTIC_REPOSITORY -replace "^s3:" -replace "^sftp:" -replace "^rest:" -replace "^azure:" -replace "^gs:" + # Uri parser doesn't handle leading connection type info (s3:, sftp:, rest:) + $connection_string = $env:RESTIC_REPOSITORY -replace "^s3:" -replace "^sftp:" -replace "^rest:" $repository_host = ([System.Uri]$connection_string).host if([string]::IsNullOrEmpty($repository_host)) { From 229d21d753a59196708668b066d9856b4434f755 Mon Sep 17 00:00:00 2001 From: Kevin Woley Date: Mon, 8 Jun 2020 08:39:07 -0700 Subject: [PATCH 4/5] add "generic" repo specific url internet tests --- backup.ps1 | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/backup.ps1 b/backup.ps1 index 7acb3d0..60a05cf 100644 --- a/backup.ps1 +++ b/backup.ps1 @@ -219,21 +219,34 @@ function Send-Email { function Invoke-ConnectivityCheck { Param($SuccessLog, $ErrorLog) - # Skip the internet connectivity check for unsupported repo types (e.g. swift:, rclone:, local, etc. ) - if(($env:RESTIC_REPOSITORY -match "^swift:") -or - ($env:RESTIC_REPOSITORY -match "^rclone:") -or - ($env:RESTIC_REPOSITORY -match "^b2:") -or - ($env:RESTIC_REPOSITORY -match "^azure:") -or - ($env:RESTIC_REPOSITORY -match "^gs:") -or - (Test-Path $env:RESTIC_REPOSITORY)) { + # skip the internet connectivity check for local repos + if(Test-Path $env:RESTIC_REPOSITORY) { Write-Output "[[Internet]] Skipping internet connectivity check." | Tee-Object -Append $SuccessLog return $true } - # 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:" - $repository_host = ([System.Uri]$connection_string).host + $repository_host = '' + + # use generic internet service for non-specific repo types (e.g. swift:, rclone:, etc. ) + if(($env:RESTIC_REPOSITORY -match "^swift:") -or + ($env:RESTIC_REPOSITORY -match "^rclone:")) { + $repository_host = "cloudflare.com" + } + elseif($env:RESTIC_REPOSITORY -match "^b2:") { + $repository_host = "api.backblazeb2.com" + } + elseif($env:RESTIC_REPOSITORY -match "^azure:") { + $repository_host = "azure.microsoft.com" + } + elseif($env:RESTIC_REPOSITORY -match "^gs:") { + $repository_host = "storage.googleapis.com" + } + 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:" + $repository_host = ([System.Uri]$connection_string).host + } if([string]::IsNullOrEmpty($repository_host)) { Write-Output "[[Internet]] Repository string could not be parsed." | Tee-Object -Append $SuccessLog | Tee-Object -Append $ErrorLog From 9dba4fd40b336244c0025a23cccc3b500fe2a489 Mon Sep 17 00:00:00 2001 From: Kevin Woley Date: Mon, 8 Jun 2020 09:41:26 -0700 Subject: [PATCH 5/5] adding changelog closes #15 --- CHANGELOG.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c66ecd7..d65f3d7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,19 +1,26 @@ # Changelog -## [1.2](https://github.com/kmwoley/restic-windows-backup/tree/HEAD) (2020-04-28) +## [1.2.1](https://github.com/kmwoley/restic-windows-backup/tree/HEAD) (2020-06-08) [Full Changelog](https://github.com/kmwoley/restic-windows-backup/compare/1.1...HEAD) +* 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` **Closed issues:** +- 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) +- 32bit Windows Support [\#7](https://github.com/kmwoley/restic-windows-backup/issues/7) - Add changelog [\#1](https://github.com/kmwoley/restic-windows-backup/issues/1) +**Merged pull requests:** + +- 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) [Full Changelog](https://github.com/kmwoley/restic-windows-backup/compare/1.0...1.1)