Compare commits

..

5 Commits

Author SHA1 Message Date
e484bc7e0a Activation features 2021-11-07 16:53:13 +01:00
61c2bdacca Added check, if folder already exists 2021-11-07 16:52:03 +01:00
d14f7aa944 first completed scripts for backup + copy2external hd 2021-11-06 14:10:21 +01:00
ec22def282 Bugfix 2021-11-06 14:03:55 +01:00
0f42fe703a Added copy-script 2021-11-06 13:56:12 +01:00
2 changed files with 78 additions and 6 deletions

75
Backup2ExternalHD.ps1 Normal file
View 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!")
}

View File

@@ -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(){