Added copy-script
This commit is contained in:
61
Backup2ExternalHD.ps1
Normal file
61
Backup2ExternalHD.ps1
Normal file
@@ -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!")
|
||||
}
|
||||
@@ -102,9 +102,6 @@ function copyDir($Source,$Destination){
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
function copyFiles(){
|
||||
|
||||
Reference in New Issue
Block a user