From 7494e1c5ea4cc8f1e59314bb34509b0f1300f4bc Mon Sep 17 00:00:00 2001 From: Rui Pinheiro Date: Sat, 23 Mar 2024 18:09:10 +0000 Subject: [PATCH] Do not snapshot child filesystem if it has a more specific config --- pyznap/take.py | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/pyznap/take.py b/pyznap/take.py index 4ac1a5f..8efe03e 100644 --- a/pyznap/take.py +++ b/pyznap/take.py @@ -127,11 +127,14 @@ def take_config(config): logger = logging.getLogger(__name__) logger.info('Taking snapshots...') + config_d = {} for conf in config: + config_d[conf['name']] = conf + + for name,conf in config_d.items(): if not conf.get('snap', None): continue - name = conf['name'] try: _type, fsname, user, host, port = parse_name(name) except ValueError as err: @@ -164,9 +167,21 @@ def take_config(config): else: # Take recursive snapshot of parent filesystem take_filesystem(children[0], conf) - # Take snapshot of all children that don't have all snapshots yet + + # Take snapshot of all children that do not have a more specific config for child in children[1:]: - take_filesystem(child, conf) + skip = False + if child.name in config_d: + skip = True + else: + for other_name in config_d.keys(): + if other_name.startswith(name + '/') and child.name.startswith(other_name + '/'): + skip = True + print(name, other_name) + break + + if not skip: + take_filesystem(child, conf) finally: if ssh: ssh.close()