Skip to content

Commit

Permalink
Add -C option, which prevents supplying -c to zfs send
Browse files Browse the repository at this point in the history
This addresses issue #15 and an email report from HIROSE yuuji.

The NetBSD date fix was supplied by HIROSE yuuji.
  • Loading branch information
Jehops committed Oct 27, 2020
1 parent 069a845 commit 681fcb4
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 14 deletions.
1 change: 1 addition & 0 deletions README.org
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ and =rep= subcommands.
- David Samms <dsamms@nw-ds.com>
- Victor Naumov <vicnaumov@gmail.com>
- Dries Michiels <driesm.michiels@gmail.com>
- HIROSE yuuji <yuuji@gentei.org>
** License
zap is released under a BSD 2-Clause License. Refer to the header of each
source file for details.
Expand Down
35 changes: 23 additions & 12 deletions zap
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ ss_ts () {
gdate=$(echo "$1" | sed 's/T/ /')
date -d"$gdate" +%s
;;
'NetBSD')
ndate=$(echo "$1" | sed 's/\+.*//;s/[T-]//g;s/://;s/:/./')
date -j "$ndate" +%s
;;
esac
}

Expand Down Expand Up @@ -220,10 +224,11 @@ time could not be determined."
done
}

# rep_parse [-DFLSv] [destination [-r] dataset [[-r] dataset]...]
# rep_parse [-CDFLSv] [destination [-r] dataset [[-r] dataset]...]
rep_parse () {
while getopts ":DFLSv" opt; do
while getopts ":CDFLSv" opt; do
case $opt in
C) C_opt=1 ;;
D) D_opt='-D' ;;
L) L_opt=1 ;;
S) S_opt=1 ;;
Expand All @@ -234,6 +239,11 @@ rep_parse () {
done
shift $(( OPTIND - 1 ))

if [ -n "$C_opt" ]; then # user has request no compression
C_opt=
else # use compression by default
C_opt='-c'
fi
[ -n "$v_opt" ] && printf '%s\nReplicating...\n' "$(date)"
if [ -z "$*" ]; then # use zap:rep property to replicate
for f in $(zfs list -H -o name -t volume,filesystem); do
Expand Down Expand Up @@ -316,8 +326,8 @@ rep_full() {

if [ -z "$host" ]; then # replicating locally
[ -n "$v_opt" ] && \
echo "zfs send -Lcep $lsnap | zfs recv -Fu $v_opt -d $rloc"
if zfs send -Lcep "$lsnap" | zfs recv -Fu $v_opt -d "$rloc"; then
echo "zfs send -Lep $C_opt $lsnap | zfs recv -Fu $v_opt -d $rloc"
if zfs send -Lep $C_opt "$lsnap" | zfs recv -Fu $v_opt -d "$rloc"; then
[ -n "$v_opt" ] && \
echo "zfs bookmark $lsnap $(echo "$lsnap" | sed 's/@/#/')"
zfs bookmark "$lsnap" "$(echo "$lsnap" | sed 's/@/#/')"
Expand All @@ -339,9 +349,9 @@ rep_full() {
fi
else # replicating remotely
[ -n "$v_opt" ] && \
echo "zfs send -Lcep $lsnap | ssh $sshto \"sh -c 'zfs recv -Fu $v_opt \
-d $rloc'\""
if zfs send -Lcep "$lsnap" | \
echo "zfs send -Lep $C_opt $lsnap | ssh $sshto \"sh -c 'zfs recv -Fu \
$v_opt -d $rloc'\""
if zfs send -Lep $C_opt "$lsnap" | \
ssh "$sshto" "sh -c 'zfs recv -Fu $v_opt -d $rloc'"; then
[ -n "$v_opt" ] && \
echo "zfs bookmark $lsnap $(echo "$lsnap" | sed 's/@/#/')"
Expand Down Expand Up @@ -392,8 +402,9 @@ intermediary snapshots will not be sent."
if echo "$sp" | grep -q '@'; then i='-I'; else i='-i'; fi
if [ -z "$host" ]; then # replicate locally
[ -n "$v_opt" ] && \
echo "zfs send -Lce $i $sp $lsnap | zfs recv -du $F_opt $v_opt $rloc"
if zfs send -Lce $i "$sp" "$lsnap" | zfs recv -du $F_opt $v_opt \
echo "zfs send -Le $C_opt $i $sp $lsnap | zfs recv -du $F_opt $v_opt \
$rloc"
if zfs send -Le $C_opt $i "$sp" "$lsnap" | zfs recv -du $F_opt $v_opt \
"$rloc"; then
[ -n "$v_opt" ] && \
echo "zfs bookmark $lsnap $(echo "$lsnap" | sed 's/@/#/')"
Expand All @@ -405,9 +416,9 @@ intermediary snapshots will not be sent."
fi
else # replicate remotely
[ -n "$v_opt" ] && \
echo "zfs send -Lce $i $sp $lsnap | ssh $sshto \"sh -c 'zfs recv -du \
$F_opt $v_opt $rloc'\""
if zfs send -Lce $i "$sp" "$lsnap" | \
echo "zfs send -Le $C_opt $i $sp $lsnap | ssh $sshto \"sh -c \
'zfs recv -du $F_opt $v_opt $rloc'\""
if zfs send -Le $C_opt $i "$sp" "$lsnap" | \
ssh "$sshto" "sh -c 'zfs recv -du $F_opt $v_opt $rloc'"; then
[ -n "$v_opt" ] && \
echo "zfs bookmark $lsnap $(echo "$lsnap" | sed 's/@/#/')"
Expand Down
10 changes: 8 additions & 2 deletions zap.1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.Dd November 10, 2018
.Dd October 27, 2020
.Dt ZAP 1
.Os
.Sh NAME
Expand All @@ -13,7 +13,7 @@
.Ar dataset Oc Ns ...
.Nm
.Ar rep Ns | Ns Ar replicate
.Op Fl DFLSv
.Op Fl CDFLSv
.Oo Oo Op Ar user Ns @ Oc Ns Ar host Ns : Ns
.Ar parent_dataset
.Op Fl r
Expand Down Expand Up @@ -105,6 +105,12 @@ specified without any domain information, that is, as returned by
.Ic hostname -s Ns .
.Sh OPTIONS
.Bl -tag -width "12345678"
.It Fl C
Do not supply
.Ic -c
to
.Ar zfs send Ns
\&. This option is unsupported on some systems, such as Debian 9 and NetBSD 9.
.It Fl D
Do not operate on snapshots when the pool is in a DEGRADED state.
.It Fl F
Expand Down

0 comments on commit 681fcb4

Please sign in to comment.