check-snapshot-age aktualisiert
This commit is contained in:
+30
-7
@@ -16,35 +16,58 @@ args = parser.parse_args()
|
|||||||
# Snapshots abrufen
|
# Snapshots abrufen
|
||||||
_snapshots = subprocess.check_output([zfs, "list", "-t", "snapshot", "-Hpo", "name,creation"])
|
_snapshots = subprocess.check_output([zfs, "list", "-t", "snapshot", "-Hpo", "name,creation"])
|
||||||
|
|
||||||
LABELS = ("frequent", "hourly", "daily", "weekly", "monthly", "yearly", "backup-zfs", "bashclub-zfs")
|
|
||||||
RE_LABELSEARCH = re.compile("|".join(LABELS))
|
|
||||||
_datasets = {}
|
_datasets = {}
|
||||||
|
|
||||||
# Snapshots parsen
|
# Snapshots parsen
|
||||||
for _datastore, _snapshot, _creation in re.findall(r"^([\w_./-]+)@([\w_.-]+)\t(\d+)", _snapshots.decode('utf-8'), re.M):
|
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):
|
if args.filter and not re.search(args.filter, _datastore):
|
||||||
continue # Dataset entspricht nicht dem Filter
|
continue
|
||||||
|
|
||||||
if _datastore not in _datasets:
|
if _datastore not in _datasets:
|
||||||
_datasets[_datastore] = {}
|
_datasets[_datastore] = {}
|
||||||
_label = RE_LABELSEARCH.search(_snapshot)
|
|
||||||
_label = _label.group(0) if _label else "other"
|
# -------------------------------------------------
|
||||||
|
# Snapshot-Typ automatisch erkennen
|
||||||
|
# -------------------------------------------------
|
||||||
|
if _snapshot.startswith("zfs-auto-snap_"):
|
||||||
|
m = re.match(r"zfs-auto-snap_([^-\s]+)-", _snapshot)
|
||||||
|
_label = m.group(1) if m else "zfs-auto-snap"
|
||||||
|
|
||||||
|
elif re.match(r"^[^_]+_\d{4}-\d{2}-\d{2}", _snapshot):
|
||||||
|
# Beispiel: bashclub-zfs_2025-09-05_06:25:24
|
||||||
|
_label = _snapshot.split("_")[0]
|
||||||
|
|
||||||
|
else:
|
||||||
|
# Fallback → alles vor erstem Datum abschneiden
|
||||||
|
_label = re.sub(r'[-_]\d{4}-\d{2}-\d{2}.*$', '', _snapshot)
|
||||||
|
|
||||||
|
# -------------------------------------------------
|
||||||
|
|
||||||
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
|
# Ergebnisse anzeigen
|
||||||
for _datastore in _datasets:
|
for _datastore in _datasets:
|
||||||
print(_datastore)
|
print(_datastore)
|
||||||
print("-" * 40)
|
print("-" * 40)
|
||||||
for _label in _datasets[_datastore]:
|
|
||||||
|
for _label in sorted(_datasets[_datastore]):
|
||||||
_data = _datasets[_datastore][_label]
|
_data = _datasets[_datastore][_label]
|
||||||
|
_data.sort(key=lambda x: x[1])
|
||||||
|
|
||||||
_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]))
|
||||||
_count = len(_data)
|
_count = len(_data)
|
||||||
|
|
||||||
print(f" {_label} {_count}")
|
print(f" {_label} {_count}")
|
||||||
print(f" {_first} {_data[0][0]}")
|
print(f" {_first} {_data[0][0]}")
|
||||||
if _count > 1:
|
if _count > 1:
|
||||||
print(f" {_last} {_data[-1][0]}")
|
print(f" {_last} {_data[-1][0]}")
|
||||||
|
|
||||||
print("")
|
print("")
|
||||||
|
|||||||
Reference in New Issue
Block a user