]> git.p6c8.net - dsmonrot.git/commitdiff
- Avoid trying to create the "Full" directory when creating month's
authorPatrick Canterino <patrick@patrick-canterino.de>
Tue, 6 Mar 2018 13:19:47 +0000 (14:19 +0100)
committerPatrick Canterino <patrick@patrick-canterino.de>
Tue, 6 Mar 2018 13:21:00 +0000 (14:21 +0100)
  directory failed
- Got rid of $doBackup variable, instead check if there are any error
  messages recorded

TODO.md
dsmonrot.ps1

diff --git a/TODO.md b/TODO.md
index b727f891ccd4f8d5c95df85d5805f190f1050b25..84b50f28c799ad7d07f02483d7b3a641728eca3c 100644 (file)
--- a/TODO.md
+++ b/TODO.md
@@ -2,7 +2,7 @@
 
 - [x] Collect error messages and send them via email
 - [x] Check if directories are created successfully
-- [x] ~~Check if the network drive already exists before connecting~~ `New-PSDrive` throws an exception if drive is already connected
+- [x] ~~Check if the network drive already exists before connecting~~ ⇒ `New-PSDrive` throws an exception if drive is already connected
 - [ ] Create a log file for the script
 - [ ] Clean up the messages sent to the console or send them to the debug or error streams (e.g. `Write-Debug` or `Write-Error`)
 - [ ] Suppress output of some commands
\ No newline at end of file
index 5732bd500eab9585398e0289b953f876d67ebd48..0323afbbaa4a3516de57cc696481bbf3db00b198 100644 (file)
@@ -120,7 +120,6 @@ Write-Host "Started at $startTime"
 $errorMessages = @()\r
 \r
 $smbConnected = $False\r
-$doBackup = $False\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
-                               $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
-                       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
@@ -225,46 +223,44 @@ if($errorMessages.Count -eq 0) {
                        }\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
-                       $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
-                       $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
@@ -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
+       $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

patrick-canterino.de