set -eux
${pkgs.xterm}/bin/xterm -fg white -bg black -fa Monospace -fs 6 \
-title "ZFS backup to: $DESTPOOL" -e "journalctl -f -o short \
- -u zfs-force-import@$DESTPOOL \
+ -u zfs-import@$DESTPOOL \
-u zfs-local-backup-home@$DESTPOOL"
'' + " %I";
};
};
- # Force zpool import, even if the disk has not been exported, or has been imported on another computer
- systemd.services."zfs-force-import@" = {
- description = "ZFS force import: %I";
- unitConfig = {
- StartLimitBurst = 5;
- StartLimitInterval = 200;
- StopWhenUnneeded = true;
- };
- wants = [ "zfs-term@%i.service" ];
- bindsTo = [ "sys-subsystem-usb-%i.device" ];
- path = lib.mkBefore [ "/run/booted-system/sw" ];
- serviceConfig = {
- Type = "oneshot";
- RemainAfterExit = true;
- PrivateTmp = true;
- SyslogIdentifier = "zfs-force-import@%i";
- Restart = "on-failure";
- ExecStart = pkgs.writeShellScript "zfs-force-import" ''
- DESTPOOL=$1
- set -eux
- # Import the zpool, using stable paths
- zpool import -d /dev/disk/by-id/ || true
- zpool import -lFd /dev/disk/by-id/ "$DESTPOOL" ||
- zpool reopen "$DESTPOOL" ||
- zpool import -f -d /dev/disk/by-id/ "$DESTPOOL" ||
- zpool clear -nFX "$DESTPOOL"
- '' + " %I";
- };
- };
# Prune old snapshots on the backup and send new ones
systemd.services."zfs-local-backup-home@" = {
description = "ZFS backup home, on: %I";
wants = [ "zfs-term@%i.service" ];
- after = [ "zfs-force-import@%i.service" ];
- requires = [ "zfs-force-import@%i.service" ];
- bindsTo = [ "sys-subsystem-usb-%i.device" ];
+ after = [ "zfs-import@%i.service" ];
+ requires = [ "zfs-import@%i.service" ];
path = lib.mkBefore [ "/run/booted-system/sw" ];
serviceConfig = rec {
Type = "oneshot";