From 1c3a2fe2e730996ea6cea11833022356533c858b Mon Sep 17 00:00:00 2001 From: Manuel Thalmann Date: Wed, 28 Aug 2024 00:22:38 +0200 Subject: [PATCH] Ignore unspecified backup archives --- scripts/Windows/Scripts/Restoration.ps1 | 96 +++++++++++++------------ 1 file changed, 50 insertions(+), 46 deletions(-) diff --git a/scripts/Windows/Scripts/Restoration.ps1 b/scripts/Windows/Scripts/Restoration.ps1 index 2e6c60a6..b30d5b3b 100644 --- a/scripts/Windows/Scripts/Restoration.ps1 +++ b/scripts/Windows/Scripts/Restoration.ps1 @@ -76,47 +76,49 @@ $null = New-Module { [string[]] $Exclude ) - [List[string]] $argumentList = @(); - $dir = New-TemporaryDirectory; - $targetPath = & $pathResolver @PSBoundParameters; - $fullPath = Join-Path $dir $targetPath; - $null = New-Item -ItemType Directory -Force (Split-Path -Parent $fullPath); + if ($env:BACKUP_ARCHIVE) { + [List[string]] $argumentList = @(); + $dir = New-TemporaryDirectory; + $targetPath = & $pathResolver @PSBoundParameters; + $fullPath = Join-Path $dir $targetPath; + $null = New-Item -ItemType Directory -Force (Split-Path -Parent $fullPath); - if (Test-Path -PathType Container $Source) { - $null = New-Item -ItemType Junction $fullPath -Target $Source; - } elseif (Test-Path -PathType Leaf $Source) { - Copy-Item $Source $fullPath; - } - - $options = @( - @("i", $Include), - @("x", $Exclude) - ); - - foreach ($option in $options) { - $indicator = $option[0]; - $list = $option[1]; - - foreach ($pattern in $list) { - $argumentList.Add("-$indicator!`"$(Join-Path $targetPath $pattern)`""); + if (Test-Path -PathType Container $Source) { + $null = New-Item -ItemType Junction $fullPath -Target $Source; + } elseif (Test-Path -PathType Leaf $Source) { + Copy-Item $Source $fullPath; } + + $options = @( + @("i", $Include), + @("x", $Exclude) + ); + + foreach ($option in $options) { + $indicator = $option[0]; + $list = $option[1]; + + foreach ($pattern in $list) { + $argumentList.Add("-$indicator!`"$(Join-Path $targetPath $pattern)`""); + } + } + + Start-Process ` + -NoNewWindow ` + -Wait ` + -WorkingDirectory $dir ` + -FilePath 7z ` + -ArgumentList ( + @( + "a", + (Get-ValhallaBackupArchive), + "-xr!desktop.ini", + "-xr!thumbs.db", + "-xr!Thumbs.db" + ) + $argumentList); + + Remove-Item -Recurse -Force $dir; } - - Start-Process ` - -NoNewWindow ` - -Wait ` - -WorkingDirectory $dir ` - -FilePath 7z ` - -ArgumentList ( - @( - "a", - (Get-ValhallaBackupArchive), - "-xr!desktop.ini", - "-xr!thumbs.db", - "-xr!Thumbs.db" - ) + $argumentList); - - Remove-Item -Recurse -Force $dir; } <# @@ -144,15 +146,17 @@ $null = New-Module { [string[]] $ArgumentList ) - $dir = New-TemporaryDirectory; - $sourcePath = & $pathResolver @PSBoundParameters; - $filePath = Join-Path $dir $sourcePath; - 7z x "-o$dir" (Get-ValhallaBackupArchive) $sourcePath @ArgumentList; + if ($env:BACKUP_ARCHIVE) { + $dir = New-TemporaryDirectory; + $sourcePath = & $pathResolver @PSBoundParameters; + $filePath = Join-Path $dir $sourcePath; + 7z x "-o$dir" (Get-ValhallaBackupArchive) $sourcePath @ArgumentList; - if (Test-Path $filePath) { - Copy-Item -Recurse (Join-Path $dir $sourcePath) $Target; + if (Test-Path $filePath) { + Copy-Item -Recurse (Join-Path $dir $sourcePath) $Target; + } + + Remove-Item -Recurse -Force $dir; } - - Remove-Item -Recurse -Force $dir; } };