Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
be35fd5e7b | ||
|
|
716e98563b | ||
|
|
f8e9653aa9 | ||
|
|
ab15f5387b | ||
|
|
0334de5546 | ||
|
|
7f576135fc |
32
CHANGELOG.md
Normal file
32
CHANGELOG.md
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
# Changelog
|
||||||
|
|
||||||
|
## [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)
|
||||||
|
|
||||||
|
* Users can now set the following variables to control sending emails on success and/or error conditions.
|
||||||
|
* Users can now completely disable maintenance activities.
|
||||||
|
|
||||||
|
New `config.ps1` variable defaults for these options are:
|
||||||
|
```
|
||||||
|
$SnapshotMaintenanceEnabled = $true
|
||||||
|
$SendEmailOnSuccess = $false
|
||||||
|
$SendEmailOnError = $true
|
||||||
|
```
|
||||||
|
|
||||||
|
**Closed issues:**
|
||||||
|
|
||||||
|
- Ability to disable maintenance [\#3](https://github.com/kmwoley/restic-windows-backup/issues/3)
|
||||||
|
- Ability to disable mail sending [\#2](https://github.com/kmwoley/restic-windows-backup/issues/2)
|
||||||
|
|
||||||
|
**Merged pull requests:**
|
||||||
|
|
||||||
|
- 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)
|
||||||
|
|
||||||
|
[Full Changelog](https://github.com/kmwoley/restic-windows-backup/compare/34eae241aa1dcf08ed1d4d4f930e1d1a5bf5788a...1.0)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
\* *This Changelog was automatically generated by [github_changelog_generator](https://github.com/github-changelog-generator/github-changelog-generator)*
|
||||||
27
backup.ps1
27
backup.ps1
@@ -45,6 +45,12 @@ function Invoke-Unlock {
|
|||||||
function Invoke-Maintenance {
|
function Invoke-Maintenance {
|
||||||
Param($SuccessLog, $ErrorLog)
|
Param($SuccessLog, $ErrorLog)
|
||||||
|
|
||||||
|
# skip maintenance if disabled
|
||||||
|
if($SnapshotMaintenanceEnabled -eq $false) {
|
||||||
|
Write-Output "[[Maintenance]] Skipped - maintenance disabled" | Tee-Object -Append $SuccessLog
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
# skip maintenance if it's been done recently
|
# skip maintenance if it's been done recently
|
||||||
if(($null -ne $ResticStateLastMaintenance) -and ($null -ne $ResticStateMaintenanceCounter)) {
|
if(($null -ne $ResticStateLastMaintenance) -and ($null -ne $ResticStateMaintenanceCounter)) {
|
||||||
$Script:ResticStateMaintenanceCounter += 1
|
$Script:ResticStateMaintenanceCounter += 1
|
||||||
@@ -121,14 +127,20 @@ function Invoke-Backup {
|
|||||||
$starting_location = Get-Location
|
$starting_location = Get-Location
|
||||||
ForEach ($item in $BackupSources.GetEnumerator()) {
|
ForEach ($item in $BackupSources.GetEnumerator()) {
|
||||||
|
|
||||||
# Create the Shadow Copy
|
$ShadowPath = Join-Path $item.Key 'resticVSS'
|
||||||
|
|
||||||
|
# check for existance of previous, orphaned VSS directory (and remove it) before creating the shadow copy
|
||||||
|
if(Test-Path $ShadowPath) {
|
||||||
|
Write-Output "[[Backup]] VSS directory exists: '$ShadowPath' - removing. Past script failure?" | Tee-Object -Append $ErrorLog | Tee-Object -Append $SuccessLog
|
||||||
|
cmd /c rmdir $ShadowPath
|
||||||
|
}
|
||||||
|
|
||||||
|
# Create the shadow copy
|
||||||
$s1 = (Get-WmiObject -List Win32_ShadowCopy).Create($item.Key, "ClientAccessible")
|
$s1 = (Get-WmiObject -List Win32_ShadowCopy).Create($item.Key, "ClientAccessible")
|
||||||
$s2 = Get-WmiObject -Class Win32_ShadowCopy | Where-Object { $_.ID -eq $s1.ShadowID }
|
$s2 = Get-WmiObject -Class Win32_ShadowCopy | Where-Object { $_.ID -eq $s1.ShadowID }
|
||||||
|
|
||||||
$device = $s2.DeviceObject + "\"
|
|
||||||
$ShadowPath = Join-Path $item.Key 'resticVSS'
|
|
||||||
|
|
||||||
# Create a symbolic link to the shadow copy
|
# Create a symbolic link to the shadow copy
|
||||||
|
$device = $s2.DeviceObject + "\"
|
||||||
cmd /c mklink /d $ShadowPath "$device" 3>&1 2>> $ErrorLog | Tee-Object -Append $SuccessLog
|
cmd /c mklink /d $ShadowPath "$device" 3>&1 2>> $ErrorLog | Tee-Object -Append $SuccessLog
|
||||||
|
|
||||||
# Build the new list of folders
|
# Build the new list of folders
|
||||||
@@ -192,8 +204,10 @@ function Send-Email {
|
|||||||
$attachments = @{Attachments = $ErrorLog}
|
$attachments = @{Attachments = $ErrorLog}
|
||||||
$status = "ERROR"
|
$status = "ERROR"
|
||||||
}
|
}
|
||||||
$subject = "$env:COMPUTERNAME Restic Backup Report [$status]"
|
if((($status -eq "SUCCESS") -and ($SendEmailOnSuccess -ne $false)) -or (($status -eq "ERROR") -and ($SendEmailOnError -ne $false))) {
|
||||||
Send-MailMessage @ResticEmailConfig -From $ResticEmailFrom -To $ResticEmailTo -Credential $credentials -Subject $subject -Body $body @attachments
|
$subject = "$env:COMPUTERNAME Restic Backup Report [$status]"
|
||||||
|
Send-MailMessage @ResticEmailConfig -From $ResticEmailFrom -To $ResticEmailTo -Credential $credentials -Subject $subject -Body $body @attachments
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function Invoke-ConnectivityCheck {
|
function Invoke-ConnectivityCheck {
|
||||||
@@ -294,6 +308,7 @@ function Invoke-Main {
|
|||||||
|
|
||||||
Write-Output "Something went wrong. Sleeping for 15 min and then retrying..." | Tee-Object -Append $success_log
|
Write-Output "Something went wrong. Sleeping for 15 min and then retrying..." | Tee-Object -Append $success_log
|
||||||
if($internet_available -eq $true) {
|
if($internet_available -eq $true) {
|
||||||
|
Invoke-HistoryCheck $success_log $error_log
|
||||||
Send-Email $success_log $error_log
|
Send-Email $success_log $error_log
|
||||||
}
|
}
|
||||||
Start-Sleep (15*60)
|
Start-Sleep (15*60)
|
||||||
|
|||||||
11
config.ps1
11
config.ps1
@@ -7,12 +7,19 @@ $WindowsExcludeFile = Join-Path $InstallPath "windows.exclude"
|
|||||||
$LocalExcludeFile = Join-Path $InstallPath "local.exclude"
|
$LocalExcludeFile = Join-Path $InstallPath "local.exclude"
|
||||||
$LogPath = Join-Path $InstallPath "logs"
|
$LogPath = Join-Path $InstallPath "logs"
|
||||||
$LogRetentionDays = 30
|
$LogRetentionDays = 30
|
||||||
|
$InternetTestAttempts = 10
|
||||||
|
$GlobalRetryAttempts = 4
|
||||||
|
|
||||||
|
# maintenance configuration
|
||||||
|
$SnapshotMaintenanceEnabled = $true
|
||||||
$SnapshotRetentionPolicy = @("--keep-daily", "30", "--keep-weekly", "52", "--keep-monthly", "24", "--keep-yearly", "10")
|
$SnapshotRetentionPolicy = @("--keep-daily", "30", "--keep-weekly", "52", "--keep-monthly", "24", "--keep-yearly", "10")
|
||||||
$SnapshotMaintenanceInterval = 7
|
$SnapshotMaintenanceInterval = 7
|
||||||
$SnapshotMaintenanceDays = 30
|
$SnapshotMaintenanceDays = 30
|
||||||
$SnapshotDeepMaintenanceDays = 90;
|
$SnapshotDeepMaintenanceDays = 90;
|
||||||
$InternetTestAttempts = 10
|
|
||||||
$GlobalRetryAttempts = 4
|
# email configuration
|
||||||
|
$SendEmailOnSuccess = $false
|
||||||
|
$SendEmailOnError = $true
|
||||||
|
|
||||||
# Paths to backup
|
# Paths to backup
|
||||||
$BackupSources = @{}
|
$BackupSources = @{}
|
||||||
|
|||||||
Reference in New Issue
Block a user