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)
Esempio n. 2
0
def check(repository: str):
    return commands.run(restic(
        repository,
        [
            "check",
            # "--with-cache",
        ]))
Esempio n. 3
0
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
Esempio n. 4
0
def init_repo(repository: str):
    """
    Attempt to initialize the repository.
    Doing this after the repository is initialized
    """
    return commands.run(restic(repository, [
        "init",
    ]))
Esempio n. 5
0
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
Esempio n. 6
0
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))
Esempio n. 7
0
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,
        ]))
Esempio n. 8
0
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))
Esempio n. 9
0
def prune(repository: str):
    return commands.run(restic(repository, [
        'prune',
    ]))
Esempio n. 10
0
def backup_files(repository: str, source='/volumes'):
    return commands.run(restic(repository, [
        "--verbose",
        "backup",
        source,
    ]))