check-snapshot-age aktualisiert

Erweiterung Filter nach Dataset oder Volums
This commit is contained in:
2025-05-15 11:12:29 +02:00
parent bf46208c4d
commit 412a576ccd
+16 -6
View File
@@ -3,25 +3,35 @@
import subprocess import subprocess
import re import re
import time import time
import argparse
#_snapshots = open("zfs.txt","r").read() # Argumente verarbeiten
parser = argparse.ArgumentParser(description="ZFS Snapshot Übersicht")
parser.add_argument("--filter", help="Nur bestimmte Datasets anzeigen (Regex möglich, z.B. 'rpool/ROOT')", type=str)
args = parser.parse_args()
# Snapshots abrufen
_snapshots = subprocess.check_output("/usr/sbin/zfs list -t snapshot -Hpo name,creation".split()) _snapshots = subprocess.check_output("/usr/sbin/zfs list -t snapshot -Hpo name,creation".split())
LABELS = ("frequent", "hourly", "daily", "weekly", "monthly", "yearly", "backup-zfs", "bashclub-zfs") LABELS = ("frequent", "hourly", "daily", "weekly", "monthly", "yearly", "backup-zfs", "bashclub-zfs")
RE_LABELSEARCH = re.compile("|".join(LABELS)) RE_LABELSEARCH = re.compile("|".join(LABELS))
_datasets = {} _datasets = {}
for _datastore,_snapshot,_creation in re.findall("^([\w_./-]+)@([\w_.-]+)\t(\d+)",_snapshots.decode('utf-8'),re.M):
# Snapshots parsen
for _datastore, _snapshot, _creation in re.findall(r"^([\w_./-]+)@([\w_.-]+)\t(\d+)", _snapshots.decode('utf-8'), re.M):
if args.filter and not re.search(args.filter, _datastore):
continue # Dataset entspricht nicht dem Filter
if _datastore not in _datasets: if _datastore not in _datasets:
_datasets[_datastore] = {} _datasets[_datastore] = {}
_label = RE_LABELSEARCH.search(_snapshot) _label = RE_LABELSEARCH.search(_snapshot)
if _label: _label = _label.group(0) if _label else "other"
_label = _label.group(0)
else:
_label = "other"
if _label not in _datasets[_datastore]: if _label not in _datasets[_datastore]:
_datasets[_datastore][_label] = [] _datasets[_datastore][_label] = []
_datasets[_datastore][_label].append((_snapshot, int(_creation))) _datasets[_datastore][_label].append((_snapshot, int(_creation)))
# Ergebnisse anzeigen
for _datastore in _datasets.keys(): for _datastore in _datasets.keys():
print(_datastore) print(_datastore)
print("-" * 40) print("-" * 40)