Automatic Database Backup
Budget Forecaster automatically creates backups of your SQLite database at each application startup, providing a safety net against data corruption or accidental deletion.
Overview
When the application starts, it:
- Checks if backup is enabled in configuration
- Creates a timestamped copy of the database file
- Removes old backups exceeding the configured limit
Backups are created before any database operations, ensuring you always have a recovery point.
Configuration
Add a backup section to your config.yaml:
backup:
enabled: true # Enable/disable automatic backups (default: true)
max_backups: 5 # Number of backups to keep (default: 5)
directory: ./backups # Backup directory (default: same as database)
Options
| Option | Type | Default | Description |
|---|---|---|---|
enabled |
boolean | true |
Enable or disable automatic backups |
max_backups |
integer | 5 |
Maximum number of backup files to retain |
directory |
string | (db folder) | Directory to store backup files |
Backup File Naming
Backup files follow this naming convention:
For example, if your database is budget.db, backups will be named:
budget_2025-01-17_143022.dbbudget_2025-01-17_091500.dbbudget_2025-01-16_180045.db
Rotation Behavior
When the number of backups exceeds max_backups:
- Existing backups are sorted by modification time
- The oldest backups are deleted until only
max_backupsremain - The newest backups are always preserved
Manual Restore
To restore from a backup:
- Stop the application
- Locate the backup file you want to restore
- Copy it to replace your current database:
- Restart the application
Troubleshooting
Backups not being created
- Verify
backup.enabledistrue(or not set, as it defaults totrue) - Check that the database file exists (no backup on first run)
- Ensure write permissions on the backup directory
Permission errors
If you see permission errors in logs:
- Check that the backup directory is writable
- On shared systems, ensure your user owns the backup directory
Disk space
Monitor your backup directory size. With large databases and frequent restarts, backups
can consume significant space. Adjust max_backups accordingly.
Disabling Backups
To disable automatic backups: