Files
felhom.eu/documentation/runbooks/pbs-phantom-list.py
T

24 lines
1.0 KiB
Python

import os, re, json
root = "/mnt/pbs-datastore"
rows = []
def walk_ns(base, ns):
for typ in ("ct", "vm", "host"):
tdir = os.path.join(base, typ)
if not os.path.isdir(tdir): continue
for gid in sorted(os.listdir(tdir)):
gdir = os.path.join(tdir, gid)
for snap in sorted(os.listdir(gdir)):
sdir = os.path.join(gdir, snap)
if not os.path.isdir(sdir) or not re.match(r"\d{4}-\d{2}-\d{2}T", snap): continue
files = os.listdir(sdir)
size = sum(os.path.getsize(os.path.join(sdir, f)) for f in files)
man = "index.json.blob" in files
manifest_files = []
rows.append({"ns": ns or "(root)", "group": f"{typ}/{gid}", "snap": snap, "files": sorted(files), "dir_bytes": size, "manifest": man})
nsdir = os.path.join(base, "ns")
if os.path.isdir(nsdir):
for n in sorted(os.listdir(nsdir)):
walk_ns(os.path.join(nsdir, n), (ns + "/" if ns else "") + n)
walk_ns(root, "")
print(json.dumps(rows))