backup: fix repository not being unmounted

This mounts the backup in a detached mount namespace, the mountpoint is
automatically unmounted when the process exits.
This commit is contained in:
Michele Guerini Rocco 2024-08-26 13:16:47 +02:00
parent a0832392b9
commit 0c37b52033
Signed by: rnhmjoj
GPG Key ID: BFBAF4C975F76450

View File

@ -56,14 +56,6 @@ with lib;
'';
};
systemd.mounts = lib.singleton
{
description = "backup volume";
what = "/dev/mapper/backup-maxwell";
where = "/mnt/backup";
partOf = [ "backup.service" ];
};
systemd.services.backup =
let
saved = pkgs.writeText "backup-saved" ''
@ -82,25 +74,24 @@ with lib;
in {
description = "system backup";
after = [ "mnt-backup.mount" ];
requires = [ "mnt-backup.mount" ];
startAt = "*-*-* 03:00"; # every day at 3:00
onFailure = [ "notify-failed@backup.service" ];
serviceConfig = {
Type = "oneshot";
PrivateTmp = true;
PrivateMounts = true;
LimitNOFILE = 65536;
};
environment.BUP_DIR = "/mnt/backup";
path = with pkgs; [ bup git nfs-utils sudo gzip postgresql ];
path = with pkgs; [ bup git util-linux sudo gzip postgresql ];
script = ''
# mount repository
mkdir -p "$BUP_DIR"
mount -m -L backup "$BUP_DIR"
# init backup
# init backup, if empty
! test -e $BUP_DIR/bupindex && bup init
# build indices and save