]> git.p6c8.net - dsmonrot.git/blobdiff - dsmonrot.ps1
Fixed Markdown
[dsmonrot.git] / dsmonrot.ps1
index bb56cdff951fe219eb9a1e1d4e6c37d533f3e23f..353e0dbaae7cd1321f12961481a4d3bda0d0253d 100644 (file)
@@ -3,7 +3,7 @@
 #\r
 # Author: Patrick Canterino <patrick@patrick-canterino.de>\r
 # WWW: https://www.patrick-canterino.de/\r
-#      https://github.com/pcanterino/dsmonrot/\r
+#      https://github.com/pcanterino/dsmonrot\r
 # License: 2-Clause BSD License\r
 #\r
 # Drive Snapshot is copyright by Tom Ehlert\r
 \r
 # Path to backup directory\r
 [String]$backupDir = "Z:\"\r
-# Keep backup for this amount of months (excluding the current month), -1 for indefinite\r
+# Keep backup for this amount of months (excluding the current month),\r
+# -1 for indefinite\r
 [Int32]$keepMonths = 2\r
 # Path to Drive Snapshot\r
 [String]$dsPath = "C:\Users\Patrick\Desktop\DSMonRot\snapshot.exe"\r
-# Path to Drive Snapshot log file\r
-[String]$dsLogFile = "C:\Users\Patrick\Desktop\DSMonRot\snapshot.log"\r
+# Path to Drive Snapshot log file (specify only the file name if you set\r
+# $dsLogFileToBackup to $True)\r
+#[String]$dsLogFile = "C:\Users\Patrick\Desktop\DSMonRot\snapshot.log"\r
+[String]$dsLogFile = "snapshot.log"\r
+# Set to $True if you want to put the log file of Drive Snapshot into the same\r
+# directory as the backup\r
+[Boolean]$dsLogFileToBackup = $True\r
 # Disks to backup, see http://www.drivesnapshot.de/en/commandline.htm\r
 [String]$disksToBackup = "HD1:1"\r
 # Path to DSMonRot log file\r
@@ -56,7 +62,7 @@
 \r
 # End of config\r
 \r
-$dsAdditionalArgs = @("--logfile:$dsLogFile", "--UseVSS")\r
+$dsAdditionalArgs = @("--UseVSS")\r
 \r
 # Allow SMTP with SSL and SMTP Auth\r
 # see: http://petermorrissey.blogspot.de/2013/01/sending-smtp-emails-with-powershell.html\r
@@ -95,13 +101,11 @@ if($smbDrive) {
                        $smbCredential = New-Object System.Management.Automation.PSCredential($smbUser, $secSmbPassword)\r
 \r
                        New-PSDrive -Name $smbDrive -PSProvider "FileSystem" -Root $smbPath -Credential $smbCredential -Persist -ErrorAction Stop\r
-                       #net use "$smbDrive`:" $smbPath $smbPassword /user:$smbUser\r
                }\r
                else {\r
                        Write-Host "Without credentials"\r
                \r
                        New-PSDrive -Name $smbDrive -PSProvider "FileSystem" -Root $smbPath -Persist -ErrorAction Stop\r
-                       #net use "$smbDrive`:" $smbPath\r
                }\r
                \r
                $smbConnected = $True\r
@@ -149,7 +153,9 @@ if((Test-Path $backupTarget) -and (Test-Path $backupTargetFull) -and (Test-Path
                        exit\r
                }\r
                \r
-               $dsArgs = @($disksToBackup, "$backupTargetFull\`$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
                Write-Host $dsPath ($dsArgs -join " ")\r
                \r
                & $dsPath $dsArgs\r
@@ -176,8 +182,10 @@ else {
                Write-Host "Creating directory $backupTargetFull"\r
                New-Item -ItemType directory -Path $backupTargetFull\r
        }\r
+       \r
+       $dsLogPath = if($dsLogFileToBackup) { "$backupTargetFull\$dsLogFile" } else { $dsLogFile }\r
 \r
-       $dsArgs = @($disksToBackup, "$backupTargetFull\`$disk.sna") + $dsAdditionalArgs\r
+       $dsArgs = @($disksToBackup, "--logfile:$dsLogPath", "$backupTargetFull\`$disk.sna") + $dsAdditionalArgs\r
        Write-Host $dsPath ($dsArgs -join " ")\r
        \r
        & $dsPath $dsArgs\r
@@ -214,7 +222,6 @@ if($isDiff -eq $False -and $success -eq $True -and $keepMonths -ge 0) {
 if($smbConnected) {\r
        Write-Host "Disconnecting network drive"\r
        Remove-PSDrive $smbDrive\r
-       #net use "$smbDrive`:" /delete\r
 }\r
 \r
 if($emailOnError -and $errorMessages.Count -gt 0) {\r

patrick-canterino.de