Added check, if folder already exists

This commit is contained in:
2021-11-07 16:52:03 +01:00
parent d14f7aa944
commit 61c2bdacca

View File

@@ -39,11 +39,23 @@ function Backup-Data($SourcePath,$BackupPath){
Write-Host(" Backup-Data-Size: $foldersize (free: $free)")
if ($foldersize -lt $free){
$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
#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!")