Add scripts for backing up personal files
This commit is contained in:
parent
823f0dac5e
commit
d0eff6a264
7 changed files with 115 additions and 0 deletions
scripts/Windows/Scripts
18
scripts/Windows/Scripts/Context.ps1
Normal file
18
scripts/Windows/Scripts/Context.ps1
Normal file
|
@ -0,0 +1,18 @@
|
|||
class Context {
|
||||
[string]$BackupName;
|
||||
[string] BackupRoot() {
|
||||
return Join-Path $PSScriptRoot ".." ".." ".." "backup" $this.BackupName;
|
||||
}
|
||||
|
||||
[string] ArchivePath($name) {
|
||||
return Join-Path $this.BackupRoot() "$name.7z";
|
||||
}
|
||||
|
||||
[string] FileArchivePath($name) {
|
||||
return $this.ArchivePath($(Join-Path "Files" $name));
|
||||
}
|
||||
|
||||
[string] SoftwareArchive([string]$softwareName) {
|
||||
return $this.ArchivePath($softwareName);
|
||||
}
|
||||
}
|
34
scripts/Windows/Scripts/PersonalFiles.ps1
Normal file
34
scripts/Windows/Scripts/PersonalFiles.ps1
Normal file
|
@ -0,0 +1,34 @@
|
|||
Import-Module "$PSScriptRoot/../../scripts/Common/Scripts/Context.ps1" -Force;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
function Invoke-FileBackup([Context] $context) {
|
||||
foreach ($candidate in Get-BackupCandidates) {
|
||||
$archiveName = $context.FileArchivePath($candidate[0]);
|
||||
|
||||
if (Test-Path $archiveName) {
|
||||
Remove-Item -Recurse $archiveName;
|
||||
}
|
||||
|
||||
Start-Process -WorkingDirectory $candidate[1] `
|
||||
-ArgumentList (
|
||||
@(
|
||||
"a",
|
||||
"-xr!desktop.ini",
|
||||
"-xr!{t,T}humbs.db") +
|
||||
$candidate[2] +
|
||||
@($archiveName)) `
|
||||
-FilePath "7z" `
|
||||
-NoNewWindow `
|
||||
-Wait;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue