]> Sergey Matveev's repositories - dotfiles.git/blobdiff - bin/bin/zsnap
HI flag
[dotfiles.git] / bin / bin / zsnap
index 5dab4c33a8aa65bb0a32ee38c8d5396513800992..7bab829040cc9ebee6e6cea2a32ac62d5ec2171b 100755 (executable)
@@ -1,7 +1,6 @@
 #!/usr/bin/env zsh
 
-set -e
-setopt EXTENDED_GLOB
+setopt ERR_EXIT EXTENDED_GLOB
 
 usage() {
     cat <<EOF
@@ -10,11 +9,19 @@ Usage: $0 DATASET@SNAPPREFIX snap-initial
        $0 DATASET@SNAPPREFIX sync-initial DST
        $0 DATASET@SNAPPREFIX sync DST
        $0 DATASET@SNAPPREFIX clean COUNT
+       FIFO=1
 EOF
     exit 1
 }
 
-enccmd=(gpg --compress-level 0 --encrypt --recipient offline)
+mk_fifo() {
+    [[ -z $FIFO ]] || {
+        mkfifo $dst/$latest_filename.zfs.zst.age
+        echo $dst/$latest_filename.zfs.zst.age
+    }
+}
+
+enccmd=(~stargrave/bin/age -R /home/stargrave/.age/general.pub)
 
 [[ $# -ge 2 ]] || usage
 
@@ -28,6 +35,7 @@ snaps=$(zfs list -t snap -d $depth -o name -H | grep $what | sort -nr)
 snaps=(${(f)snaps})
 latest=${snaps[1]}
 latest_filename=${latest:gs#/#%}
+dst=$3
 
 case $action in
     snap-initial)
@@ -41,25 +49,25 @@ case $action in
         print $what-$now
         ;;
     sync-initial)
-        dst=$3
         [[ -d $dst ]] || usage
+        mk_fifo
         setopt PIPE_FAIL
-        zfs send -Rwv $latest | zstd | $enccmd > $dst/$latest_filename.zfs.zst.gpg
+        zfs send -Rwv $latest | zstdmt | $enccmd > $dst/$latest_filename.zfs.zst.age
         sync
         touch $dst/$latest_filename.from
         ;;
     sync)
-        dst=$3
         [[ -d $dst ]] || usage
-        latest_dst=($dst/*~$dst/.*(.L0Onn[1]))
+        mk_fifo
+        latest_dst=($dst/*.from~$dst/.*(.Onn[1]))
         [[ $latest_dst ]]
         latest_dst=${latest_dst[1]}
         latest_dst=${${latest_dst##*/}%.from}
         [[ $latest_dst != $latest_filename ]]
         setopt PIPE_FAIL
         set -x
-        zfs send -Rwv -i ${latest_dst:gs#%#/} $latest | zstd | $enccmd > \
-            $dst/$latest_filename.zfs.zst.gpg
+        zfs send -Rwv -i ${latest_dst:gs#%#/} $latest | zstdmt | $enccmd > \
+            $dst/$latest_filename.zfs.zst.age
         set +x
         sync
         print $latest_dst > $dst/$latest_filename.from