mirror of
https://github.com/retspen/webvirtcloud
synced 2026-12-01 16:36:06 +00:00
fix: backups and snapshots keep their order when the clock goes back
Backup retention kept the last --keep backups by name, and a name is the panel's local time. Where the clock goes back an hour in autumn (TIME_ZONE=Europe/Berlin), a backup at 02:10 CET forty minutes after one at 02:50 CEST sorted first, and --keep 1 deleted the new one. Retention now keeps the newest by when they were made (the directory's mtime); the names stay as they were. Snapshot times from libvirt (epoch seconds) became naive local times, which the snapshot list sorts newest first: in the same hour the older snapshot came first. They are now aware UTC times; the page still shows them in the panel's time zone. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Kk4h2TcUiaWmU5MUszYSea
This commit is contained in:
parent
0d20d07b29
commit
25e49c2aa2
4 changed files with 26 additions and 7 deletions
|
|
@ -2,6 +2,7 @@
|
|||
readable only by the panel's user, the newest --keep of them kept."""
|
||||
|
||||
import fcntl
|
||||
from datetime import datetime
|
||||
import os
|
||||
import shutil
|
||||
import sqlite3
|
||||
|
|
@ -85,12 +86,24 @@ class BackupTests(SimpleTestCase):
|
|||
self.assertEqual(oct(copy.stat().st_mode & 0o777), "0o600")
|
||||
|
||||
def test_only_the_newest_backups_and_no_partial_one_are_kept(self):
|
||||
for name in ("webvirtcloud-backup-20260101-000000", "webvirtcloud-backup-20260102-000000",
|
||||
".webvirtcloud-backup-20260103-000000"):
|
||||
for made, name in ((1, "webvirtcloud-backup-20260101-000000"), (2, "webvirtcloud-backup-20260102-000000"),
|
||||
(3, ".webvirtcloud-backup-20260103-000000")):
|
||||
(self.backups / name).mkdir(parents=True)
|
||||
os.utime(self.backups / name, (made, made))
|
||||
backup = self.backup("--keep", "2")
|
||||
self.assertEqual(self.kept(), ["webvirtcloud-backup-20260102-000000", backup.name])
|
||||
|
||||
def test_the_newest_are_kept_by_when_they_were_made_not_by_name(self):
|
||||
# 02:50 CEST, then 02:10 CET forty minutes later as the clock went back; or an
|
||||
# older backup named in another time zone
|
||||
older = self.backups / "webvirtcloud-backup-20261025-025000"
|
||||
older.mkdir(parents=True)
|
||||
os.utime(older, (1, 1))
|
||||
with patch("appsettings.management.commands.backup.datetime") as clock:
|
||||
clock.now.return_value = datetime(2026, 10, 25, 2, 10)
|
||||
newest = self.backup("--keep", "1")
|
||||
self.assertEqual(self.kept(), [newest.name])
|
||||
|
||||
def test_a_failed_backup_leaves_nothing_and_deletes_no_older_one(self):
|
||||
(self.backups / "webvirtcloud-backup-20260101-000000").mkdir(parents=True)
|
||||
with patch.object(Command, "copy", side_effect=OSError("No space left on device")), self.assertRaises(OSError):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue