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:
parent
a0832392b9
commit
0c37b52033
17
jobs.nix
17
jobs.nix
@ -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 =
|
systemd.services.backup =
|
||||||
let
|
let
|
||||||
saved = pkgs.writeText "backup-saved" ''
|
saved = pkgs.writeText "backup-saved" ''
|
||||||
@ -82,25 +74,24 @@ with lib;
|
|||||||
|
|
||||||
in {
|
in {
|
||||||
description = "system backup";
|
description = "system backup";
|
||||||
after = [ "mnt-backup.mount" ];
|
|
||||||
requires = [ "mnt-backup.mount" ];
|
|
||||||
startAt = "*-*-* 03:00"; # every day at 3:00
|
startAt = "*-*-* 03:00"; # every day at 3:00
|
||||||
onFailure = [ "notify-failed@backup.service" ];
|
onFailure = [ "notify-failed@backup.service" ];
|
||||||
|
|
||||||
serviceConfig = {
|
serviceConfig = {
|
||||||
Type = "oneshot";
|
Type = "oneshot";
|
||||||
PrivateTmp = true;
|
PrivateTmp = true;
|
||||||
|
PrivateMounts = true;
|
||||||
LimitNOFILE = 65536;
|
LimitNOFILE = 65536;
|
||||||
};
|
};
|
||||||
|
|
||||||
environment.BUP_DIR = "/mnt/backup";
|
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 = ''
|
script = ''
|
||||||
# mount repository
|
# 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
|
! test -e $BUP_DIR/bupindex && bup init
|
||||||
|
|
||||||
# build indices and save
|
# build indices and save
|
||||||
|
Loading…
Reference in New Issue
Block a user