12 Commits
1.1 ... 1.2.1

Author SHA1 Message Date
Kevin Woley
eba7f4d10a Merge pull request #17 from kmwoley/release_1_3
Release 1 3
2020-06-08 09:43:22 -07:00
Kevin Woley
9dba4fd40b adding changelog
closes #15
2020-06-08 09:41:26 -07:00
Kevin Woley
229d21d753 add "generic" repo specific url internet tests 2020-06-08 08:39:07 -07:00
Kevin Woley
69e8a23b36 remove azure, gs, and b2 from connectivity check 2020-06-08 07:48:57 -07:00
Kevin Woley
63a8bb9218 retry error messaging improvements 2020-04-30 09:49:49 -07:00
Kevin Woley
7cff028471 send email on first success after a failure
(if SendEmailOnError is enabled)
2020-04-29 14:39:54 -07:00
Kevin Woley
102bc0ccc9 Add Zoom, VS Code, Signal, and Spotify to default exclude list 2020-04-28 20:58:36 -07:00
Kevin Woley
88bc571998 Add date to Release 1.2 2020-04-28 20:44:39 -07:00
Kevin Woley
7d7978f0cc Merge pull request #13 from kmwoley/option-refinement
1.2 Release
2020-04-28 20:42:49 -07:00
Kevin Woley
6edfe75696 Changelog update. 2020-04-28 20:41:08 -07:00
Kevin Woley
5ef9e3bb53 add 32-bit windows support to the install
Closes #7
2020-04-28 20:28:08 -07:00
Kevin Woley
b73008a5f1 internet connectivity check handles all repo types
Closes #10
2020-04-28 20:08:41 -07:00
4 changed files with 88 additions and 13 deletions

View File

@@ -1,5 +1,26 @@
# Changelog
## [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)
@@ -21,6 +42,7 @@ $SendEmailOnError = $true
**Merged pull requests:**
- add changelog [\#6](https://github.com/kmwoley/restic-windows-backup/pull/6) ([kmwoley](https://github.com/kmwoley))
- add options to enable/disable email sending and maintenance [\#4](https://github.com/kmwoley/restic-windows-backup/pull/4) ([kmwoley](https://github.com/kmwoley))
## [1.0](https://github.com/kmwoley/restic-windows-backup/tree/1.0) (2020-02-09)

View File

@@ -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
}
@@ -212,12 +219,39 @@ function Send-Email {
function Invoke-ConnectivityCheck {
Param($SuccessLog, $ErrorLog)
# parse connection string for hostname
# TODO: handle non-s3 repositories
# Uri parser doesn't handle leading connection type info
$connection_string = $env:RESTIC_REPOSITORY -replace "s3:"
$repository_host = ([System.Uri]$connection_string).host
# 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
}
$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
return $false
}
# test for internet connectivity
$connections = 0
@@ -225,7 +259,7 @@ function Invoke-ConnectivityCheck {
while($true) {
$connections = Get-NetRoute | Where-Object DestinationPrefix -eq '0.0.0.0/0' | Get-NetIPInterface | Where-Object ConnectionState -eq 'Connected' | Measure-Object | ForEach-Object{$_.Count}
if($sleep_count -le 0) {
Write-Output "[[Internet]] Connection to repository could not be established." | Tee-Object -Append $SuccessLog | Tee-Object -Append $ErrorLog
Write-Output "[[Internet]] Connection to repository ($repository_host) could not be established." | Tee-Object -Append $SuccessLog | Tee-Object -Append $ErrorLog
return $false
}
if(($null -eq $connections) -or ($connections -eq 0)) {
@@ -246,7 +280,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
@@ -306,13 +340,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

View File

@@ -3,7 +3,13 @@
# download restic
if(-not (Test-Path $ResticExe)) {
$url = "https://github.com/restic/restic/releases/download/v0.9.6/restic_0.9.6_windows_amd64.zip"
$url = $null
if([Environment]::Is64BitOperatingSystem){
$url = "https://github.com/restic/restic/releases/download/v0.9.6/restic_0.9.6_windows_amd64.zip"
}
else {
$url = "https://github.com/restic/restic/releases/download/v0.9.6/restic_0.9.6_windows_386.zip"
}
$output = Join-Path $InstallPath "restic.zip"
Invoke-WebRequest -Uri $url -OutFile $output
Expand-Archive -LiteralPath $output $InstallPath

View File

@@ -52,6 +52,12 @@ AppData\Local\Microsoft\Windows Store
AppData\Local\restic
AppData\LocalLow\Microsoft\CryptnetUrlCache
AppData\Local\IsolatedStorage
AppData\Local\Spotify
AppData\Local\Programs\signal-desktop
AppData\Roaming\Code
AppData\Roaming\Slack
AppData\Roaming\Spotify
AppData\Roaming\Zoom
# misc. temporary files
Temporary Internet Files