def backup(self): config = Config() destination = self.backup_destination_path() commands.run(["mkdir", "-p", f"{destination}"]) commands.run(self.dump_command()) return restic.backup_files(config.repository, f"{destination}", tags=self.tags)
def check(repository: str): return commands.run(restic( repository, [ "check", # "--with-cache", ]))
def is_initialized(repository: str) -> bool: """ Checks if a repository is initialized using snapshots command. Note that this cannot separate between uninitalized repo and other errors, but this method is reccomended by the restic community. """ return commands.run(restic(repository, ["snapshots", '--last'])) == 0
def init_repo(repository: str): """ Attempt to initialize the repository. Doing this after the repository is initialized """ return commands.run(restic(repository, [ "init", ]))
def rcon_cli(host, port, cmd: str) -> int: exit_code = commands.run( ["rcon-cli", f"--host={host}", f"--port={port}", cmd]) if exit_code != 0: raise RconException( f"rcon-cli {cmd} exited with a non-zero exit code: {exit_code}") return exit_code
def backup_files(repository: str, source='/volumes', tags=''): args = ["--verbose", "backup", source] excludes_file = os.path.join(source, "excludes.txt") if os.path.isfile(excludes_file): args.extend(['--exclude-file', excludes_file]) args.extend(utils.format_tags(tags)) return commands.run(restic(repository, args))
def forget(repository: str, daily: str, weekly: str, monthly: str, yearly: str): return commands.run( restic(repository, [ 'forget', '--group-by', 'paths', '--keep-daily', daily, '--keep-weekly', weekly, '--keep-monthly', monthly, '--keep-yearly', yearly, ]))
def forget(repository: str, keeplast: str, hourly: str, daily: str, weekly: str, monthly: str, yearly: str, keep_tags='', filter_tags=''): args = [ 'forget', '--group-by', 'paths,tags', '--keep-last', keeplast, '--keep-hourly', hourly, '--keep-daily', daily, '--keep-weekly', weekly, '--keep-monthly', monthly, '--keep-yearly', yearly ] args.extend(utils.format_tags(keep_tags, '--keep-tag')) args.extend(utils.format_tags(filter_tags)) return commands.run(restic(repository, args))
def prune(repository: str): return commands.run(restic(repository, [ 'prune', ]))
def backup_files(repository: str, source='/volumes'): return commands.run(restic(repository, [ "--verbose", "backup", source, ]))