diff --git a/Backup2ExternalHD.ps1 b/Backup2ExternalHD.ps1 index 03c8466..a6c5c60 100644 --- a/Backup2ExternalHD.ps1 +++ b/Backup2ExternalHD.ps1 @@ -38,12 +38,24 @@ function Backup-Data($SourcePath,$BackupPath){ $free = (Get-PSDrive -Name $BackupDrive).Free / 1Gb Write-Host(" Backup-Data-Size: $foldersize (free: $free)") if ($foldersize -lt $free){ - $Destination = $BackupPath+"\"+$f - Write-Host(" Source-Path: $Source") - Write-Host(" Target-Path: $Destination") - Copy-Dir -Source $Source -Destination $Destination + $Destination = $BackupPath+"\"+$f + if (Test-Path -Path $Destination){ + Write-Host(" Target folder exists...checking size") + $copysize = (Get-ChildItem -path $Destination -Recurse | Measure-Object -Property Length -sum).Sum / 1Gb + } else { + $copysize = 0 + } + if ($foldersize -ne $copysize){ + Write-Host(" Source-Path: $Source") + Write-Host(" Target-Path: $Destination") + #Copy-Dir -Source $Source -Destination $Destination + } else { + Write-Host(" Skipping $Source, as it is already available on destination with identical size.") + } + if ($move){ - Remove-Item -Recurse -Force $Source + Write-Host(" Finally cleaning up after move") + #Remove-Item -Recurse -Force $Source } } else { Write-Host("ERROR: Not enough free space on Backup-Drive!")