]> Sergey Matveev's repositories - dotfiles.git/commitdiff
Various zsnap fixes
authorSergey Matveev <stargrave@stargrave.org>
Wed, 1 Sep 2021 08:56:41 +0000 (11:56 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Wed, 1 Sep 2021 13:15:52 +0000 (16:15 +0300)
bin/bin/zsnap.zsh

index f9f97024a7d9c62aefa4d8d814f1fd476158f1e2..0182a53c7575d6142c2f9445042710f06be3c078 100755 (executable)
@@ -1,6 +1,7 @@
 #!/usr/bin/env zsh
 
 set -e
+setopt EXTENDED_GLOB
 
 usage() {
     cat <<EOF
@@ -13,7 +14,7 @@ EOF
     exit 1
 }
 
-enccmd="/home/stargrave/bin/gpg-e-fast.sh --recipient offline"
+enccmd=(~stargrave/bin/gpg-e-fast.sh --recipient offline)
 
 [[ $# -ge 2 ]] || usage
 
@@ -21,7 +22,7 @@ what=$1
 action=$2
 
 now=$(date "+%Y%m%d%H%M")
-depth=${#${(s./.)what}}
+[[ $what =~ / ]] && depth=1 || depth=${#${(s./.)what}}
 snaps=$(zfs list -t snap -d $depth -o name -H | grep $what | sort -nr)
 snaps=(${(f)snaps})
 latest=${snaps[1]}
@@ -42,22 +43,23 @@ case $action in
         dst=$3
         [[ -d $dst ]] || usage
         setopt PIPE_FAIL
-        zfs send -Rv $latest | zstd | ${=enccmd} > \
-            $dst/$latest_filename.zfs.zst.gpg
+        zfs send -Rv $latest | zstd | $enccmd > $dst/$latest_filename.zfs.zst.gpg
         sync
         touch $dst/$latest_filename.from
         ;;
     sync)
         dst=$3
         [[ -d $dst ]] || usage
-        latest_dst=($dst/*(.Onn[1]))
+        latest_dst=($dst/*~$dst/.*(.L0Onn[1]))
         [[ $latest_dst ]]
         latest_dst=${latest_dst[1]}
         latest_dst=${${latest_dst##*/}%.from}
         [[ $latest_dst != $latest_filename ]]
         setopt PIPE_FAIL
-        zfs send -Rv -i ${latest_dst:gs#%#/} $latest | zstd | ${=enccmd} > \
+        set -x
+        zfs send -Rv -i ${latest_dst:gs#%#/} $latest | zstd | $enccmd > \
             $dst/$latest_filename.zfs.zst.gpg
+        set +x
         sync
         print $latest_dst > $dst/$latest_filename.from
         ;;