ignore "snaphost already exists"-errors when creating snapshots

This commit is contained in:
Fredrik Eriksson 2020-12-20 08:13:09 +01:00
parent 3cbeaa887f
commit 89a19edd6d
Signed by: feffe
GPG Key ID: F4329687B0FA7F8D

View File

@ -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