Giter Club home page Giter Club logo

dsmonrot's People

Contributors

pcanterino avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

dsmonrot's Issues

Do a new full backup if the existing one is corrupted (quick and dirty patch included)

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"

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.