zfsborg: use TemporaryFileSystem for temp snapshots

Otherwise:

Sep 13 00:01:05 vno1-oh2 systemd[1]: Started BorgBackup job -var-lib-1.
Sep 13 00:01:06 vno1-oh2 borgbackup-job--var-lib-1-start[329228]: filesystem 'rpool/nixos/var/lib@autosnap_2023-09-12_21:00:06_hourly' is already mounted
Sep 13 00:01:06 vno1-oh2 borgbackup-job--var-lib-1-start[329209]: umount: /var/lib/.snapshot-latest: not mounted.
Sep 13 00:01:06 vno1-oh2 systemd[1]: borgbackup-job--var-lib-1.service: Main process exited, code=exited, status=32/n/a
Sep 13 00:01:06 vno1-oh2 systemd[1]: borgbackup-job--var-lib-1.service: Failed with result 'exit-code'.
Sep 13 00:01:06 vno1-oh2 systemd[1]: borgbackup-job--var-lib-1.service: Triggering OnFailure= dependencies.
This commit is contained in:
Motiejus Jakštys 2023-09-13 08:37:10 +03:00
parent 6bdaca4095
commit 00a6a27b92

View File

@ -45,7 +45,16 @@ in {
config = with config.mj.base.zfsborg; config = with config.mj.base.zfsborg;
lib.mkIf enable { lib.mkIf enable {
systemd.services."zfsborg-snapshot-dirs" = { systemd.services =
lib.listToAttrs (lib.imap1 (
i: attr:
lib.nameValuePair "borgbackup-job-${lib.strings.sanitizeDerivationName attr.mountpoint}-${toString i}" {
serviceConfig.TemporaryFileSystem = "${attr.mountpoint}/.snapshot-latest";
}
)
dirs)
// {
"zfsborg-snapshot-dirs" = {
description = "zfsborg prepare snapshot directories"; description = "zfsborg prepare snapshot directories";
wantedBy = ["multi-user.target"]; wantedBy = ["multi-user.target"];
serviceConfig = { serviceConfig = {
@ -59,6 +68,7 @@ in {
RemainAfterExit = true; RemainAfterExit = true;
}; };
}; };
};
services.borgbackup.jobs = builtins.listToAttrs ( services.borgbackup.jobs = builtins.listToAttrs (
lib.imap0 ( lib.imap0 (
@ -83,7 +93,6 @@ in {
extraArgs = "--remote-path=borg1"; extraArgs = "--remote-path=borg1";
compression = "auto,lzma"; compression = "auto,lzma";
startAt = attrs.backup_at; startAt = attrs.backup_at;
readWritePaths = let p = mountpoint + "/.snapshot-latest"; in [p];
preHook = mountLatest mountpoint fs.device; preHook = mountLatest mountpoint fs.device;
postHook = umountLatest mountpoint; postHook = umountLatest mountpoint;
prune.keep = { prune.keep = {