check-snapshot-age aktualisiert

fix which zfs
This commit is contained in:
2025-07-01 01:41:25 +02:00
parent a09317b44a
commit 6a1b6a27cf
+6 -3
View File
@@ -5,13 +5,16 @@ import re
import time import time
import argparse import argparse
# ZFS-Pfad ermitteln
zfs = subprocess.check_output(["which", "zfs"]).decode().strip()
# Argumente verarbeiten # Argumente verarbeiten
parser = argparse.ArgumentParser(description="ZFS Snapshot Übersicht") 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) parser.add_argument("--filter", help="Nur bestimmte Datasets anzeigen (Regex möglich, z.B. 'rpool/ROOT')", type=str)
args = parser.parse_args() args = parser.parse_args()
# Snapshots abrufen # Snapshots abrufen
_snapshots = subprocess.check_output("/usr/sbin/zfs list -t snapshot -Hpo name,creation".split()) _snapshots = subprocess.check_output([zfs, "list", "-t", "snapshot", "-Hpo", "name,creation"])
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))
@@ -32,10 +35,10 @@ for _datastore, _snapshot, _creation in re.findall(r"^([\w_./-]+)@([\w_.-]+)\t(\
_datasets[_datastore][_label].append((_snapshot, int(_creation))) _datasets[_datastore][_label].append((_snapshot, int(_creation)))
# Ergebnisse anzeigen # Ergebnisse anzeigen
for _datastore in _datasets.keys(): for _datastore in _datasets:
print(_datastore) print(_datastore)
print("-" * 40) print("-" * 40)
for _label in _datasets[_datastore].keys(): for _label in _datasets[_datastore]:
_data = _datasets[_datastore][_label] _data = _datasets[_datastore][_label]
_first = time.strftime("%d.%m.%Y %H:%M:%S", time.localtime(_data[0][1])) _first = time.strftime("%d.%m.%Y %H:%M:%S", time.localtime(_data[0][1]))
_last = time.strftime("%d.%m.%Y %H:%M:%S", time.localtime(_data[-1][1])) _last = time.strftime("%d.%m.%Y %H:%M:%S", time.localtime(_data[-1][1]))