8 Usage: $0 DATASET@SNAPPREFIX snap-initial
9 $0 DATASET@SNAPPREFIX snap
10 $0 DATASET@SNAPPREFIX sync-initial DST
11 $0 DATASET@SNAPPREFIX sync DST
12 $0 DATASET@SNAPPREFIX clean COUNT
17 enccmd=(~stargrave/bin/gpg-e-fast.sh --recipient offline)
19 [[ $# -ge 2 ]] || usage
24 zmodload -F zsh/datetime b:strftime
25 now=$(strftime %Y%m%d%H%M)
26 [[ $what =~ / ]] && depth=1 || depth=${#${(s./.)what}}
27 snaps=$(zfs list -t snap -d $depth -o name -H | grep $what | sort -nr)
30 latest_filename=${latest:gs#/#%}
34 zfs snap -r $what-$now
39 [[ "$what-$now" != $latest ]]
40 zfs snap -r $what-$now
45 [[ -d $dst ]] || usage
47 zfs send -Rv $latest | zstd | $enccmd > $dst/$latest_filename.zfs.zst.gpg
49 touch $dst/$latest_filename.from
53 [[ -d $dst ]] || usage
54 latest_dst=($dst/*~$dst/.*(.L0Onn[1]))
56 latest_dst=${latest_dst[1]}
57 latest_dst=${${latest_dst##*/}%.from}
58 [[ $latest_dst != $latest_filename ]]
61 zfs send -Rv -i ${latest_dst:gs#%#/} $latest | zstd | $enccmd > \
62 $dst/$latest_filename.zfs.zst.gpg
65 print $latest_dst > $dst/$latest_filename.from
69 [[ -n $count ]] || usage
70 count=$(( $count + 1 ))
71 for snap in $snaps ; do
72 count=$(( $count - 1 ))
73 [[ $count -le 0 ]] || continue