PortValhalla/scripts/Windows/Scripts/PersonalFiles.ps1

34 lines
1.2 KiB
PowerShell
Raw Normal View History

2023-07-12 20:37:31 +00:00
#!/bin/pwsh
2023-06-07 20:56:41 +00:00
. "$PSScriptRoot/Context.ps1";
function Get-BackupCandidates() {
[System.Collections.Generic.List[System.Tuple[string, string, string[]]]]$candidates = @();
$candidates.AddRange(
[System.Tuple[string, string, string[]][]]@(
[System.Tuple]::Create("Home", "$HOME", @("-i@`"$PSScriptRoot/FileLists/Home.include.txt`"", "-x@`"$PSScriptRoot/FileLists/Home.exclude.txt`"")),
[System.Tuple]::Create("Public", "$env:PUBLIC", @("-i@`"$PSScriptRoot/FileLists/Public.include.txt`"", "-x@`"$PSScriptRoot/FileLists/Public.exclude.txt`""))));
return $candidates;
}
2023-06-30 10:19:54 +00:00
function Backup-PersonalFiles([Context] $context) {
2023-06-22 17:02:02 +00:00
Write-Host "Backing up Personal Files";
foreach ($candidate in Get-BackupCandidates) {
$context.Backup($candidate[1], $context.FileArchivePath($candidate[0]), $candidate[2]);
}
}
2023-06-22 16:44:31 +00:00
2023-06-30 10:19:54 +00:00
function Restore-PersonalFiles([Context] $context) {
2023-06-22 17:02:02 +00:00
Write-Host "Restoring Personal Files";
2023-06-22 16:44:31 +00:00
foreach ($candidate in Get-BackupCandidates) {
$archivePath = $context.FileArchivePath($candidate[0]);
if (Test-Path -PathType Leaf $archivePath) {
$context.Restore($archivePath, $candidate[1]);
}
}
}