From 89a19edd6d92c771032cfdeb3fc3ddf1237c7cff Mon Sep 17 00:00:00 2001 From: Fredrik Eriksson Date: Sun, 20 Dec 2020 08:13:09 +0100 Subject: [PATCH] ignore "snaphost already exists"-errors when creating snapshots --- zsnaplib/__init__.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/zsnaplib/__init__.py b/zsnaplib/__init__.py index 37a072e..fb3952b 100644 --- a/zsnaplib/__init__.py +++ b/zsnaplib/__init__.py @@ -6,6 +6,7 @@ import sys time_format='%Y-%m-%d_%H%M' re_snapshot = re.compile(r'^(.*)@([0-9]{4}-[0-9]{2}-[0-9]{2}_[0-9]{4})$') +re_err_ok = re.compile(r"cannot create snapshot '[^']+': dataset already exists") logger = 'zsnapper' class ZFSSnapshotError(Exception): @@ -33,7 +34,12 @@ def do_zfs_command(args, zfs_cmd, pipecmd=None): (out, err) = ctrl_proc.communicate() - if ctrl_proc.returncode != 0: + # check if we try to create a snapshot that already exists. This can happen + # if the script is run every minute and it takes more time than that to + # create all snapshots + if ctrl_proc.returncode == 1 && re_match(re_err_ok, err): + pass + elif ctrl_proc.returncode != 0: raise ZFSSnapshotError('Failed to execute {}: {}'.format(cmd, err)) return out