Skip to content

feat enhanced TOOL: Add diff, backup --user-only, and migrate --auto to BackupRestore.ts #974

Open
sauldataman wants to merge 6 commits intodanielmiessler:mainfrom
sauldataman:feat/enhance-backup-upgrade
Open

feat enhanced TOOL: Add diff, backup --user-only, and migrate --auto to BackupRestore.ts #974
sauldataman wants to merge 6 commits intodanielmiessler:mainfrom
sauldataman:feat/enhance-backup-upgrade

Conversation

@sauldataman
Copy link
Contributor

@sauldataman sauldataman commented Mar 20, 2026

Summary

fix #973

Enhance Tools/BackupRestore.ts with three new capabilities for safer PAI release updates:

  • diff --release <path> — Preview which local files differ from a release using SHA-256 comparison
  • backup --user-only --release <path> — Back up only user data (PAI/USER/, MEMORY/, settings.json, user-generated files, modified system files) instead of the entire ~/.claude directory
  • migrate --auto --release <path> — Automatically restore user data from a user-only backup after applying a new release

All existing commands (backup, restore, list, migrate) are completely unchanged.

Motivation

The current migrate command identifies only _-prefixed skills, settings identity fields, and MEMORY subdirectory names — missing PAI/USER/ content, user-modified hooks/skills, installed Packs, Claude Code auto-memory (projects/), and other user-generated data. It also only produces a text report without performing any restore.

These additions give users visibility into what a release update will change (diff), a way to capture only their data (backup --user-only), and an automated restore path (migrate --auto) — reducing the manual effort and risk of losing customizations during updates.

Changes

Single file changed: Tools/BackupRestore.ts

New commands:

  • diff --release <path> — SHA-256 comparison against release, excluding PAI/USER/, MEMORY/, settings.json, PAI-Install/ from conflict reporting (handled separately)
  • backup --user-only --release <path> — Backs up user data in three categories: always-backup dirs (PAI/USER/, MEMORY/), modified system files, and user-generated files not in the release. Supports --exclude for fine-grained control
  • migrate --auto --release <path> — Restores user data from the latest user-only backup (or --backup <path>), skips CLAUDE.md (regenerated by BuildCLAUDE.ts), then runs BuildCLAUDE.ts

Unchanged commands:

  • backup, restore, list, migrate — no behavioral changes

Migration Flow

# 1. Full backup (safety net)
bun Tools/BackupRestore.ts backup --name "pre-v4.1"

# 2. Preview changes
bun Tools/BackupRestore.ts diff --release ./Releases/v4.1.0/.claude

# 3. Smart backup of user data
bun Tools/BackupRestore.ts backup --user-only --release ./Releases/v4.1.0/.claude

# 4. Apply new release
cp -r ./Releases/v4.1.0/.claude ~/

# 5. Restore user data
bun Tools/BackupRestore.ts migrate --auto --release ./Releases/v4.1.0/.claude

# 6. Merge settings
cd ~/.claude && bash install.sh

# 7. Rebuild CLAUDE.md
bun ~/.claude/PAI/Tools/BuildCLAUDE.ts

Test plan

  • diff --release correctly shows new/unchanged/conflict files
  • diff excludes PAI/USER/, MEMORY/, settings.json, PAI-Install/ from conflicts
  • backup --user-only includes PAI/USER/, MEMORY/, settings.json, CLAUDE.md, and all user-generated files
  • backup --user-only --exclude correctly removes specified files from backup
  • list distinguishes full vs user-only backups with [user-only] tag
  • migrate --auto restores files from user-only backup, skips CLAUDE.md
  • migrate --auto auto-finds latest user-only backup when --backup is not specified
  • migrate (without --auto) works exactly as before
  • backup, restore, list work exactly as before

@sauldataman
Copy link
Contributor Author

related to issue #973

@sauldataman sauldataman force-pushed the feat/enhance-backup-upgrade branch 2 times, most recently from 3af0f47 to e9d3533 Compare March 20, 2026 03:48
sauldataman and others added 3 commits March 19, 2026 20:50
… upgrades

Add three new capabilities to BackupRestore.ts for safe upgrade workflows:

- `diff --release <path>`: Compare local installation against a release
  using SHA-256 hashes. Shows new files, unchanged files, and conflicts
  (locally modified system files). Automatically excludes PAI/USER/,
  MEMORY/, settings.json, PAI-Install/, and CLAUDE.md from conflict
  reporting since they are handled separately.

- `backup --user-only --release <path>`: Smart backup that saves only
  user data: always-backup dirs (PAI/USER/, MEMORY/), settings.json,
  CLAUDE.md, modified system files, and user-generated files not in
  the release. Excludes CC runtime dirs (debug/, telemetry/, etc.).
  Supports --exclude for fine-grained control.

- `upgrade --release <path>`: Automated upgrade cycle — checks for
  full backup, diffs, backs up user data, applies release via cp -r,
  restores user modifications, and rebuilds CLAUDE.md. Skips restoring
  CLAUDE.md (regenerated by BuildCLAUDE.ts) but restores settings.json
  before install.sh runs so its merge logic preserves user config.

Ignore patterns are read from the repo's .gitignore rather than
hardcoded. All existing commands (backup, restore, list, migrate)
are completely unchanged.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…re.ts

Add three new capabilities for safer PAI release updates:

- diff --release <path>: SHA-256 comparison against release, auto-excludes
  PAI/USER/, MEMORY/, settings.json, PAI-Install/ from conflict reporting

- backup --user-only --release <path>: Smart backup of user data — always
  includes PAI/USER/, MEMORY/, settings.json, CLAUDE.md, plus modified
  system files and user-generated files not in the release. Supports
  --exclude for fine-grained control

- migrate --auto [--backup <path>]: Auto-restore user data from a
  user-only backup after applying a new release. Skips CLAUDE.md
  (regenerated by BuildCLAUDE.ts), runs BuildCLAUDE.ts after restore

All existing commands (backup, restore, list, migrate) unchanged.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@sauldataman sauldataman force-pushed the feat/enhance-backup-upgrade branch from e9d3533 to b6d1418 Compare March 20, 2026 03:50
sauldataman and others added 3 commits March 19, 2026 22:49
- Replace execSync("bun BuildCLAUDE.ts") with dynamic import of build()
  to eliminate the only shell command dependency. All operations now use
  Node.js/Bun APIs exclusively (cpSync, readFileSync, createHash, etc.)
- Remove unused execSync import
- Remove empty BACKUP_EXCLUDE_DIRS constant (no dirs are excluded)
- Fix stale --release parameter references in migrate --auto comments,
  header docs, and printUsage Migration Flow
- Fix "upgrading" → "migration" in diff output text

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Instead of copying files one by one, use cpSync(backup, target, {recursive: true})
matching the approach used by the original restoreBackup function. Then remove
auto-regenerated files (CLAUDE.md) and the backup manifest afterward.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
cpSync with recursive:true fails on read-only files (e.g. .git/objects/).
Switch back to per-file copy with try/catch to skip permission errors
gracefully instead of aborting the entire restore.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TOOL enhance, feat: Add diff, backup --user-only, and migrate --auto for safer PAI release updates

1 participant