From 9f64c0224e5540db6590bf6efe9d60c1194abf2c 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 | 98 +++++++++++++------------ 1 file changed, 51 insertions(+), 47 deletions(-) diff --git a/scripts/Windows/Scripts/Restoration.ps1 b/scripts/Windows/Scripts/Restoration.ps1 index 2c16a56e..26378a4d 100644 --- a/scripts/Windows/Scripts/Restoration.ps1 +++ b/scripts/Windows/Scripts/Restoration.ps1 @@ -76,48 +76,50 @@ $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) { - $null = New-Item -ItemType Directory -Force $fullPath; - 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) { + $null = New-Item -ItemType Directory -Force $fullPath; + 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; } <# @@ -145,15 +147,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; } };