Added check, if folder already exists
This commit is contained in:
@@ -39,11 +39,23 @@ function Backup-Data($SourcePath,$BackupPath){
|
||||
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
|
||||
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!")
|
||||
|
||||
Reference in New Issue
Block a user