backup: add mount-zfs-backup
authorJulien Moutinho <julm@sourcephile.fr>
Thu, 17 Dec 2020 17:57:32 +0000 (18:57 +0100)
committerJulien Moutinho <julm@sourcephile.fr>
Thu, 17 Dec 2020 17:57:32 +0000 (18:57 +0100)
homes/julm.nix
hosts/oignon/backup.nix
hosts/patate/backup.nix

index 96be3fcf18ae9fd3f5b36746783413733c669dcc..9f7a5e008947d90a35d42a53681ad1b84db3cfef 100644 (file)
@@ -100,6 +100,7 @@ home.packages = [
   pkgs.git-crypt
   #pkgs.git-remote-gpg
   pkgs.glib # gio
+  pkgs.go-mtpfs
   pkgs.gnumake
   pkgs.gvfs
   #pkgs.haskell.packages.ghc865.zerobin
index 2e4165585bfd994a4bc3373c21e734177da8cc50..3466362a3a78b9790a7463afd81e53e9080d9cb7 100644 (file)
@@ -118,6 +118,7 @@ systemd.services."zfs-local-backup-home@" = {
         process_children_only=false
 
         [$DESTPOOL/${User}/backup/${hostName}/home]
+        hourly=12
         daily=31
         monthly=0
         recursive=true
@@ -165,4 +166,21 @@ systemd.services."zfs-local-backup-home@" = {
     '' + " %I";
   };
 };
+programs.bash.interactiveShellInit = ''
+  mount-zfs-backup () {
+    (
+    set -x
+    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}/bin/caja --browser /mnt/"$zpool"/"$USER"/backup
+    )
+  }
+'';
+programs.bash.shellAliases = {
+  mount-backup-WD10JPVT = "mount-zfs-backup WD10JPVT";
+};
 }
index a0ec425e4f4b2238f4b7756712923019e294b682..caf548f7413d12b0b89027044cc1f25750c12636 100644 (file)
@@ -150,7 +150,7 @@ systemd.services."zfs-local-backup-home@" = {
       fi
       if zpool status "$DESTPOOL"; then
         zpool scrub -p "$DESTPOOL" || true
-        sleep 10
+        sleep 20
         # Export the zpool (to avoid a forced import later on)
         zpool export "$DESTPOOL"
       fi
@@ -158,4 +158,21 @@ systemd.services."zfs-local-backup-home@" = {
     '' + " %I";
   };
 };
+programs.bash.interactiveShellInit = ''
+  mount-zfs-backup () {
+    (
+    set -x
+    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}/bin/caja --browser /mnt/"$zpool"/"$USER"/backup
+    )
+  }
+'';
+programs.bash.shellAliases = {
+  mount-backup-WD10JPVT = "mount-zfs-backup WD10JPVT";
+};
 }