mirror of
https://github.com/retspen/webvirtcloud
synced 2026-12-03 01:16:10 +00:00
feat(backups): verify a backup's files on demand
The daily target check only finds files that are gone. Verify (a ready backup's Restore menu, superusers) runs backup.verify: it reads the backup's files and those of the backups it builds on whole from the target through a libvirt stream: each there, a disk at its size and in its format on its base's file, the small files with their SHA-256, and a disk with the SHA-256 recorded at its first verification. What is wrong is kept on the backup and shown as Damaged; a target that cannot be read fails the job and leaves the backup as it was. Progress in bytes, cancellable.
This commit is contained in:
parent
eeae606d08
commit
2cf7dbe577
14 changed files with 891 additions and 231 deletions
|
|
@ -1,5 +1,6 @@
|
|||
"""VM backups: the target pools and what a VM's backup holds (app vmbackups)."""
|
||||
|
||||
import contextlib
|
||||
import hashlib
|
||||
import os
|
||||
import re
|
||||
|
|
@ -262,6 +263,25 @@ def get_file(conn, pool, name):
|
|||
return conn.download_volume(pool.storageVolLookupByName(name))
|
||||
|
||||
|
||||
def read_sha256(conn, vol, on_read):
|
||||
"""The SHA-256 of the file of vol, read whole through a libvirt stream
|
||||
(holes as zeros); on_read(bytes) after each chunk, which may raise to
|
||||
stop the read."""
|
||||
digest = hashlib.sha256()
|
||||
stream = conn.wvm.newStream(0)
|
||||
try:
|
||||
vol.download(stream, 0, 0, 0)
|
||||
while data := stream.recv(1 << 20):
|
||||
digest.update(data)
|
||||
on_read(len(data))
|
||||
stream.finish()
|
||||
except BaseException:
|
||||
with contextlib.suppress(libvirt.libvirtError):
|
||||
stream.abort()
|
||||
raise
|
||||
return digest.hexdigest()
|
||||
|
||||
|
||||
def remove_files(pool, names):
|
||||
"""Deletes the volumes names of pool; missing ones are passed over."""
|
||||
for name in names:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue