From c3a4268be7412d12db47011436f327696f97eed0 Mon Sep 17 00:00:00 2001 From: Anne W <41674213+AnneWielis@users.noreply.github.com> Date: Fri, 20 Oct 2023 14:48:08 +0200 Subject: [PATCH] Bugfix for File Selection, Added Support for Windows zipping --- BackupScript_v2.ps1 | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/BackupScript_v2.ps1 b/BackupScript_v2.ps1 index 5c44bd5..42a43f1 100644 --- a/BackupScript_v2.ps1 +++ b/BackupScript_v2.ps1 @@ -182,15 +182,16 @@ if ($PreCheck) { foreach ($Backup in $FinalBackupdirs) { - $Files = Get-ChildItem -LiteralPath $Backup -recurse -Attributes D+!ReparsePoint, D+H+!ReparsePoint -ErrorVariable +errItems -ErrorAction SilentlyContinue | + $Files1 = Get-ChildItem -LiteralPath $Backup -recurse -Attributes D+!ReparsePoint, D+H+!ReparsePoint -ErrorVariable +errItems -ErrorAction SilentlyContinue | ForEach-Object -Process { Add-Member -InputObject $_ -NotePropertyName "ParentFullName" -NotePropertyValue ($_.FullName.Substring(0, $_.FullName.LastIndexOf("\" + $_.Name))) -PassThru -ErrorAction SilentlyContinue } | Where-Object { $_.FullName -notmatch $exclude -and $_.ParentFullName -notmatch $exclude } | Get-ChildItem -Attributes !D -ErrorVariable +errItems -ErrorAction SilentlyContinue | Where-Object { $_.DirectoryName -notmatch $exclude } #$BackupDirFiles.Add($Backup, $Files) - $Files+= Get-ChildItem -LiteralPath $Backup | + $Files2= Get-ChildItem -LiteralPath $Backup | ForEach-Object -Process { Add-Member -InputObject $_ -NotePropertyName "ParentFullName" -NotePropertyValue ($_.FullName.Substring(0, $_.FullName.LastIndexOf("\" + $_.Name))) -PassThru -ErrorAction SilentlyContinue } | Get-ChildItem -Attributes !D -ErrorVariable +errItems -ErrorAction SilentlyContinue + $Files = $files1 + $Files2 $BackupDirFiles.Add($Backup, $Files) @@ -272,6 +273,18 @@ if ($BackUpCheck) { if ($ZIP) { Write-au2matorLog -Type INFO -Text "ZIP is on, so lets go" + if (!(Test-Path -Path $StagingPath)) { + try { + $null = New-Item -Path $StagingPath -ItemType Directory + Write-Verbose ("Path: ""{0}"" was created." -f$StagingPath) + } + catch { + Write-Verbose ("Path: ""{0}"" couldn't be created." -f $StagingPath) + } + } + else { + Write-Verbose ("Path: ""{0}"" already exists." -f $StagingPath) + } if ($Use7ZIP) { Write-au2matorLog -Type INFO -Text "We should use 7Zip for this" @@ -305,7 +318,12 @@ if ($BackUpCheck) { } } else { - + Write-au2matorLog -Type Info -Text "Compress File" + $Zip = $StagingPath + ("\" + $BackupDestination.Replace($Destination, '').Replace('\', '') + ".zip") + Compress-Archive -Path $BackupDestination -DestinationPath $Zip + Write-au2matorLog -Type Info -Text "Move Zip to Destination" + Move-Item -Path $Zip -Destination $Destination + $ZIPCheck = $true } } else { @@ -365,4 +383,4 @@ if ($CountZip -gt $Versions) { $Zip.FullName | Remove-Item -Recurse -Force -} \ No newline at end of file +}