diff --git a/checks/backups/flake-module.nix b/checks/backups/flake-module.nix index 15f5e75cd..dd152b769 100644 --- a/checks/backups/flake-module.nix +++ b/checks/backups/flake-module.nix @@ -30,6 +30,7 @@ { imports = [ self.clanModules.borgbackup + self.clanModules.localbackup self.clanModules.sshd ]; clan.networking.targetHost = "machine"; @@ -102,6 +103,26 @@ }; 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 = { path = "/var/lib/borgbackup/test-backups"; authorizedKeys = [ (builtins.readFile ../lib/ssh/pubkey) ]; @@ -114,10 +135,13 @@ checks = pkgs.lib.mkIf (pkgs.stdenv.isLinux) { test-backups = (import ../lib/test-base.nix) { name = "test-backups"; - nodes.machine.imports = [ - self.nixosModules.clanCore - self.nixosModules.test-backup - ]; + nodes.machine = { + imports = [ + self.nixosModules.clanCore + self.nixosModules.test-backup + ]; + virtualisation.emptyDiskImages = [ 256 ]; + }; testScript = '' import json @@ -130,16 +154,27 @@ # create machine.succeed("clan --debug --flake ${self} backups create test-backup") 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 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() print(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(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" machine.succeed("test -f /var/test-service/pre-restore-command") machine.succeed("test -f /var/test-service/post-restore-command") diff --git a/clanModules/localbackup.nix b/clanModules/localbackup.nix index c7c55fc18..abb5db7c2 100644 --- a/clanModules/localbackup.nix +++ b/clanModules/localbackup.nix @@ -158,7 +158,7 @@ in ] } name=$(awk -F'::' '{print $1}' <<< $NAME) - backupname=''${NAME#$mountpoint::} + backupname=''${NAME#$name::} if command -v localbackup-mount-$name; then localbackup-mount-$name