| 47 | |
| 48 | |
| 49 | def backup_profiles(db_path: Path) -> Path: |
| 50 | backup_dir = PROJECT_ROOT / "data" / "backups" |
| 51 | backup_dir.mkdir(parents=True, exist_ok=True) |
| 52 | timestamp = datetime.now().strftime("%Y%m%d_%H%M%S") |
| 53 | backup_path = backup_dir / f"profiles_backup_{timestamp}.json" |
| 54 | |
| 55 | conn = sqlite3.connect(db_path) |
| 56 | conn.row_factory = sqlite3.Row |
| 57 | rows = [dict(row) for row in conn.execute("SELECT * FROM profiles ORDER BY user_id")] |
| 58 | conn.close() |
| 59 | |
| 60 | backup_path.write_text(json.dumps(rows, ensure_ascii=False, indent=2), encoding="utf-8") |
| 61 | return backup_path |
| 62 | |
| 63 | |
| 64 | def clear_profiles_only(db_path: Path) -> int: |