Package Exports
- cat-ate-my-source-code
- cat-ate-my-source-code/dist/cli.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (cat-ate-my-source-code) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
cat-ate-my-source-code
A pragmatic backup & restore CLI tool for code projects, focused on disaster recovery and redundancy habits.
"The Cat Ate My Source Code" - Inspired by The Pragmatic Programmer, this tool helps you develop good backup habits and protect your code from disasters.
Features
- ✅ Versioned Backups: Timestamped backups for easy tracking
- ✅ Multiple Projects: Configure and backup multiple code projects
- ✅ Exclude Patterns: Skip
node_modules,.git, and other unnecessary files - ✅ Retention Policy: Automatically prune old backups
- ✅ Dry-Run Mode: Preview what will be backed up
- ✅ Cross-Platform: Works on macOS, Linux, and Windows
- ✅ Config-Driven: Simple JSON configuration
- 🔜 Remote Backups: Interface designed for rsync/SCP (implementation stubbed)
Installation
npm install
npm run buildFor global installation:
npm linkConfiguration
Create a configuration file in one of these locations:
cat-ate-my-source-code.config.jsonin your current working directory~/.cat-ate-my-source-code/config.jsonin your home directory
Example Configuration
{
"projects": [
{
"name": "my-app",
"path": "/Users/me/dev/my-app",
"exclude": ["node_modules", ".git", "dist", "*.log"]
}
],
"backupTargets": [
{
"name": "local-disk",
"type": "local",
"path": "/Users/me/backups"
}
],
"retention": {
"maxBackupsPerProject": 10
}
}Configuration Options
projects: Array of project configurations
name: Unique project identifierpath: Absolute or relative path to project directoryexclude: Array of glob patterns to exclude (e.g.,["node_modules", ".git"])
backupTargets: Array of backup destinations
name: Unique target identifiertype:"local"or"remote"(remote is stubbed)path: Destination path for backupsssh: (Remote only) SSH connection details
retention: Retention policy
maxBackupsPerProject: Maximum number of backups to keep per project (default: 10)
compression: Enable compression (not yet implemented, default: false)
Usage
Note: The example config file (cat-ate-my-source-code.config.json) contains placeholder paths. Update it with your actual project paths before use.
Backup Commands
After building (npm run build), use the compiled CLI:
node dist/cli.js backup --project my-appOr during development with ts-node:
npm start -- backup --project my-appBackup all projects:
node dist/cli.js backup --allDry-run to preview:
node dist/cli.js backup --project my-app --dry-runList Backups
List all backups for a project:
node dist/cli.js list --project my-appList backups for all projects:
node dist/cli.js listRestore Commands
Restore a backup to a destination:
node dist/cli.js restore --project my-app --backup 2025-01-15T10-30-00Z --dest /tmp/restore-my-appNote: The restore command will not overwrite existing directories by default. Choose a destination that doesn't exist, or use --in-place (not yet implemented) with confirmation.
Check Configuration
Validate your configuration file:
node dist/cli.js checkGlobal Options
--config <path>: Specify a custom config file path--verboseor-v: Enable verbose output--dry-run: Preview operations without making changes
Backup Structure
Backups are organized as follows:
backups/
└── my-app/
├── 2025-01-15T10-30-00Z/
│ └── [project files]
├── 2025-01-15T14-20-00Z/
│ └── [project files]
└── ...Each backup is a timestamped directory containing a complete copy of the project (excluding specified patterns).
Retention Policy
After creating a new backup, the tool automatically removes the oldest backups that exceed maxBackupsPerProject. This keeps your backup storage manageable while maintaining a history of recent backups.
Development
Build
npm run buildRun in Development
npm start backup --project my-appTest
npm testPhilosophy
This tool embodies the principles from The Pragmatic Programmer:
- Always Use Version Control: While Git is essential, backups provide an additional safety net
- Backup Early, Backup Often: Automated backups help you develop good habits
- Design for Failure: Multiple backup targets and retention policies ensure redundancy
- DRY (Don't Repeat Yourself): Config-driven approach means you define your projects once
The name "cat-ate-my-source-code" is a playful reference to the book's discussion about excuses and the importance of having backups. When disaster strikes (hardware failure, accidental deletion, etc.), you'll be glad you have backups.
Limitations & Future Work
- Remote Backups: Interface is designed but implementation is stubbed. Future versions will support rsync/SCP.
- Compression: Config option exists but compression is not yet implemented.
- In-Place Restore:
--in-placeflag is designed but not yet implemented for safety.
License
MIT