]> git.p6c8.net - dsmonrot.git/blobdiff - dsmonrot.ps1
- Avoid trying to create the "Full" directory when creating month's
[dsmonrot.git] / dsmonrot.ps1
index 5732bd500eab9585398e0289b953f876d67ebd48..0323afbbaa4a3516de57cc696481bbf3db00b198 100644 (file)
@@ -120,7 +120,6 @@ Write-Host "Started at $startTime"
 $errorMessages = @()\r
 \r
 $smbConnected = $False\r
 $errorMessages = @()\r
 \r
 $smbConnected = $False\r
-$doBackup = $False\r
 $success = $False\r
 $isDiff = $False\r
 $dsCommand = ""\r
 $success = $False\r
 $isDiff = $False\r
 $dsCommand = ""\r
@@ -179,14 +178,13 @@ if($errorMessages.Count -eq 0) {
                        \r
                        try {\r
                                New-Item -ItemType directory -Path $backupTargetDiff -ErrorAction Stop\r
                        \r
                        try {\r
                                New-Item -ItemType directory -Path $backupTargetDiff -ErrorAction Stop\r
-                               $doBackup = $True\r
                        }\r
                        catch {\r
                                Write-Host "Could not create directory $backupTargetDiff`: $_.Exception.Message"\r
                                $errorMessages += "Could not create directory $backupTargetDiff`: $_.Exception.Message"\r
                        }\r
                        \r
                        }\r
                        catch {\r
                                Write-Host "Could not create directory $backupTargetDiff`: $_.Exception.Message"\r
                                $errorMessages += "Could not create directory $backupTargetDiff`: $_.Exception.Message"\r
                        }\r
                        \r
-                       if($doBackup) {\r
+                       if($errorMessages.Count -eq 0) {\r
                                $dsLogPath = if($dsLogFileToBackup) { "$backupTargetDiff\$dsLogFile" } else { $dsLogFile }\r
                                \r
                                $dsArgs = @($disksToBackup, "--logfile:$dsLogPath", "$backupTargetDiff\`$disk.sna", "-h$backupTargetFull\`$disk.hsh") + $dsAdditionalArgs\r
                                $dsLogPath = if($dsLogFileToBackup) { "$backupTargetDiff\$dsLogFile" } else { $dsLogFile }\r
                                \r
                                $dsArgs = @($disksToBackup, "--logfile:$dsLogPath", "$backupTargetDiff\`$disk.sna", "-h$backupTargetFull\`$disk.hsh") + $dsAdditionalArgs\r
@@ -225,46 +223,44 @@ if($errorMessages.Count -eq 0) {
                        }\r
                }\r
                \r
                        }\r
                }\r
                \r
-               if(!(Test-Path $backupTargetFull)) {\r
-                       Write-Host "Creating directory $backupTargetFull"\r
-                       \r
-                       try {\r
-                               New-Item -ItemType directory -Path $backupTargetFull -ErrorAction Stop\r
-                               $doBackup = $True\r
-                       }\r
-                       catch {\r
-                               Write-Host "Could not create directory $backupTargetFull`: $_.Exception.Message"\r
-                               $errorMessages += "Could not create directory $backupTargetFull`: $_.Exception.Message"\r
-                       }\r
-               }\r
-               else {\r
-                       $doBackup = $True\r
-               }\r
-               \r
-               if($doBackup) {\r
-                       if($rotateBeforeBackup) {\r
-                               Rotate-Backup\r
+               if($errorMessages.Count -eq 0) {\r
+                       if(!(Test-Path $backupTargetFull)) {\r
+                               Write-Host "Creating directory $backupTargetFull"\r
+                               \r
+                               try {\r
+                                       New-Item -ItemType directory -Path $backupTargetFull -ErrorAction Stop\r
+                               }\r
+                               catch {\r
+                                       Write-Host "Could not create directory $backupTargetFull`: $_.Exception.Message"\r
+                                       $errorMessages += "Could not create directory $backupTargetFull`: $_.Exception.Message"\r
+                               }\r
                        }\r
                        \r
                        }\r
                        \r
-                       $dsLogPath = if($dsLogFileToBackup) { "$backupTargetFull\$dsLogFile" } else { $dsLogFile }\r
+                       if($errorMessages.Count -eq 0) {\r
+                               if($rotateBeforeBackup) {\r
+                                       Rotate-Backup\r
+                               }\r
+                               \r
+                               $dsLogPath = if($dsLogFileToBackup) { "$backupTargetFull\$dsLogFile" } else { $dsLogFile }\r
 \r
 \r
-                       $dsArgs = @($disksToBackup, "--logfile:$dsLogPath", "$backupTargetFull\`$disk.sna") + $dsAdditionalArgs\r
-                       Write-Host $dsPath ($dsArgs -join " ")\r
-                       \r
-                       $dsCommand = "$dsPath $dsArgs"\r
-                       \r
-                       & $dsPath $dsArgs\r
-                       \r
-                       if($LastExitCode -ne 0) {\r
-                               Write-Host "Drive Snapshot failed to backup! Exit code: $LastExitCode"\r
-                               $errorMessages += "Drive Snapshot failed to backup! Exit code: $LastExitCode"\r
-                       }\r
-                       else {\r
-                               $success = $True\r
-                       }\r
-                       \r
-                       if($rotateBeforeBackup -eq $False -and $success -eq $True) {\r
-                               Rotate-Backup\r
+                               $dsArgs = @($disksToBackup, "--logfile:$dsLogPath", "$backupTargetFull\`$disk.sna") + $dsAdditionalArgs\r
+                               Write-Host $dsPath ($dsArgs -join " ")\r
+                               \r
+                               $dsCommand = "$dsPath $dsArgs"\r
+                               \r
+                               & $dsPath $dsArgs\r
+                               \r
+                               if($LastExitCode -ne 0) {\r
+                                       Write-Host "Drive Snapshot failed to backup! Exit code: $LastExitCode"\r
+                                       $errorMessages += "Drive Snapshot failed to backup! Exit code: $LastExitCode"\r
+                               }\r
+                               else {\r
+                                       $success = $True\r
+                               }\r
+                               \r
+                               if($rotateBeforeBackup -eq $False -and $success -eq $True) {\r
+                                       Rotate-Backup\r
+                               }\r
                        }\r
                }\r
        }\r
                        }\r
                }\r
        }\r
@@ -285,6 +281,7 @@ if($smbConnected) {
 if($emailOnError -and $errorMessages.Count -gt 0) {\r
        $emailBody  = "This is DSMonRot on $env:computername, started at $startTime.`n"\r
        $emailBody += "An error occured while performing a backup. Below are the error messages and some status information.`n`n"\r
 if($emailOnError -and $errorMessages.Count -gt 0) {\r
        $emailBody  = "This is DSMonRot on $env:computername, started at $startTime.`n"\r
        $emailBody += "An error occured while performing a backup. Below are the error messages and some status information.`n`n"\r
+       $emailBody += "Backup directory:       $backupDir`n"\r
        $emailBody += "Differential backup:    $isDiff`n"\r
        $emailBody += "Backup successful:      $success`n"\r
        $emailBody += "Drive Snapshot command: $dsCommand`n`n"\r
        $emailBody += "Differential backup:    $isDiff`n"\r
        $emailBody += "Backup successful:      $success`n"\r
        $emailBody += "Drive Snapshot command: $dsCommand`n`n"\r

patrick-canterino.de