Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions pyznap/take.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -164,9 +167,20 @@ 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
break

if not skip:
take_filesystem(child, conf)
finally:
if ssh:
ssh.close()
7 changes: 5 additions & 2 deletions pyznap/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
import os
import re
import logging
import pathlib
from subprocess import Popen, PIPE, TimeoutExpired, CalledProcessError
from .process import run
from .ssh import SSHException

from datetime import datetime
from configparser import (ConfigParser, NoOptionError, MissingSectionHeaderError,
DuplicateSectionError, DuplicateOptionError)
from pkg_resources import resource_string


def exists(executable='', ssh=None):
Expand Down Expand Up @@ -171,7 +171,10 @@ def create_config(path):
logger = logging.getLogger(__name__)

CONFIG_FILE = os.path.join(path, 'pyznap.conf')
config = resource_string(__name__, 'config/pyznap.conf').decode("utf-8")

config_path = (pathlib.Path(__file__).parent.resolve() / 'config' / 'pyznap.conf').absolute()
with open(config_path, 'r') as file:
config = file.read()

logger.info('Initial setup...')

Expand Down