From eca161b33a505aa6a7c6a3a4a377ece3aed4fbb4 Mon Sep 17 00:00:00 2001 From: Holger Frey Date: Wed, 7 Aug 2019 16:28:40 +0200 Subject: [PATCH] updated snapshot name extraction --- zfs-snapshot-backup.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/zfs-snapshot-backup.py b/zfs-snapshot-backup.py index c1bd014..2fc6319 100755 --- a/zfs-snapshot-backup.py +++ b/zfs-snapshot-backup.py @@ -68,10 +68,19 @@ def gzip_filename(current, last=None): def extract_snapshot_name(filename): - parts = filename.split(".") - if len(parts) in (2, 4): - # snapshot1.gz or snapshot1.to.snapshot2.gz - return parts[-2] + # elabfs-LukasMetzler@auto-20190807.0200-1w.gz + if not filename.endswith(".gz"): + raise ValueError(f"Not a gzip file: {filename}") + if not filename.startswith(ZFS_ELAB_PREFIX): + raise ValueError(f"Not an elabfs snapshot: {filename}") + snapshot = filename[:-3] + if snapshot.count(".") == 1 and snapshot.count("@") == 1: + # elabfs-...@auto-20190807.0200-1w + return snapshot + elif snapshot.count(".to.") == 1 and snapshot.count("@") == 2: + # elabfs-...@auto-20190806.0200-1w.to.elabfs-...@auto-20190807.0200-1w + old_snapshot, new_snapshot = snapshot.split(".to.") + return new_snapshot else: raise ValueError(f"Unknown Filename Format: {filename}")