#!/usr/bin/env zsh
set -e
+setopt EXTENDED_GLOB
usage() {
cat <<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]}
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
;;