fix backup restic test

This commit is contained in:
ibizaman 2024-11-10 16:58:07 +01:00 committed by Pierre Penninckx
parent fb60451820
commit 8e0a75c82c

View file

@ -32,19 +32,12 @@ let
}; };
shb.restic.instances."testinstance" = { shb.restic.instances."testinstance" = {
enable = true; settings = {
enable = true;
passphraseFile = toString (pkgs.writeText "passphrase" "PassPhrase"); passphraseFile = toString (pkgs.writeText "passphrase" "PassPhrase");
sourceDirectories = [ repository = {
"/opt/files/A"
"/opt/files/B"
];
user = user;
repositories = [
{
path = "/opt/repos/A"; path = "/opt/repos/A";
timerConfig = { timerConfig = {
OnCalendar = "00:00:00"; OnCalendar = "00:00:00";
@ -56,39 +49,45 @@ let
A.source = config.shb.hardcodedsecret.A.path; A.source = config.shb.hardcodedsecret.A.path;
B.source = config.shb.hardcodedsecret.B.path; B.source = config.shb.hardcodedsecret.B.path;
}; };
} };
{ };
path = "/opt/repos/B";
timerConfig = {
OnCalendar = "00:00:00";
RandomizedDelaySec = "5h";
};
}
];
hooks.before_backup = ['' request = {
echo $RUNTIME_DIRECTORY inherit user;
if [ "$RUNTIME_DIRECTORY" = /run/restic-backups-testinstance_opt_repos_A ]; then
if ! [ -f /run/secrets_restic/restic-backups-testinstance_opt_repos_A ]; then sourceDirectories = [
exit 10 "/opt/files/A"
"/opt/files/B"
];
hooks.before_backup = [''
echo $RUNTIME_DIRECTORY
if [ "$RUNTIME_DIRECTORY" = /run/restic-backups-testinstance_opt_repos_A ]; then
if ! [ -f /run/secrets_restic/restic-backups-testinstance_opt_repos_A ]; then
exit 10
fi
if [ -z "$A" ] || ! [ "$A" = "secretA" ]; then
echo "A:$A"
exit 11
fi
if [ -z "$B" ] || ! [ "$B" = "secretB" ]; then
echo "B:$B"
exit 12
fi
fi fi
if [ -z "$A" ] || ! [ "$A" = "secretA" ]; then ''];
echo "A:$A" };
exit 11
fi
if [ -z "$B" ] || ! [ "$B" = "secretB" ]; then
echo "B:$B"
exit 12
fi
fi
''];
}; };
}; };
extraPythonPackages = p: [ p.dictdiffer ]; extraPythonPackages = p: [ p.dictdiffer ];
skipTypeCheck = true; skipTypeCheck = true;
testScript = '' testScript = { nodes, ... }: let
provider = nodes.machine.shb.restic.instances."testinstance";
backupService = provider.result.backupService;
restoreScript = provider.result.restoreScript;
in ''
from dictdiffer import diff from dictdiffer import diff
def list_files(dir): def list_files(dir):
@ -133,7 +132,7 @@ let
}) })
with subtest("First backup in repo A"): with subtest("First backup in repo A"):
machine.succeed("systemctl start restic-backups-testinstance_opt_repos_A") machine.succeed("systemctl start ${backupService}")
with subtest("New content"): with subtest("New content"):
machine.succeed(""" machine.succeed("""
@ -150,9 +149,6 @@ let
'/opt/files/A/fileB': 'repoA_fileB_2', '/opt/files/A/fileB': 'repoA_fileB_2',
}) })
with subtest("Second backup in repo B"):
machine.succeed("systemctl start restic-backups-testinstance_opt_repos_B")
with subtest("Delete content"): with subtest("Delete content"):
machine.succeed(""" machine.succeed("""
rm -r /opt/files/A /opt/files/B rm -r /opt/files/A /opt/files/B
@ -162,7 +158,7 @@ let
with subtest("Restore initial content from repo A"): with subtest("Restore initial content from repo A"):
machine.succeed(""" machine.succeed("""
restic-testinstance_opt_repos_A restore latest -t / ${restoreScript} restore latest
""") """)
assert_files("/opt/files", { assert_files("/opt/files", {
@ -171,18 +167,6 @@ let
'/opt/files/A/fileA': 'repoA_fileA_1', '/opt/files/A/fileA': 'repoA_fileA_1',
'/opt/files/A/fileB': 'repoA_fileB_1', '/opt/files/A/fileB': 'repoA_fileB_1',
}) })
with subtest("Restore initial content from repo B"):
machine.succeed("""
restic-testinstance_opt_repos_B restore latest -t /
""")
assert_files("/opt/files", {
'/opt/files/B/fileA': 'repoB_fileA_2',
'/opt/files/B/fileB': 'repoB_fileB_2',
'/opt/files/A/fileA': 'repoA_fileA_2',
'/opt/files/A/fileB': 'repoA_fileB_2',
})
''; '';
}; };