mirror of
https://github.com/MarekWo/mc-webui.git
synced 2026-03-28 17:42:45 +01:00
fix(backup): use DB filename as backup prefix instead of hardcoded 'mc-webui'
Backup filenames now derive from the active DB stem (e.g. mc_9cebbd27.2026-03-24.db). Listing and cleanup glob *.db so existing mc-webui.* backups remain visible. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1064,7 +1064,8 @@ class Database:
|
|||||||
backup_dir.mkdir(parents=True, exist_ok=True)
|
backup_dir.mkdir(parents=True, exist_ok=True)
|
||||||
|
|
||||||
date_str = datetime.now().strftime('%Y-%m-%d')
|
date_str = datetime.now().strftime('%Y-%m-%d')
|
||||||
backup_path = backup_dir / f"mc-webui.{date_str}.db"
|
prefix = self.db_path.stem # e.g. "mc_9cebbd27"
|
||||||
|
backup_path = backup_dir / f"{prefix}.{date_str}.db"
|
||||||
|
|
||||||
source = sqlite3.connect(str(self.db_path))
|
source = sqlite3.connect(str(self.db_path))
|
||||||
dest = sqlite3.connect(str(backup_path))
|
dest = sqlite3.connect(str(backup_path))
|
||||||
@@ -1084,7 +1085,7 @@ class Database:
|
|||||||
return []
|
return []
|
||||||
|
|
||||||
backups = []
|
backups = []
|
||||||
for f in sorted(backup_dir.glob("mc-webui.*.db"), reverse=True):
|
for f in sorted(backup_dir.glob("*.db"), reverse=True):
|
||||||
backups.append({
|
backups.append({
|
||||||
'filename': f.name,
|
'filename': f.name,
|
||||||
'path': str(f),
|
'path': str(f),
|
||||||
@@ -1101,7 +1102,7 @@ class Database:
|
|||||||
|
|
||||||
cutoff = datetime.now() - timedelta(days=retention_days)
|
cutoff = datetime.now() - timedelta(days=retention_days)
|
||||||
removed = 0
|
removed = 0
|
||||||
for f in backup_dir.glob("mc-webui.*.db"):
|
for f in backup_dir.glob("*.db"):
|
||||||
if datetime.fromtimestamp(f.stat().st_mtime) < cutoff:
|
if datetime.fromtimestamp(f.stat().st_mtime) < cutoff:
|
||||||
f.unlink()
|
f.unlink()
|
||||||
removed += 1
|
removed += 1
|
||||||
|
|||||||
@@ -392,7 +392,7 @@ class TestBackup:
|
|||||||
db.create_backup(backup_dir)
|
db.create_backup(backup_dir)
|
||||||
backups = db.list_backups(backup_dir)
|
backups = db.list_backups(backup_dir)
|
||||||
assert len(backups) == 1
|
assert len(backups) == 1
|
||||||
assert 'mc-webui.' in backups[0]['filename']
|
assert backups[0]['filename'].endswith('.db')
|
||||||
|
|
||||||
def test_list_backups_empty_dir(self, db):
|
def test_list_backups_empty_dir(self, db):
|
||||||
with tempfile.TemporaryDirectory() as tmp:
|
with tempfile.TemporaryDirectory() as tmp:
|
||||||
|
|||||||
Reference in New Issue
Block a user