Compare commits
5 Commits
3a154ee846
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| e484bc7e0a | |||
| 61c2bdacca | |||
| d14f7aa944 | |||
| ec22def282 | |||
| 0f42fe703a |
75
Backup2ExternalHD.ps1
Normal file
75
Backup2ExternalHD.ps1
Normal file
@@ -0,0 +1,75 @@
|
||||
|
||||
$SourcePath = "E:\Backup"
|
||||
$BackupPath = "G:\Backup\GigabyteWinServer"
|
||||
|
||||
function Copy-Dir($Source,$Destination){
|
||||
$n = New-Item -ItemType Directory -Force -Path $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){
|
||||
$Source = $f.FullName
|
||||
if ($f -eq $sources[$sources.Length-1]){
|
||||
Write-Host("Copying: $f")
|
||||
$move = $false
|
||||
} else {
|
||||
Write-Host("Moving: $f")
|
||||
$move = $true
|
||||
}
|
||||
$foldersize = (Get-ChildItem -path $Source -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
|
||||
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){
|
||||
Write-Host(" Finally cleaning up after move")
|
||||
Remove-Item -Recurse -Force $Source
|
||||
}
|
||||
} 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!")
|
||||
}
|
||||
@@ -87,7 +87,7 @@ function startDocker(){
|
||||
}
|
||||
|
||||
function copyDir($Source,$Destination){
|
||||
|
||||
$n = New-Item -ItemType Directory -Force -Path $Destination
|
||||
Write-Host("Copy Folder: $Source to Folder: $Destination")
|
||||
$files = Get-ChildItem $Source -Recurse
|
||||
foreach ($f in $files){
|
||||
@@ -96,15 +96,12 @@ function copyDir($Source,$Destination){
|
||||
$n = New-Item -ItemType Directory -Force -Path $dest
|
||||
} else {
|
||||
if ($f.Length -gt 10000000){
|
||||
#Start-BitsTransfer -Source $f.FullName -Destination $dest
|
||||
Start-BitsTransfer -Source $f.FullName -Destination $dest
|
||||
} else {
|
||||
#Copy-Item -Path $f.FullName -Destination $dest
|
||||
Copy-Item -Path $f.FullName -Destination $dest
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
function copyFiles(){
|
||||
|
||||
Reference in New Issue
Block a user