pcanterino / dsmonrot Goto Github PK
View Code? Open in Web Editor NEWScript for rotating Drive Snapshot backups monthly
License: BSD 2-Clause "Simplified" License
Script for rotating Drive Snapshot backups monthly
License: BSD 2-Clause "Simplified" License
If the full backup is corrupt, DSMonRot / Drive Snapshot is not able to do anything until the next full backup. It behaves as expected, because Drive Snapshot is not able to create a differential backup from a corrupted full backup.
We are able to detect this, because Drive Snapshot throws error code 21 if the hash file of the full backup is corrupted. So we could do a new full backup if Drive Snapshot exits with that error code.
I created a patch for the user who reported this issue. This patch is a quick and dirty solution and I don't really like it. It adds a new configuration variable $renameCorruptFullBackups
. If this variable is set, DSMonRot checks for error code 21, renames the directory of the corrupted full backup and does a new one.
The problem with my solution is that I created some redundant code. To fix this I would have to rewrite some parts of the code (create subroutines) - and I currently don't have the time to do that.
I created this issue so that the problem and a possible solution is written down.
So, if you face this problem and can accept a quick and dirty solution, you can apply this patch file to dsmonrot.ps1:
--- dsmonrot.ps1 Fri Mar 9 14:16:09 2018
+++ dsmonrot_new.ps1 Tue Aug 27 19:08:37 2019
@@ -28,6 +28,8 @@
[Boolean]$rotateBeforeBackup = $False
# Set to $True if you want to allow multiple backups for a day
[Boolean]$multipleDailyBackups = $False
+# Set to $True if you want to rename corrupted full backups (experimental)
+[Boolean]$renameCorruptFullBackups = $False
# Path to Drive Snapshot log file (specify only the file name if you set
# $dsLogFileToBackup to $True)
#[String]$dsLogFile = "C:\Users\Patrick\Desktop\DSMonRot\snapshot.log"
@@ -355,6 +357,46 @@
& $dsPath $dsArgs
+ if($renameCorruptFullBackups -and $LastExitCode -eq 21) {
+ Write-Log "Drive Snapshot failed with exit code $LastExitCode because of problems with the hash file of the full backup!" -Path $logFile -Level Warn
+ Write-Log "Renaming corrupted full backup and retrying..." -Path $logFile
+
+ Rename-Item $backupTargetFull ("$backupTargetFull-corrupt-" + (Get-Item $backupTargetFull).LastWriteTime.toString("yyyy-MM-dd-HH-mm-ss"))
+
+ Write-Log "Removing directory for failed differential backup" -Path $logFile
+
+ Remove-Item -Recurse -Force $backupTargetDiff
+
+ Write-Log "Doing a full backup" -Path $logFile
+
+ if(!(Test-Path $backupTargetFull)) {
+ try {
+ New-Item -ItemType directory -Path $backupTargetFull -ErrorAction Stop | Out-Null
+ }
+ catch {
+ Write-Log "Could not create directory $backupTargetFull`: $_.Exception.Message" -Path $logFile -Level Error
+ $errorMessages += "Could not create directory $backupTargetFull`: $_.Exception.Message"
+ }
+ }
+
+ $dsLogPath = if($dsLogFileToBackup) { "$backupTargetFull\$dsLogFile" } else { $dsLogFile }
+
+ $dsArgs = @($disksToBackup, "--logfile:$dsLogPath", "$backupTargetFull\`$disk.sna") + $dsAdditionalArgs
+ $dsCommand = "$dsPath $dsArgs"
+
+ Write-Log $dsCommand -Path $logFile
+
+ & $dsPath $dsArgs
+
+ if($LastExitCode -ne 0) {
+ Write-Log "Drive Snapshot failed to backup! Exit code: $LastExitCode" -Path $logFile -Level Error
+ $errorMessages += "Drive Snapshot failed to backup! Exit code: $LastExitCode"
+ }
+ else {
+ Write-Log "Drive Snapshot succeeded!" -Path $logFile
+ $success = $True
+ }
+ }
if($LastExitCode -ne 0) {
Write-Log "Drive Snapshot failed to backup! Exit code: $LastExitCode" -Path $logFile -Level Error
$errorMessages += "Drive Snapshot failed to backup! Exit code: $LastExitCode"
Feature request by Mike:
Make use of Drive Snapshot's --exclude
command line parameter. It allows to exclude files and directories from the snapshot.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.