Prepare MariaDB restore tests and recover backup disk space safely

This commit is contained in:
admin committed 2026-09-12 20:36:18 +02:00
1 parent f0c761213d
commit b0416461bc
23 files changed
+918 -129

No files matched your search

+7 -2
View File
@@ -99,9 +99,11 @@ def check_tar(path, roots):
proc = subprocess.Popen(command, stdout=subprocess.PIPE)
entries = {}
hardlinks = []
expanded = 0
try:
with tarfile.open(fileobj=proc.stdout, mode="r|") as archive:
for item in archive:
expanded += ((item.size + 4095) // 4096) * 4096 + 4096
name = member_name(item.name)
if not any(name == root or name.startswith(root + "/") for root in roots):
raise ValueError(f"Member outside component root: {name}")
@@ -128,6 +130,7 @@ def check_tar(path, roots):
pass
if proc.wait() != 0:
raise ValueError(f"Decompression failed: {path}")
return expanded
finally:
proc.stdout.close()
if proc.poll() is None:
@@ -291,9 +294,11 @@ def main():
crypt(*args)
elif op == "create":
create(Path(args[0]), *args[1:])
elif op in ("verify", "metadata", "list"):
elif op in ("verify", "metadata", "list", "expanded"):
data = load_set(Path(args[0]), metadata_only=op == "metadata")
if op == "verify":
if op == "expanded":
print(sum(check_tar(Path(args[0]) / item['file'], [item['root']]) for item in data['archives']))
elif op == "verify":
for item in data["archives"]:
check_tar(Path(args[0]) / item["file"], [item["root"]])
print(f"Verified: {data['run_id']} ({len(data['archives'])} archives)")