コード例 #1
0
ファイル: test_BorgTask.py プロジェクト: Oprax/backup-utils
def test_BorgTask(mock_which, mock_run, my_cfg):
    from backup_utils.tasks.BorgTask import BorgTask
    from backup_utils.utils import render

    test_env = environ.copy()
    test_env["BORG_PASSPHRASE"] = my_cfg.get("backup", {}).get("pswd", "")
    test_env["BORG_REPO"] = my_cfg.get("repo")

    t = BorgTask(repo=my_cfg.get("repo"), **my_cfg.get("backup"))
    t.start()
    mock_run.assert_any_call(
        [
            "borg",
            "create",
            "-v",
            "--stats",
            "--compression",
            my_cfg.get("backup", {}).get("compression", ""),
            "--exclude-caches",
            render("::{hostname}-{date}"),
        ],
        check=True,
        env=ANY,
        stderr=PIPE,
        stdout=PIPE,
    )
    prune_args = ["borg", "prune", "-v", "::"]
    prune_args.extend("-d 7 -w 4 -m 3 -y 1".split(" "))
    mock_run.assert_any_call(prune_args, check=True, env=ANY, stderr=PIPE, stdout=PIPE)
コード例 #2
0
def test_render():
    from backup_utils.utils import render

    res = subprocess.run(r"date +%Y-%m-%d".split(" "), stdout=subprocess.PIPE)
    today = res.stdout.decode("utf-8").strip()
    res = subprocess.run(["hostname"], stdout=subprocess.PIPE)
    hostname = res.stdout.decode("utf-8").strip()
    template = "machine-{hostname}-{date}"
    assert render(template) == template.format(hostname=hostname, date=today)
コード例 #3
0
ファイル: test_RcloneSync.py プロジェクト: Oprax/backup-utils
def test_RcloneSync(mock_which, mock_run, my_cfg):
    from backup_utils.syncs.RcloneSync import RcloneSync
    from backup_utils.utils import render

    t = RcloneSync(repo=my_cfg.get("repo"), **my_cfg.get("sync"))
    t.start()
    mock_run.assert_called_once_with(
        ["rclone", "-v", "sync", my_cfg.get("repo"), render("s3:backup/{hostname}")],
        check=True,
        env=None,
        stderr=PIPE,
        stdout=PIPE,
    )
コード例 #4
0
def test_TarTask(mock_which, mock_run, my_cfg):
    from backup_utils.tasks.TarTask import TarTask
    from backup_utils.utils import render

    t = TarTask(repo=my_cfg.get("repo"), **my_cfg.get("backup"))
    t.start()
    mock_run.assert_any_call(
        [
            "tar",
            "-c",
            "-J",
            "-f",
            str(Path(my_cfg.get("repo")) / render("{hostname}.tar.xz")),
        ],
        check=True,
        env=None,
        stderr=PIPE,
        stdout=PIPE,
    )
コード例 #5
0
def test_RsyncSync(mock_which, mock_run, my_cfg):
    from backup_utils.syncs.RsyncSync import RsyncSync
    from backup_utils.utils import render

    t = RsyncSync(repo=my_cfg.get("repo"), **my_cfg.get("sync"))
    t.start()
    mock_run.assert_called_once_with(
        [
            "rsync",
            "-a",
            "--delete",
            "--exclude=test",
            "-e",
            "ssh -p 4242",
            my_cfg.get("repo"),
            render("[email protected]:~/{hostname}"),
        ],
        check=True,
        env=None,
        stderr=PIPE,
        stdout=PIPE,
    )