fix(uninstall): MANDATORY tar backup in ALL modes (safe/settings-only/full)

Per user demand after data loss incident: never trust mode flags alone.
Previously only `full` mode created tar.gz backup. Now `safe` and
`settings-only` also create full tar.gz of ~/.claude (resp .codex,
.gemini, .qwen) BEFORE any mutation. If backup fails, refuse to
proceed for that user — skip to next.

Restore is always one command:
  tar -xzf ~/.<tool>.uninstall-backup.<TS>.tar.gz -C ~

Applies to all 4 scripts: uclaude, ucodex, ugemini, uqwen.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
delta-cloud-208e
2026-04-26 07:17:34 +00:00
parent 84c1287501
commit dd11b9784d
4 changed files with 66 additions and 39 deletions

View File

@@ -166,6 +166,24 @@ for user_home in /root /home/*; do
CLAUDE_DIR="$user_home/.claude"
[ -d "$CLAUDE_DIR" ] || continue
# ALWAYS create full tar backup BEFORE any destructive operation, in EVERY mode.
# Per user demand after data loss incident: never trust mode flags alone.
# If backup fails, refuse to touch this user's data and skip to next user.
FULL_BACKUP_TAR="$user_home/.claude.uninstall-backup.${TIMESTAMP}.tar.gz"
info "Creating safety backup: $FULL_BACKUP_TAR ..."
if ! tar -czf "$FULL_BACKUP_TAR" -C "$user_home" .claude 2>/dev/null; then
err "Backup FAILED for $CLAUDE_DIR — REFUSING to proceed (data preserved)"
continue
fi
backup_size=$(du -h "$FULL_BACKUP_TAR" 2>/dev/null | awk '{print $1}')
log "Safety backup: $FULL_BACKUP_TAR ($backup_size)"
log "Restore anytime: tar -xzf $FULL_BACKUP_TAR -C $user_home"
# Also back up ~/.claude.json (onboarding state lives outside .claude/)
if [ -f "$user_home/.claude.json" ]; then
cp -p "$user_home/.claude.json" "$user_home/.claude.json.uninstall.bak.${TIMESTAMP}" 2>/dev/null || true
fi
case "$MODE" in
safe)
# Remove ONLY patcher-managed files. Preserve all user data.
@@ -197,18 +215,9 @@ for user_home in /root /home/*; do
;;
full)
# WIPE — but ALWAYS backup first.
BACKUP_TAR="$user_home/.claude.uninstall-backup.${TIMESTAMP}.tar.gz"
info "Creating backup: $BACKUP_TAR ..."
if tar -czf "$BACKUP_TAR" -C "$user_home" .claude 2>/dev/null; then
local_size=$(du -h "$BACKUP_TAR" 2>/dev/null | awk '{print $1}')
log "Backup saved: $BACKUP_TAR ($local_size)"
rm -rf "$CLAUDE_DIR"
log "Removed $CLAUDE_DIR"
log " Restore anytime: tar -xzf $BACKUP_TAR -C $user_home"
else
err "Backup FAILED — refusing to delete $CLAUDE_DIR (data preserved)"
fi
# Backup already created above. Now wipe.
rm -rf "$CLAUDE_DIR"
log "Removed $CLAUDE_DIR (full wipe)"
;;
esac