Local backup: daily scheduled + before destroy#6
Open
titouanmathis wants to merge 9 commits intomainfrom
Open
Conversation
Add BackupConfig, BackupResult, and BackupEntry interfaces. Parse [backup] section from TOML config with defaults: - enabled: false - schedule_hour: 3 (3am) - retain_days: 7 - local_dir: /var/backups/trafic Co-authored-by: Claude <claude@anthropic.com>
Implement backup.ts with: - backupProjectDb: export a project DB via ddev export-db - backupAgentData: copy agent SQLite DB and config - runBackup: backup all or a specific project - listBackups: list available backups by date - cleanOldBackups: retention cleanup by date - restoreProjectDb: restore via ddev import-db - findBackup: find latest or date-specific backup file Auto-starts stopped projects before export/import. Backups stored as <localDir>/<YYYY-MM-DD>/<project>.sql.gz. Co-authored-by: Claude <claude@anthropic.com>
Add backup command with --name, --list, --clean options. Add restore command with --name, --date, --file options. Add backup-scheduler.ts for daily scheduled backups. Start backup scheduler alongside idle scheduler when backup.enabled is true. Co-authored-by: Claude <claude@anthropic.com>
Run trafic-agent backup --name <project> via SSH before deleting a project. Failure is non-blocking (warns and continues). Add --no-backup flag to skip the backup step. Co-authored-by: Claude <claude@anthropic.com>
Add 13 tests for backup logic (listBackups, cleanOldBackups, findBackup). Update destroy tests for the new backup-before-destroy step: - Expect 3 exec calls (backup + delete + rm) - Add test for --no-backup flag - Add test for backup failure being non-blocking Co-authored-by: Claude <claude@anthropic.com>
Add [backup] section to examples/config.toml with documentation. Export backup types and functions from the agent's public API. Co-authored-by: Claude <claude@anthropic.com>
Use a finally block to ensure projects that were stopped before backup are stopped again after export, whether it succeeds or fails. Prevents daily backups from leaving all projects running. Co-authored-by: Claude <claude@anthropic.com>
Avoid starting all stopped projects during scheduled backups. Instead: - Idle scheduler backs up each project before stopping it - Scheduled daily backup only exports running projects - Manual CLI backup with --name forces start for a specific project - trafic-agent backup (all) skips stopped projects This ensures every project gets a fresh backup before going idle, without the resource cost of starting everything for a full backup. Co-authored-by: Claude <claude@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #1 (partial — local backup only, remote storage to come later).
Adds local backup support to trafic with two triggers:
Agent changes (
packages/trafic-agent/)New types
BackupConfig— configuration for[backup]TOML sectionBackupResult/BackupEntry— result and listing typesConfig (
src/utils/config.ts)[backup]section with defaults: disabled, 3am schedule, 7-day retention,/var/backups/traficCore logic (
src/tasks/backup.ts)backupProjectDb()— exports a project DB viaddev export-db --gzipbackupAgentData()— copies agent SQLite DB and config filerunBackup()— backup all or a specific projectlistBackups()— list available backups grouped by datecleanOldBackups()— remove backups older than retention periodrestoreProjectDb()— restore viaddev import-dbfindBackup()— find latest or date-specific backup fileAuto-starts stopped projects before export/import. Backups stored as
<localDir>/<YYYY-MM-DD>/<project>.sql.gz.Scheduler (
src/tasks/backup-scheduler.ts)CLI commands (
src/cli.ts)trafic-agent backup— backup all projectstrafic-agent backup --name my-app— backup a specific projecttrafic-agent backup --list— list available backupstrafic-agent backup --clean— clean old backupstrafic-agent restore --name my-app— restore from latest backuptrafic-agent restore --name my-app --date 2026-02-07— restore from specific dateCLI changes (
packages/trafic-cli/)Backup before destroy (
src/commands/destroy.ts)trafic-agent backup --name <project>via SSH beforeddev delete--no-backupflagTests
Config example
Future work