nixos/borgbackup: Add option dumpCommandProducesTar

Add an option `service.borgbackup.jobs.<name>.dumpCommandProducesTar`
that allows using `borg import-tar` rather than `borg create` to import
an archive.
This commit is contained in:
Artem Sheremet
2025-10-29 19:37:42 +00:00
parent ddf56acbeb
commit 4818537fe5
2 changed files with 75 additions and 14 deletions

View File

@@ -9,6 +9,7 @@ let
keepFile = "important_file";
keepFileData = "important_data";
localRepo = "/root/back:up";
localTarRepo = "/root/backup-tar";
# a repository on a file system which is not mounted automatically
localRepoMount = "/noAutoMount";
archiveName = "my_archive";
@@ -47,7 +48,7 @@ in
nodes = {
client =
{ ... }:
{ lib, pkgs, ... }:
{
virtualisation.fileSystems.${localRepoMount} = {
device = "tmpfs";
@@ -93,6 +94,20 @@ in
startAt = [ ];
};
localTar = {
dumpCommand = pkgs.writeScript "createTarArchive" ''
${lib.getExe pkgs.gnutar} cf - ${dataDir}
'';
dumpCommandProducesTar = true;
repo = localTarRepo;
# Make sure in import-tar mode encryption flags are still respected.
encryption = {
mode = "repokey";
inherit passphrase;
};
startAt = [ ]; # Do not run automatically
};
remote = {
paths = dataDir;
repo = remoteRepo;
@@ -231,6 +246,19 @@ in
# Make sure disabling wrapper works
client.fail("command -v borg-job-localMount")
with subtest("localTar"):
borg = "BORG_PASSPHRASE='${passphrase}' borg"
client.systemctl("start --wait borgbackup-job-localTar")
client.fail("systemctl is-failed borgbackup-job-localTar")
archiveName, = client.succeed("{} list --format '{{archive}}{{NL}}' '${localTarRepo}'".format(borg)).strip().split("\n")
# Since excludes are not supported by import-tar, we expect to find exclude file, too
client.succeed(
"{} list '${localTarRepo}::{}' | grep -qF '${excludeFile}'".format(borg, archiveName)
)
# Make sure keepFile has the correct content
client.succeed("{} extract '${localTarRepo}::{}'".format(borg, archiveName))
assert "${keepFileData}" in client.succeed("cat ${dataDir}/${keepFile}")
with subtest("remote"):
borg = "BORG_RSH='ssh -oStrictHostKeyChecking=no -i /root/id_ed25519' borg"
server.wait_for_unit("sshd.service")