diff --git a/Backup2ExternalHD.ps1 b/Backup2ExternalHD.ps1 new file mode 100644 index 0000000..19c67e5 --- /dev/null +++ b/Backup2ExternalHD.ps1 @@ -0,0 +1,61 @@ + +$SourcePath = "E:\Backup" +$BackupPath = "G:\Backup\GigabyteWinServer" + +function Copy-Dir($Source,$Destination){ + + Write-Host("Copy Folder: $Source to Folder: $Destination") + $files = Get-ChildItem $Source -Recurse + foreach ($f in $files){ + $dest = $f.FullName.Replace($Source,$Destination) + if ($f.PSIsContainer){ + $n = New-Item -ItemType Directory -Force -Path $dest + } else { + if ($f.Length -gt 10000000){ + #Start-BitsTransfer -Source $f.FullName -Destination $dest + } else { + #Copy-Item -Path $f.FullName -Destination $dest + } + } + } +} + +function Backup-Data($SourcePath,$BackupPath){ + $sources = Get-ChildItem -Path $SourcePath + $sources = $Sources | Sort-Object -Property FullName + $BackupDrive = $BackupPath -replace(':.*','') + $move = $true + foreach($f in $sources){ + if ($f -eq $sources[$sources.Length-1]){ + Write-Host("Copying: $f") + $move = $false + } else { + Write-Host("Moving: $f") + $move = $true + } + $foldersize = (Get-ChildItem -path $f.FullName -Recurse | Measure-Object -Property Length -sum).Sum / 1Gb + $free = (Get-PSDrive -Name $BackupDrive).Free / 1Gb + Write-Host(" Backup-Data-Size: $foldersize (free: $free)") + if ($foldersize -lt $free){ + $Destination = $BackupPath+"\"+$f + Write-Host(" Target-Path: $Destination") + Copy-Dir -Source $SourcePath -Destination $Destination + if ($move){ + Remove-Item -Recurse -Force $SourcePath + } + } else { + Write-Host("ERROR: Not enough free space on Backup-Drive!") + } + } +} + +#main +if (Test-Path $BackupPath){ + if (Test-Path $SourcePath){ + Backup-Data -SourcePath $SourcePath -BackupPath $BackupPath + } else { + Write-Host("ERROR: Source Path: $SourcePath isn't available!") + } +} else { + Write-Host("ERROR: Backup Path: $BackupPath isn't available!") +} \ No newline at end of file diff --git a/WinServerVMBackup.ps1 b/WinServerVMBackup.ps1 index 84051e8..4ae9b9b 100644 --- a/WinServerVMBackup.ps1 +++ b/WinServerVMBackup.ps1 @@ -102,9 +102,6 @@ function copyDir($Source,$Destination){ } } } - - - } function copyFiles(){