pumpkin: sanoid: use recursive=zfs
authorJulien Moutinho <julm+julm-nix@sourcephile.fr>
Fri, 10 Jan 2025 01:25:42 +0000 (02:25 +0100)
committerJulien Moutinho <julm+julm-nix@sourcephile.fr>
Fri, 10 Jan 2025 01:25:42 +0000 (02:25 +0100)
hosts/pumpkin/backup.nix

index f26ef38c815d949b6d7e221c115d66beb6f97bb1..fbcc7937c8c9b254baee047dea9851100149b39a 100644 (file)
@@ -1,30 +1,20 @@
 { pkgs, lib, hostName, ... }:
 with builtins;
 {
-  # syncoid --create-bookmark --no-privilege-elevation --no-sync-snap --recvoptions '' --sendoptions raw --recursive oignon/home off2/julm/backup/oignon/home
-  # zfs list -t snapshot -o name | grep ^oignon/home | while read -r snap; do zfs bookmark "$snap" "${snap//@/#}"; done
   # Take regular snapshots, and prune old ones
   services.sanoid = {
     enable = true;
     extraArgs = [ "--verbose" ];
     datasets = {
-      "${hostName}/root/home" = {
+      "${hostName}/root" = {
         autosnap = true;
         autoprune = true;
+        frequently = 0;
         hourly = 12;
-        daily = 3;
-        monthly = 0;
-        yearly = 0;
-        recursive = true;
-      };
-      "${hostName}/root/var" = {
-        autosnap = true;
-        autoprune = true;
-        hourly = 12;
-        daily = 1;
+        daily = 7;
         monthly = 0;
         yearly = 0;
-        recursive = true;
+        recursive = "zfs";
       };
       "off2/julm/backup/oignon" = {
         autosnap = false;
@@ -33,10 +23,32 @@ with builtins;
         daily = 7;
         monthly = 3;
         yearly = 0;
-        recursive = true;
+        recursive = "zfs";
       };
     };
   };
+  programs.bash.interactiveShellInit = ''
+    backup-pumpkin () {
+      sudo syncoid --sshkey ~julm/.ssh/id_ed25519 \
+        --create-bookmark --no-sync-snap --no-privilege-elevation \
+        --sendoptions=Rw --recvoptions=u \
+        --exclude pumpkin/root/nix \
+        pumpkin/root \
+        aubergine.sp:off2/julm/backup/pumpkin
+    }
+    mount-zfs-backup () {
+      (
+      set -eux
+      zpool="$1"
+      zpool status "$zpool" 2>/dev/null ||
+      sudo zpool import -d /dev/disk/by-id/ "$zpool"
+      trap "sudo zpool export $zpool" EXIT
+      zfs list -rH -t filesystem -o mounted,mountpoint,name "$zpool"/"$USER"/backup |
+      grep "^no\\s*/" | cut -f 3 | xargs -ortL1 sudo zfs mount -Olv || true
+      ${pkgs.mate.caja-with-extensions}/bin/caja --browser /mnt/"$zpool"/"$USER"/backup
+      )
+    }
+  '';
   # Trigger backups when disks are plugged
   services.udev.extraRules = ''
     ACTION=="add",    SUBSYSTEM=="block", KERNEL=="sd*", ENV{ID_SERIAL}=="WDC_WD10JPVT-22A1YT0_WD-WX21AC2F3987", ENV{SYSTEMD_WANTS}+="zfs-local-backup-home@WD10JPVT.service", ENV{SYSTEMD_ALIAS}="/sys/subsystem/usb/WD10JPVT"
@@ -180,20 +192,6 @@ with builtins;
       '' + " %I";
     };
   };
-  programs.bash.interactiveShellInit = ''
-    mount-zfs-backup () {
-      (
-      set -eux
-      zpool="$1"
-      zpool status "$zpool" 2>/dev/null ||
-      sudo zpool import -d /dev/disk/by-id/ "$zpool"
-      trap "sudo zpool export $zpool" EXIT
-      zfs list -rH -t filesystem -o mounted,mountpoint,name "$zpool"/"$USER"/backup |
-      grep "^no\\s*/" | cut -f 3 | xargs -ortL1 sudo zfs mount -Olv || true
-      ${pkgs.mate.caja-with-extensions}/bin/caja --browser /mnt/"$zpool"/"$USER"/backup
-      )
-    }
-  '';
   programs.bash.shellAliases = {
     mount-backup-WD10JPVT = "mount-zfs-backup WD10JPVT";
   };