diff --git a/README.md b/README.md index cb646ed..982538a 100644 --- a/README.md +++ b/README.md @@ -29,14 +29,15 @@ A backup command is available via `./manage.py backup_database` (also runs on a Configure these additional settings as needed: ``` -DB_BACKUP_SSH_KEY="/path/to/ssh/private/key" -DB_BACKUP_SSH_DEST="user@backup.example.com:/remote/path/" -DB_BACKUP_NTFY_URL="https://ntfy.sh/your-topic" +VROBBLER_DB_BACKUP_SSH_KEY="/path/to/ssh/private/key" +VROBBLER_DB_BACKUP_SSH_DEST="user@backup.example.com:/remote/path/" +VROBBLER_DB_BACKUP_NTFY_URL="https://ntfy.sh/your-topic" ``` -- `DB_BACKUP_SSH_KEY` — Path to the SSH private key used for remote copy. -- `DB_BACKUP_SSH_DEST` — SCP destination (user@host:path). If set alongside SSH_KEY, the backup is copied to the remote host and old backups are pruned. -- `DB_BACKUP_NTFY_URL` — ntfy.sh URL for success notifications. Defaults to `https://ntfy.unbl.ink/backups`. +- `VROBBLER_DB_BACKUP_SSH_KEY` — Path to the SSH private key used for remote copy. +- `VROBBLER_DB_BACKUP_SSH_DEST` — SCP destination (user@host:path). If set, the backup is copied to the remote host and old backups are pruned. +- `VROBBLER_DB_BACKUP_LOCAL_DIR` — Local directory for backup storage. Defaults to `/var/backups/`. Backups are stored in a `vrobbler/` subdirectory. +- `VROBBLER_DB_BACKUP_NTFY_URL` — ntfy.sh URL for success notifications. Defaults to `https://ntfy.unbl.ink/backups`. Retention is hardcoded: keeps daily backups for 7 days, plus one per month for 12 months. ``` diff --git a/vrobbler/apps/scrobbles/tasks.py b/vrobbler/apps/scrobbles/tasks.py index e304c50..709693e 100644 --- a/vrobbler/apps/scrobbles/tasks.py +++ b/vrobbler/apps/scrobbles/tasks.py @@ -327,6 +327,7 @@ def _run_remote_cleanup(ssh_key, ssh_host, remote_path): return from datetime import datetime + now = datetime.now() to_delete = _retention_files_to_delete(files, now) if not to_delete: @@ -363,7 +364,7 @@ def backup_database(): logger.warning("backup_database skipped — not PostgreSQL") return - backup_dir = Path("/var/backup/vrobbler") + backup_dir = Path(settings.DB_BACKUP_LOCAL_DIR) backup_dir.mkdir(parents=True, exist_ok=True) date_str = datetime.now().strftime("%Y_%m_%d") backup_path = backup_dir / f"vrobbler-backup-{date_str}.sql.gz" diff --git a/vrobbler/settings.py b/vrobbler/settings.py index 7d3f613..d92754b 100644 --- a/vrobbler/settings.py +++ b/vrobbler/settings.py @@ -66,6 +66,12 @@ IGDB_CLIENT_ID = os.getenv("VROBBLER_IGDB_CLIENT_ID") IGDB_CLIENT_SECRET = os.getenv("VROBBLER_IGDB_CLIENT_SECRET") COMICVINE_API_KEY = os.getenv("VROBBLER_COMICVINE_API_KEY") BGG_ACCESS_TOKEN = os.getenv("VROBBLER_BGG_ACCESS_TOKEN", "") +DB_BACKUP_SSH_KEY = os.getenv("VROBBLER_DB_BACKUP_SSH_KEY", "") +DB_BACKUP_SSH_DEST = os.getenv("VROBBLER_DB_BACKUP_SSH_DEST", "") +DB_BACKUP_LOCAL_DIR = os.getenv("VROBBLER_DB_BACKUP_LOCAL_DIR", "/var/backups/") +DB_BACKUP_NTFY_URL = os.getenv( + "VROBBLER_DB_BACKUP_NTFY_URL", "https://ntfy.unbl.ink/backups" +) GEOLOC_ACCURACY = os.getenv("VROBBLER_GEOLOC_ACCURACY", 3) GEOLOC_PROXIMITY = os.getenv("VROBBLER_GEOLOC_PROXIMITY", "0.0001") POINTS_FOR_MOVEMENT_HISTORY = os.getenv("VROBBLER_POINTS_FOR_MOVEMENT_HISTORY", 3)