commit 00a6a27b9266a2ab74ba42d2ce8c1d4f1df642c0 (tree)
parent 6bdaca409595626f18e3bdc045b81e2443229adb
Author: Motiejus Jakštys <motiejus@jakstys.lt>
Date: Wed, 13 Sep 2023 08:37:10 +0300
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.
Diffstat:
1 file changed, 23 insertions(+), 14 deletions(-)
diff --git a/modules/base/zfsborg/default.nix b/modules/base/zfsborg/default.nix
@@ -45,20 +45,30 @@ in {
config = with config.mj.base.zfsborg;
lib.mkIf enable {
- systemd.services."zfsborg-snapshot-dirs" = {
- description = "zfsborg prepare snapshot directories";
- wantedBy = ["multi-user.target"];
- serviceConfig = {
- Type = "oneshot";
- ExecStart = let
- mountpoints = lib.unique (lib.catAttrs "mountpoint" dirs);
- in
- builtins.map
- (d: "${pkgs.coreutils}/bin/mkdir -p ${d}/.snapshot-latest")
- mountpoints;
- RemainAfterExit = true;
+ 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";
+ wantedBy = ["multi-user.target"];
+ serviceConfig = {
+ Type = "oneshot";
+ ExecStart = let
+ mountpoints = lib.unique (lib.catAttrs "mountpoint" dirs);
+ in
+ builtins.map
+ (d: "${pkgs.coreutils}/bin/mkdir -p ${d}/.snapshot-latest")
+ mountpoints;
+ RemainAfterExit = true;
+ };
+ };
};
- };
services.borgbackup.jobs = builtins.listToAttrs (
lib.imap0 (
@@ -83,7 +93,6 @@ in {
extraArgs = "--remote-path=borg1";
compression = "auto,lzma";
startAt = attrs.backup_at;
- readWritePaths = let p = mountpoint + "/.snapshot-latest"; in [p];
preHook = mountLatest mountpoint fs.device;
postHook = umountLatest mountpoint;
prune.keep = {