#!/usr/bin/env python3
"""Create a consistent SQLite backup of the SPG support database."""
from pathlib import Path
from datetime import datetime
import sqlite3
import config

base = Path(__file__).resolve().parent
source = Path(config.DATABASE_PATH)
if not source.is_absolute():
    source = base / source
if not source.exists():
    raise SystemExit(f"Database not found: {source}; start the bot once first.")
outdir = base / "backups"
outdir.mkdir(exist_ok=True)
target = outdir / f"spg_support_{datetime.now().strftime('%Y%m%d_%H%M%S')}.sqlite3"
with sqlite3.connect(source) as src, sqlite3.connect(target) as dst:
    src.backup(dst)
print(f"Backup created: {target}")
