]> Sergey Matveev's repositories - dotfiles.git/blobdiff - bin/bin/zsnap.zsh
zsh built-in strftime
[dotfiles.git] / bin / bin / zsnap.zsh
index a75650c2a2c3ac09e37b6b216aec4125879e3766..67fff3c5bba62dfbf4e238f74d0e98f9fa37201a 100755 (executable)
@@ -1,6 +1,7 @@
 #!/usr/bin/env zsh
 
 set -e
+setopt EXTENDED_GLOB
 
 usage() {
     cat <<EOF
@@ -13,15 +14,16 @@ EOF
     exit 1
 }
 
-enccmd="gpg --compress-level 0 --encrypt --recipient offline --cipher-algo AES-128"
+enccmd=(~stargrave/bin/gpg-e-fast.sh --recipient offline)
 
 [[ $# -ge 2 ]] || usage
 
 what=$1
 action=$2
 
-now=$(date "+%Y%m%d%H%M")
-depth=${#${(s./.)what}}
+zmodload -F zsh/datetime b:strftime
+now=$(strftime %Y%m%d%H%M)
+[[ $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 +44,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
         ;;