localbackup: integrate into regression test
This commit is contained in:
@@ -30,6 +30,7 @@
|
|||||||
{
|
{
|
||||||
imports = [
|
imports = [
|
||||||
self.clanModules.borgbackup
|
self.clanModules.borgbackup
|
||||||
|
self.clanModules.localbackup
|
||||||
self.clanModules.sshd
|
self.clanModules.sshd
|
||||||
];
|
];
|
||||||
clan.networking.targetHost = "machine";
|
clan.networking.targetHost = "machine";
|
||||||
@@ -102,6 +103,26 @@
|
|||||||
};
|
};
|
||||||
clan.borgbackup.destinations.test-backup.repo = "borg@machine:.";
|
clan.borgbackup.destinations.test-backup.repo = "borg@machine:.";
|
||||||
|
|
||||||
|
fileSystems."/mnt/external-disk" = {
|
||||||
|
device = "/dev/vdb"; # created in tests with virtualisation.emptyDisks
|
||||||
|
autoFormat = true;
|
||||||
|
fsType = "ext4";
|
||||||
|
options = [
|
||||||
|
"defaults"
|
||||||
|
"noauto"
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
|
clan.localbackup.targets.hdd = {
|
||||||
|
directory = "/mnt/external-disk";
|
||||||
|
mountHook = ''
|
||||||
|
touch /run/mount-external-disk
|
||||||
|
'';
|
||||||
|
unmountHook = ''
|
||||||
|
touch /run/unmount-external-disk
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
services.borgbackup.repos.test-backups = {
|
services.borgbackup.repos.test-backups = {
|
||||||
path = "/var/lib/borgbackup/test-backups";
|
path = "/var/lib/borgbackup/test-backups";
|
||||||
authorizedKeys = [ (builtins.readFile ../lib/ssh/pubkey) ];
|
authorizedKeys = [ (builtins.readFile ../lib/ssh/pubkey) ];
|
||||||
@@ -114,10 +135,13 @@
|
|||||||
checks = pkgs.lib.mkIf (pkgs.stdenv.isLinux) {
|
checks = pkgs.lib.mkIf (pkgs.stdenv.isLinux) {
|
||||||
test-backups = (import ../lib/test-base.nix) {
|
test-backups = (import ../lib/test-base.nix) {
|
||||||
name = "test-backups";
|
name = "test-backups";
|
||||||
nodes.machine.imports = [
|
nodes.machine = {
|
||||||
self.nixosModules.clanCore
|
imports = [
|
||||||
self.nixosModules.test-backup
|
self.nixosModules.clanCore
|
||||||
];
|
self.nixosModules.test-backup
|
||||||
|
];
|
||||||
|
virtualisation.emptyDiskImages = [ 256 ];
|
||||||
|
};
|
||||||
|
|
||||||
testScript = ''
|
testScript = ''
|
||||||
import json
|
import json
|
||||||
@@ -130,16 +154,27 @@
|
|||||||
# create
|
# create
|
||||||
machine.succeed("clan --debug --flake ${self} backups create test-backup")
|
machine.succeed("clan --debug --flake ${self} backups create test-backup")
|
||||||
machine.wait_until_succeeds("! systemctl is-active borgbackup-job-test-backup >&2")
|
machine.wait_until_succeeds("! systemctl is-active borgbackup-job-test-backup >&2")
|
||||||
|
machine.succeed("test -f /run/mount-external-disk")
|
||||||
|
machine.succeed("test -f /run/unmount-external-disk")
|
||||||
|
|
||||||
# list
|
# list
|
||||||
backup_id = json.loads(machine.succeed("borg-job-test-backup list --json"))["archives"][0]["archive"]
|
backup_id = json.loads(machine.succeed("borg-job-test-backup list --json"))["archives"][0]["archive"]
|
||||||
out = machine.succeed("clan --debug --flake ${self} backups list test-backup").strip()
|
out = machine.succeed("clan --debug --flake ${self} backups list test-backup").strip()
|
||||||
print(out)
|
print(out)
|
||||||
assert backup_id in out, f"backup {backup_id} not found in {out}"
|
assert backup_id in out, f"backup {backup_id} not found in {out}"
|
||||||
|
localbackup_id = "hdd::/mnt/external-disk/snapshot.0"
|
||||||
|
assert localbackup_id in out, "localbackup not found in {out}"
|
||||||
|
|
||||||
# restore
|
## borgbackup restore
|
||||||
machine.succeed("rm -f /var/test-backups/somefile")
|
machine.succeed("rm -f /var/test-backups/somefile")
|
||||||
machine.succeed(f"clan --debug --flake ${self} backups restore test-backup borgbackup {out} >&2")
|
machine.succeed(f"clan --debug --flake ${self} backups restore test-backup borgbackup 'test-backup::borg@machine:.::{backup_id}' >&2")
|
||||||
|
assert machine.succeed("cat /var/test-backups/somefile").strip() == "testing", "restore failed"
|
||||||
|
machine.succeed("test -f /var/test-service/pre-restore-command")
|
||||||
|
machine.succeed("test -f /var/test-service/post-restore-command")
|
||||||
|
|
||||||
|
## localbackup restore
|
||||||
|
machine.succeed("rm -f /var/test-backups/somefile /var/test-service/{pre,post}-restore-command")
|
||||||
|
machine.succeed(f"clan --debug --flake ${self} backups restore test-backup localbackup '{localbackup_id}' >&2")
|
||||||
assert machine.succeed("cat /var/test-backups/somefile").strip() == "testing", "restore failed"
|
assert machine.succeed("cat /var/test-backups/somefile").strip() == "testing", "restore failed"
|
||||||
machine.succeed("test -f /var/test-service/pre-restore-command")
|
machine.succeed("test -f /var/test-service/pre-restore-command")
|
||||||
machine.succeed("test -f /var/test-service/post-restore-command")
|
machine.succeed("test -f /var/test-service/post-restore-command")
|
||||||
|
|||||||
@@ -158,7 +158,7 @@ in
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
name=$(awk -F'::' '{print $1}' <<< $NAME)
|
name=$(awk -F'::' '{print $1}' <<< $NAME)
|
||||||
backupname=''${NAME#$mountpoint::}
|
backupname=''${NAME#$name::}
|
||||||
|
|
||||||
if command -v localbackup-mount-$name; then
|
if command -v localbackup-mount-$name; then
|
||||||
localbackup-mount-$name
|
localbackup-mount-$name
|
||||||
|
|||||||
Reference in New Issue
Block a user