@jamiefutch/pi-backup 1.1.9 → 1.1.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +29 -8
- package/backup-pi.ps1 +25 -13
- package/backup-pi.sh +1 -1
- package/extensions/pi-backup-manager.ts +48 -21
- package/package.json +1 -1
- package/restore-pi.ps1 +20 -5
- package/restore-pi.sh +6 -12
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# pi-backup — Pi Backup & Restore Utilities
|
|
2
2
|
|
|
3
|
-
Complete backup/restore for Pi coding agent. Backs up **everything** needed to restore to
|
|
3
|
+
Complete, cross-platform backup/restore for the Pi coding agent. Backs up **everything** needed to restore to an equivalent state after a clean reinstall, with an interactive `/pi-backup` manager and 7-Zip-first archive support.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -27,6 +27,13 @@ pi install /path/to/pi-backup
|
|
|
27
27
|
|
|
28
28
|
Then restart Pi or run `/reload`.
|
|
29
29
|
|
|
30
|
+
### Developer documentation
|
|
31
|
+
|
|
32
|
+
Repository-specific agent guidance is available in:
|
|
33
|
+
|
|
34
|
+
- `.pi/agents.md` — pi-backup project conventions and safety rules
|
|
35
|
+
- `.pi/agents/pi-development-expert.md` — detailed Pi extension, package, SDK, TUI, provider, and resource-development guidance
|
|
36
|
+
|
|
30
37
|
---
|
|
31
38
|
|
|
32
39
|
## Scripts
|
|
@@ -44,6 +51,18 @@ Then restart Pi or run `/reload`.
|
|
|
44
51
|
|
|
45
52
|
---
|
|
46
53
|
|
|
54
|
+
## Archive format and compression
|
|
55
|
+
|
|
56
|
+
External backups are compressed automatically:
|
|
57
|
+
|
|
58
|
+
- If `7zz`, `7z`, or `7za` is available on **macOS, Linux, or Windows**, Pi Backup uses 7-Zip and creates a `.7z` archive.
|
|
59
|
+
- Otherwise it falls back to native platform tools and creates a `.zip` archive (`zip`/`unzip` on macOS/Linux, `Compress-Archive`/`Expand-Archive` on Windows).
|
|
60
|
+
- Restoring a `.7z` archive requires 7-Zip to be installed and available on `PATH`.
|
|
61
|
+
- The TUI uses the same preference for creating, restoring, copying, and viewing manifests.
|
|
62
|
+
- Internal backups remain uncompressed directories for fast rollback.
|
|
63
|
+
|
|
64
|
+
The executable may be named `7zz`, `7z`, or `7za`.
|
|
65
|
+
|
|
47
66
|
## Usage
|
|
48
67
|
|
|
49
68
|
### TUI Extension (after package install)
|
|
@@ -83,7 +102,7 @@ External dir: ~/projects/personal/pi-utils/backups
|
|
|
83
102
|
Backups (8 total)
|
|
84
103
|
|
|
85
104
|
→ 📁 pi-backup-20260812-112053 │ 2026-08-12 11:20:53 │ 1.6 MB │ 347 files
|
|
86
|
-
💾 pi-backup-20260812-112019.
|
|
105
|
+
💾 pi-backup-20260812-112019.7z │ 2026-08-12 11:20:19 │ 1.6 MB │ 1 files • compressed
|
|
87
106
|
💾 pi-backup-20260812-095402.zip │ 2026-08-12 09:54:02 │ 1.6 MB │ 1 files • compressed
|
|
88
107
|
...
|
|
89
108
|
🔄 Refresh
|
|
@@ -95,7 +114,7 @@ Columns: **Location icon** • **Name** • **Timestamp** • **Size** • **Fil
|
|
|
95
114
|
#### Backup Actions (after selecting a backup)
|
|
96
115
|
|
|
97
116
|
```
|
|
98
|
-
Backup: pi-backup-20260812-112019.
|
|
117
|
+
Backup: pi-backup-20260812-112019.7z
|
|
99
118
|
|
|
100
119
|
→ 🔄 Restore this backup (2026-08-12 11:20:19)
|
|
101
120
|
📋 Copy to internal (~/.pi/backups/)
|
|
@@ -106,7 +125,7 @@ Backup: pi-backup-20260812-112019.zip
|
|
|
106
125
|
|
|
107
126
|
| Action | Description |
|
|
108
127
|
|--------|-------------|
|
|
109
|
-
| **🔄 Restore** | Runs
|
|
128
|
+
| **🔄 Restore** | Runs the platform restore script — overwrites all Pi config (requires confirmation) |
|
|
110
129
|
| **📋 Copy to internal** | Copies external backup to `~/.pi/backups/` for quick access (external only) |
|
|
111
130
|
| **📄 View manifest** | Opens `MANIFEST.txt` in editor (extracts from compressed archives) |
|
|
112
131
|
| **🗑️ Delete** | Permanently removes backup (requires confirmation) |
|
|
@@ -132,9 +151,9 @@ Backup: pi-backup-20260812-112019.zip
|
|
|
132
151
|
~/projects/personal/pi-backup/pi-clean-reinstall.sh
|
|
133
152
|
```
|
|
134
153
|
|
|
135
|
-
#### 3. Restore
|
|
154
|
+
#### 3. Restore a directory, `.7z` archive, or `.zip` archive
|
|
136
155
|
```bash
|
|
137
|
-
~/projects/personal/pi-backup/restore-pi.sh ~/projects/personal/pi-utils/backups/pi-backup-20260811-143000
|
|
156
|
+
~/projects/personal/pi-backup/restore-pi.sh ~/projects/personal/pi-utils/backups/pi-backup-20260811-143000.7z
|
|
138
157
|
```
|
|
139
158
|
|
|
140
159
|
#### 4. Reinstall npm deps + verify
|
|
@@ -172,13 +191,13 @@ Customize locations in PowerShell with environment variables (same names as the
|
|
|
172
191
|
$env:PI_ROOT='C:\Users\you\.pi'; $env:BACKUP_ROOT='D:\pi-backups'; .\backup-pi.ps1
|
|
173
192
|
```
|
|
174
193
|
|
|
175
|
-
> **Note**: If the Execution Policy blocks scripts, run once: `Set-ExecutionPolicy -Scope CurrentUser RemoteSigned`.
|
|
194
|
+
> **Note**: If the Execution Policy blocks scripts, run once: `Set-ExecutionPolicy -Scope CurrentUser RemoteSigned`. With 7-Zip (`7zz`, `7z`, or `7za`) on `PATH`, backups are created as `.7z`; otherwise PowerShell's built-in `Compress-Archive` creates `.zip` files. `restore-pi.ps1` prefers 7-Zip when available and uses `Expand-Archive` for ZIP fallback.
|
|
176
195
|
|
|
177
196
|
## What Gets Backed Up
|
|
178
197
|
|
|
179
198
|
| Category | Paths |
|
|
180
199
|
|----------|-------|
|
|
181
|
-
| **Core config** | `settings.json`, `auth.json`, `models.json`, `trust.json`, `keybindings.json`, `pix.json`, `optimizer.json`, `hermes-memory-config.json` |
|
|
200
|
+
| **Core config** | `settings.json`, `auth.json`, `models.json`, `trust.json`, `keybindings.json`, `pix.json`, `optimizer.json`, `lmstudio.json.bak`, `hermes-memory-config.json`, `pi.code-workspace` |
|
|
182
201
|
| **Extension configs** | `pi-hermes-memory-cleanup/scoped-memory.json`, `loop-police.json`, `pi-rtk/config.json`, `context-mode/config.json`, `pi-timeout/config.json`, `pi-context-viewer/config.json`, `pix-optimizer/config.json`, `pi-nvidia-nim/config.json` |
|
|
183
202
|
| **Global skills** | `~/.pi/agent/skills/` |
|
|
184
203
|
| **Project skills & memory** | `~/.pi/agent/projects-memory/<project>/` |
|
|
@@ -274,6 +293,8 @@ If the default directory already contains backups, it is treated as configured a
|
|
|
274
293
|
|----------|---------|---------|
|
|
275
294
|
| `PI_ROOT` | `~/.pi` | Override Pi root directory |
|
|
276
295
|
| `BACKUP_ROOT` | `~/projects/personal/pi-utils/backups` | Override backup destination (highest priority for the TUI too) |
|
|
296
|
+
| `KEEP_UNCOMPRESSED` | `0` | Keep the uncompressed staging directory after external backup; the TUI sets this automatically for internal backups |
|
|
297
|
+
| `PKG_MANAGER` | `bun` | Package manager used by the clean-reinstall scripts (`bun`, `npm`, etc.) |
|
|
277
298
|
|
|
278
299
|
```bash
|
|
279
300
|
# Custom locations
|
package/backup-pi.ps1
CHANGED
|
@@ -20,6 +20,8 @@ $Timestamp = Get-Date -Format 'yyyyMMdd-HHmmss'
|
|
|
20
20
|
$ArchiveBase = "pi-backup-$Timestamp"
|
|
21
21
|
$ArchiveDir = Join-Path $BackupRoot $ArchiveBase
|
|
22
22
|
$KeepUncompressed = $env:KEEP_UNCOMPRESSED -eq '1'
|
|
23
|
+
$SevenZip = @('7zz', '7z', '7za') | ForEach-Object { Get-Command $_ -ErrorAction SilentlyContinue } | Select-Object -First 1
|
|
24
|
+
$ArchiveExtension = if ($SevenZip) { '7z' } else { 'zip' }
|
|
23
25
|
|
|
24
26
|
function Log { Write-Host "[INFO] $args" -ForegroundColor Cyan }
|
|
25
27
|
function OK { Write-Host "[OK] $args" -ForegroundColor Green }
|
|
@@ -58,13 +60,13 @@ function Copy-Tree([string]$src, [string]$dst, [string[]]$excludeDirs = @(), [st
|
|
|
58
60
|
& robocopy @robocopyArgs | Out-Null
|
|
59
61
|
} else {
|
|
60
62
|
# Fallback: manual recursive copy with exclusions
|
|
61
|
-
$dirs = if ($excludeDirs.Count) { @{ } } else { @{ } }
|
|
62
63
|
Get-ChildItem -LiteralPath $src | ForEach-Object {
|
|
64
|
+
$item = $_
|
|
63
65
|
$skip = $false
|
|
64
|
-
if ($
|
|
65
|
-
if (-not $
|
|
66
|
+
if ($item.PSIsContainer -and $item.Name -in $excludeDirs) { $skip = $true }
|
|
67
|
+
if (-not $item.PSIsContainer -and ($excludeFiles | Where-Object { $item.Name -like $_ })) { $skip = $true }
|
|
66
68
|
if (-not $skip) {
|
|
67
|
-
Copy-Item -LiteralPath $
|
|
69
|
+
Copy-Item -LiteralPath $item.FullName -Destination (Join-Path $dst $item.Name) -Recurse -Force
|
|
68
70
|
}
|
|
69
71
|
}
|
|
70
72
|
}
|
|
@@ -200,15 +202,25 @@ $manifest += ($relFiles -join "`n") + "`n"
|
|
|
200
202
|
Set-Content -LiteralPath (Join-Path $ArchiveDir 'MANIFEST.txt') -Value $manifest -Encoding UTF8
|
|
201
203
|
|
|
202
204
|
# ── 9. Compress ───────────────────────────────────────────
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
205
|
+
$archivePath = $null
|
|
206
|
+
if ($KeepUncompressed) {
|
|
207
|
+
Log "9/9 Skipping compression for internal backup"
|
|
208
|
+
} else {
|
|
209
|
+
Log "9/9 Compressing backup ($ArchiveExtension)..."
|
|
210
|
+
$archivePath = Join-Path $BackupRoot ($ArchiveBase + ".$ArchiveExtension")
|
|
211
|
+
try {
|
|
212
|
+
if ($SevenZip) {
|
|
213
|
+
& $SevenZip.Source a -t7z -mx=9 $archivePath $ArchiveDir | Out-Null
|
|
214
|
+
if ($LASTEXITCODE -ne 0) { throw "7zip exited with code $LASTEXITCODE" }
|
|
215
|
+
} else {
|
|
216
|
+
Compress-Archive -LiteralPath $ArchiveDir -DestinationPath $archivePath -CompressionLevel Optimal -Force
|
|
217
|
+
}
|
|
218
|
+
OK " $archivePath"
|
|
219
|
+
} catch {
|
|
220
|
+
Warn " Compress-Archive failed: $_.Exception.Message"
|
|
221
|
+
Warn " Keeping uncompressed staging dir: $ArchiveDir"
|
|
222
|
+
$archivePath = $null
|
|
223
|
+
}
|
|
212
224
|
}
|
|
213
225
|
|
|
214
226
|
# ── 10. Clean up staging dir (unless told to keep it) ─────
|
package/backup-pi.sh
CHANGED
|
@@ -29,7 +29,7 @@ elif command -v zip >/dev/null 2>&1; then
|
|
|
29
29
|
ZIP_TOOL="zip"
|
|
30
30
|
ZIP_EXT="zip"
|
|
31
31
|
fi
|
|
32
|
-
[[ -n "$ZIP_TOOL" ]] || { echo
|
|
32
|
+
[[ -n "$ZIP_TOOL" ]] || { echo "[ERR] Neither 7zip nor zip found. Install one for compressed backups." >&2; exit 1; }
|
|
33
33
|
ARCHIVE="$BACKUP_ROOT/pi-backup-$TIMESTAMP.$ZIP_EXT"
|
|
34
34
|
|
|
35
35
|
# ─── Colors ──────────────────────────────────────────────────────
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
2
|
-
import {
|
|
2
|
+
import { execFileSync } from "node:child_process";
|
|
3
3
|
import { join, dirname } from "node:path";
|
|
4
4
|
import { fileURLToPath } from "node:url";
|
|
5
5
|
import { existsSync, mkdirSync, readdirSync, statSync, readFileSync, writeFileSync, rmSync, cpSync } from "node:fs";
|
|
@@ -90,6 +90,41 @@ function getRestoreScriptPath(): string {
|
|
|
90
90
|
return join(PACKAGE_ROOT, IS_WINDOWS ? "restore-pi.ps1" : "restore-pi.sh");
|
|
91
91
|
}
|
|
92
92
|
|
|
93
|
+
function findSevenZip(): string | null {
|
|
94
|
+
const lookup = IS_WINDOWS ? "where.exe" : "which";
|
|
95
|
+
for (const candidate of ["7zz", "7z", "7za"]) {
|
|
96
|
+
try {
|
|
97
|
+
execFileSync(lookup, [candidate], { stdio: "ignore" });
|
|
98
|
+
return candidate;
|
|
99
|
+
} catch {}
|
|
100
|
+
}
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function expandZipWithPowerShell(archivePath: string, destination: string): void {
|
|
105
|
+
execFileSync("pwsh", [
|
|
106
|
+
"-NoProfile",
|
|
107
|
+
"-Command",
|
|
108
|
+
"Expand-Archive -LiteralPath $env:PI_BACKUP_ARCHIVE -DestinationPath $env:PI_BACKUP_DEST -Force",
|
|
109
|
+
], {
|
|
110
|
+
env: { ...process.env, PI_BACKUP_ARCHIVE: archivePath, PI_BACKUP_DEST: destination },
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function extractArchive(archivePath: string, destination: string): void {
|
|
115
|
+
const sevenZip = findSevenZip();
|
|
116
|
+
if (sevenZip) {
|
|
117
|
+
execFileSync(sevenZip, ["x", "-y", `-o${destination}`, archivePath]);
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
if (archivePath.endsWith(".zip")) {
|
|
121
|
+
if (IS_WINDOWS) expandZipWithPowerShell(archivePath, destination);
|
|
122
|
+
else execFileSync("unzip", ["-q", archivePath, "-d", destination]);
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
throw new Error("7zip is required to extract .7z backups and was not found on PATH");
|
|
126
|
+
}
|
|
127
|
+
|
|
93
128
|
function ensureDirs(externalDir: string) {
|
|
94
129
|
if (!existsSync(INTERNAL_BACKUP_DIR)) mkdirSync(INTERNAL_BACKUP_DIR, { recursive: true });
|
|
95
130
|
if (!existsSync(externalDir)) mkdirSync(externalDir, { recursive: true });
|
|
@@ -238,12 +273,9 @@ function copyBackupToInternal(backup: BackupInfo): { success: boolean; output: s
|
|
|
238
273
|
if (backup.isCompressed) {
|
|
239
274
|
const tmpDir = join(INTERNAL_BACKUP_DIR, `.tmp-${Date.now()}`);
|
|
240
275
|
mkdirSync(tmpDir, { recursive: true });
|
|
241
|
-
|
|
242
|
-
execSync(`unzip -q "${backup.path}" -d "${tmpDir}"`);
|
|
243
|
-
} else {
|
|
244
|
-
execSync(`7z x -o"${tmpDir}" "${backup.path}" >/dev/null`);
|
|
245
|
-
}
|
|
276
|
+
extractArchive(backup.path, tmpDir);
|
|
246
277
|
const extracted = readdirSync(tmpDir)[0];
|
|
278
|
+
if (!extracted) throw new Error(`Archive is empty: ${backup.path}`);
|
|
247
279
|
cpSync(join(tmpDir, extracted), destPath, { recursive: true });
|
|
248
280
|
rmSync(tmpDir, { recursive: true, force: true });
|
|
249
281
|
} else {
|
|
@@ -432,19 +464,15 @@ async function confirmDelete(ctx: any, backup: BackupInfo) {
|
|
|
432
464
|
}
|
|
433
465
|
|
|
434
466
|
async function viewManifest(ctx: any, backup: BackupInfo) {
|
|
435
|
-
let
|
|
467
|
+
let content: string;
|
|
436
468
|
if (backup.isCompressed) {
|
|
437
469
|
const tmpDir = join(INTERNAL_BACKUP_DIR, `.tmp-manifest-${Date.now()}`);
|
|
438
470
|
mkdirSync(tmpDir, { recursive: true });
|
|
439
471
|
try {
|
|
440
|
-
|
|
441
|
-
execSync(`unzip -q "${backup.path}" "*/MANIFEST.txt" -d "${tmpDir}"`);
|
|
442
|
-
} else {
|
|
443
|
-
execSync(`7z x -o"${tmpDir}" "${backup.path}" "*/MANIFEST.txt" >/dev/null`);
|
|
444
|
-
}
|
|
472
|
+
extractArchive(backup.path, tmpDir);
|
|
445
473
|
const found = findFile(tmpDir, "MANIFEST.txt");
|
|
446
|
-
if (found)
|
|
447
|
-
|
|
474
|
+
if (!found) throw new Error("MANIFEST.txt not found in archive");
|
|
475
|
+
content = readFileSync(found, "utf-8");
|
|
448
476
|
} catch (e: any) {
|
|
449
477
|
ctx.ui.notify(`Failed to extract manifest: ${e.message}`, "error");
|
|
450
478
|
rmSync(tmpDir, { recursive: true, force: true });
|
|
@@ -452,15 +480,14 @@ async function viewManifest(ctx: any, backup: BackupInfo) {
|
|
|
452
480
|
}
|
|
453
481
|
rmSync(tmpDir, { recursive: true, force: true });
|
|
454
482
|
} else {
|
|
455
|
-
manifestPath = join(backup.path, "MANIFEST.txt");
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
483
|
+
const manifestPath = join(backup.path, "MANIFEST.txt");
|
|
484
|
+
if (!existsSync(manifestPath)) {
|
|
485
|
+
ctx.ui.notify("No manifest found in backup", "warning");
|
|
486
|
+
return;
|
|
487
|
+
}
|
|
488
|
+
content = readFileSync(manifestPath, "utf-8");
|
|
461
489
|
}
|
|
462
490
|
|
|
463
|
-
const content = readFileSync(manifestPath, "utf-8");
|
|
464
491
|
await ctx.ui.editor(`MANIFEST — ${backup.name}`, content);
|
|
465
492
|
}
|
|
466
493
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jamiefutch/pi-backup",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.10",
|
|
4
4
|
"description": "Pi package: Pi backup/restore scripts and TUI extension. Back up and restore all Pi config, skills, extensions, and memory; /pi-backup interactive manager.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
package/restore-pi.ps1
CHANGED
|
@@ -33,7 +33,7 @@ Examples:
|
|
|
33
33
|
.\$($MyInvocation.MyCommand.Name) ~\projects\personal\pi-utils\backups\pi-backup-20260811-143000
|
|
34
34
|
.\$($MyInvocation.MyCommand.Name) ~\projects\personal\pi-utils\backups\pi-backup-20260811-143000.zip
|
|
35
35
|
|
|
36
|
-
Accepts either an uncompressed backup directory or a compressed zip archive
|
|
36
|
+
Accepts either an uncompressed backup directory or a compressed zip/7z archive
|
|
37
37
|
(as produced by backup-pi.ps1).
|
|
38
38
|
|
|
39
39
|
Prerequisites:
|
|
@@ -48,17 +48,32 @@ if (-not $BackupArg) { Show-Usage }
|
|
|
48
48
|
# ─── Archive handling ─────────────────────────────────────
|
|
49
49
|
$STAGE = $null
|
|
50
50
|
$BackupDir = $null
|
|
51
|
+
$SevenZip = @('7zz', '7z', '7za') | ForEach-Object { Get-Command $_ -ErrorAction SilentlyContinue } | Select-Object -First 1
|
|
51
52
|
|
|
52
53
|
if (Test-Path -LiteralPath $BackupArg -PathType Container) {
|
|
53
54
|
# Uncompressed directory backup
|
|
54
55
|
$BackupDir = $BackupArg
|
|
55
|
-
} elseif (Test-Path -LiteralPath $BackupArg) {
|
|
56
|
-
# Compressed
|
|
56
|
+
} elseif (Test-Path -LiteralPath $BackupArg -PathType Leaf) {
|
|
57
|
+
# Compressed archive: prefer 7zip when installed, otherwise use native ZIP support.
|
|
58
|
+
$extension = [System.IO.Path]::GetExtension($BackupArg).ToLowerInvariant()
|
|
59
|
+
if ($extension -notin @('.zip', '.7z')) {
|
|
60
|
+
Err "Unsupported backup archive: $BackupArg (need .zip or .7z)"
|
|
61
|
+
exit 1
|
|
62
|
+
}
|
|
63
|
+
if ($extension -eq '.7z' -and -not $SevenZip) {
|
|
64
|
+
Err "7zip is required to extract .7z backups. Install 7-Zip and ensure it is on PATH."
|
|
65
|
+
exit 1
|
|
66
|
+
}
|
|
57
67
|
$STAGE = Join-Path $env:TEMP ("pi-restore-" + [guid]::NewGuid().ToString('N'))
|
|
58
68
|
New-Item -ItemType Directory -Path $STAGE -Force | Out-Null
|
|
59
69
|
Log "Extracting archive: $BackupArg"
|
|
60
70
|
try {
|
|
61
|
-
|
|
71
|
+
if ($SevenZip) {
|
|
72
|
+
& $SevenZip.Source x -y "-o$STAGE" $BackupArg | Out-Null
|
|
73
|
+
if ($LASTEXITCODE -ne 0) { throw "7zip exited with code $LASTEXITCODE" }
|
|
74
|
+
} else {
|
|
75
|
+
Expand-Archive -LiteralPath $BackupArg -DestinationPath $STAGE -Force
|
|
76
|
+
}
|
|
62
77
|
} catch {
|
|
63
78
|
Err "Failed to extract archive: $($_.Exception.Message)"
|
|
64
79
|
Remove-Item -LiteralPath $STAGE -Recurse -Force -ErrorAction SilentlyContinue
|
|
@@ -70,7 +85,7 @@ if (Test-Path -LiteralPath $BackupArg -PathType Container) {
|
|
|
70
85
|
$BackupDir = $top.FullName
|
|
71
86
|
Log "Extracted to: $BackupDir"
|
|
72
87
|
} else {
|
|
73
|
-
Err "Backup not found: $BackupArg (need a directory or .
|
|
88
|
+
Err "Backup not found: $BackupArg (need a directory, .zip, or .7z)"
|
|
74
89
|
exit 1
|
|
75
90
|
}
|
|
76
91
|
|
package/restore-pi.sh
CHANGED
|
@@ -60,19 +60,13 @@ elif [[ -f "$BACKUP_ARG" && "$BACKUP_ARG" =~ \.(zip|7z)$ ]]; then
|
|
|
60
60
|
# Compressed archive: extract to a temp dir first
|
|
61
61
|
STAGE="$(mktemp -d)"
|
|
62
62
|
log "Extracting archive: $BACKUP_ARG"
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
unzip -q "$BACKUP_ARG" -d "$STAGE"
|
|
66
|
-
else
|
|
67
|
-
# 7z can also extract zip; fall back to it
|
|
68
|
-
local tool="$(pick_extract_tool)"
|
|
69
|
-
[[ -n "$tool" ]] || { err "No unzip or 7zip available to extract the archive."; exit 1; }
|
|
70
|
-
"$tool" x -o"$STAGE" "$BACKUP_ARG" >/dev/null
|
|
71
|
-
fi
|
|
72
|
-
else
|
|
73
|
-
local tool="$(pick_extract_tool)"
|
|
74
|
-
[[ -n "$tool" ]] || { err "7zip is required to extract .7z backups. Install it."; exit 1; }
|
|
63
|
+
tool="$(pick_extract_tool)"
|
|
64
|
+
if [[ -n "$tool" ]]; then
|
|
75
65
|
"$tool" x -o"$STAGE" "$BACKUP_ARG" >/dev/null
|
|
66
|
+
elif [[ "$BACKUP_ARG" == *.zip ]] && command -v unzip >/dev/null 2>&1; then
|
|
67
|
+
unzip -q "$BACKUP_ARG" -d "$STAGE"
|
|
68
|
+
else
|
|
69
|
+
err "No 7zip or native ZIP extractor available for $BACKUP_ARG."; exit 1
|
|
76
70
|
fi
|
|
77
71
|
# The archive holds one top-level pi-backup-* dir
|
|
78
72
|
BACKUP_DIR="$(find "$STAGE" -mindepth 1 -maxdepth 1 -type d | head -1)"
|