def test_restore(self): target_dir = self.tmpdir / 'restore_target' profile = self.define_profile( 1, 'pr', { 'repo': self.repo1, 'filedir': PATHS[1], 'exclude': 'patterna\n**.tmp\n/cache', 'password-file': 'secret password', 'target': target_dir, }) self.run_init(profile) self.run_test(profile, ['backup'], [( 'RUN restic backup ' \ '--password-file={} --repo={} ' \ '--exclude=patterna --exclude=**.tmp --exclude=/cache {}'.format( profile / 'password-file', self.repo1, PATHS[1]), 0, {}), ]) self.run_test(profile, ['restore', 'latest'], [( 'RUN restic restore ' \ '--password-file={} --repo={} ' \ '--exclude=patterna --exclude=**.tmp --exclude=/cache --target={} latest'.format( profile / 'password-file', self.repo1, target_dir, ), 0, {}), ]) self.compare_directories( PATHS[1], target_dir / PyPath(str(self.tmpdir)[1:]) / 'user')
def test_cpal(self): # 1. normal, mit rmcpal # 2. repo=sftp.... profile = self.define_profile( 1, 'pr', { 'repo': self.repo1, 'filedir': PATHS[1], 'password-file': 'secret password', }) self.run_init(profile) self.run_test(profile, ['backup'], [( 'RUN restic backup ' \ '--password-file={} --repo={} {}'.format( profile / 'password-file', self.repo1, PATHS[1]), 0, {}), ]) cp_path = PyPath(str(self.repo1) + '.restaround_cpal') self.run_test(profile, ['cpal'], [ ('RUN cp -al {} {}'.format(self.repo1, str(cp_path)), 0, {}), ]) assert cp_path.exists() self.compare_directories(self.repo1, cp_path) self.run_test(profile, ['rmcpal'], [ ('RUN rm -r {}'.format(str(cp_path)), 0, {}), ]) assert not cp_path.exists()
def setup_method(self): self.tmpdir = PyPath(tempfile.mkdtemp()) global PATHS # pylint: disable=global-statement Main.init_globals() PATHS = (self.tmpdir / 'etc', self.tmpdir / 'user') self.profiles = {} self.test_env = os.environ.copy() self.repo1 = self.tmpdir / 'repösitory 1 €=EUR'
def check_same_fs(self, profile): repo = PyPath(str(self.repo(profile))) repo_parent = self.repo_parent(profile) repo_dev = repo.stat().st_dev repo_parent_dev = repo_parent.stat().st_dev if repo_parent_dev != repo_dev: logging.error('%s: %s is a mount point, this is not supported', Main.command, repo) return 2 return 0
def add_values(self, entry): super().add_values(entry) self.values = [ PyPath(x) if not isinstance(x, PyPath) else x for x in self.values ]
def repo_parent(self, profile): return PyPath( os.path.normpath(os.path.join(str(self.repo(profile)), '..')))
import tempfile import filecmp try: import argcomplete # pylint: disable=unused-import except ImportError: pass VERSION = "0.1.3" # PATHS defines directories for looking up profile definitions. # This is without the 'restaround' part. # If a profile is found in more than one path, apply them in the order found. PATHS = (PyPath('/etc'), PyPath.home() / '.config') class Test_restaround: profiles = [] tmpdir = None test_env = None repo1 = None def setup_method(self): self.tmpdir = PyPath(tempfile.mkdtemp()) global PATHS # pylint: disable=global-statement Main.init_globals() PATHS = (self.tmpdir / 'etc', self.tmpdir / 'user') self.profiles = {}
def temp_dir() -> Generator[PyPath, None, None]: with FileUtil() as fu: childdir = PyPath(fu.make_dir(str(uuid.uuid4()))).resolve() yield childdir
def validate(self, obj, value): try: return PyPath(value) except: self.error(obj, value)