Files
AIPass/src/aipass/backup/README.md
T
AIPassandClaude Opus 4.6 2aa207bdaa feat(backup): S62 4-phase rebuild — atomic writes, API auth migration, Google Drive sync, 75 new tests (#143)
Backup branch overnight rebuild (FPLAN-0141):
- P1: Branding fixed (BACKUP_SYSTEM→backup), dead code removed, conftest cleaned, README updated
- P2: JSON corruption root cause fixed — atomic writes (temp+os.replace) in json_handler, changelog, backup_info, timestamps. load_json hardened with JSONDecodeError catch + template regeneration
- P3: Google Drive auth migrated to @api — drive_sync_client now imports from api.google_client. 80-line authenticate() replaced, thread service + retry logic from API. Legacy JSON format auto-migration added
- P4: 75 new tests (182→257) — diff_generator, drive_sync_json, report_formatter, statistics_handler, backup_metadata_builder + json_handler expansions
- Drive-sync bugs: list index mismatch, drive-test routing (False→True return), config stuck disabled
- Drone: backup promoted to interactive_branches (per-branch allowlist, no timeout for any backup command)

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-29 17:26:17 -07:00

4.9 KiB

BACKUP

Purpose: Multi-mode backup with Google Drive integration Module: aipass.backup Created: 2026-03-07 Citizen Class: builder Last Updated: 2026-03-28


Overview

Builder citizen — full 3-layer architecture with identity and memory.

Provides automated file protection through snapshot backups, versioned backups, and Google Drive synchronization. The entry point routes commands to two specialized modules: backup_core and google_drive_sync.


Architecture

backup/
├── __init__.py
├── README.md
├── apps/
│   ├── backup.py                # Entry point (CLI) — drone @backup
│   ├── modules/
│   │   ├── backup_core.py       # Core backup operations (snapshot, versioned)
│   │   └── google_drive_sync.py # Google Drive sync orchestration
│   ├── handlers/
│   │   ├── config/
│   │   │   └── config_handler.py        # Configuration management
│   │   ├── diff/
│   │   │   └── diff_generator.py        # Diff generation between backups
│   │   ├── json/
│   │   │   ├── backup_info_handler.py   # Backup info JSON read/write
│   │   │   ├── backup_metadata_builder.py # Metadata construction
│   │   │   ├── changelog_handler.py     # Changelog JSON management
│   │   │   ├── drive_sync_json.py       # Drive sync state tracking
│   │   │   ├── json_handler.py          # Generic JSON utilities
│   │   │   └── statistics_handler.py    # Backup statistics
│   │   ├── models/
│   │   │   └── backup_models.py         # Data models for backup objects
│   │   ├── operations/
│   │   │   ├── drive_sync_client.py     # Google Drive API client
│   │   │   ├── drive_sync_ops.py        # Drive sync implementation
│   │   │   ├── file_cleanup.py          # Old backup cleanup
│   │   │   ├── file_operations.py       # File copy/move operations
│   │   │   ├── file_scanner.py          # File discovery and filtering
│   │   │   └── path_builder.py          # Backup path construction
│   │   ├── reporting/
│   │   │   └── report_formatter.py      # Backup report formatting
│   │   └── utils/
│   │       ├── backup_timestamps.py     # Timestamp utilities
│   │       └── system_utils.py          # System-level utilities
│   └── json_templates/          # JSON template files
├── backup_json/                 # JSON tracking data
├── artifacts/                   # Backup artifacts
├── docs/                        # Documentation
├── tests/                       # Test suite
└── tools/                       # Branch verification utilities

Commands / Usage

drone @backup                              # Introspection — list discovered modules
drone @backup --help                       # Show full help
drone @backup --version                    # Show version
drone @backup --all                        # Full backup cycle: snapshot -> versioned -> drive-sync
drone @backup snapshot                     # Create a system snapshot backup
drone @backup versioned                    # Create a versioned backup
drone @backup drive-test                   # Test Google Drive connectivity
drone @backup drive-sync                   # Sync backups to Google Drive
drone @backup drive-sync --test            # Run a small test sync to verify integration
drone @backup drive-stats                  # Show Drive file tracker statistics
drone @backup drive-clear-tracker          # Clear Drive file tracker cache

Options:

Flag Description
--verbose, -v Extra diagnostic output
--dry-run Preview what would happen, execute nothing
--note NOTE Add a backup note/description
--project NAME Project name for Drive sync (default: AIPass)
--force Force sync all files (ignore change tracker)
--limit N Limit drive-sync to first N files

Integration Points

Depends On

  • rich — Console output and formatting
  • Python stdlib (sys, argparse, logging, pathlib)

Provides To

  • All modules — automated file protection, snapshot and versioned backups
  • Google Drive — cloud backup synchronization
  • Other branches — backup artifacts via backup_json/ and artifacts/

Modules

Module Purpose
backup_core Core backup operations — snapshot and versioned backup creation
google_drive_sync Google Drive synchronization — upload, track, and manage cloud backups

Identity

  • Passport: .trinity/passport.json
  • Session History: .trinity/local.json
  • Observations: .trinity/observations.json
  • Branch Prompt: .aipass/branch_system_prompt.md