Skip to content

Commit

Permalink
Merge pull request #17 from maxatome/master
Browse files Browse the repository at this point in the history
Add rep -h HOST option to replicate snapshots originating from HOST
  • Loading branch information
Jehops authored Jun 5, 2021
2 parents 681fcb4 + ee1f8e8 commit ae320a3
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 7 deletions.
7 changes: 6 additions & 1 deletion README.org
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
** Synopsis
=# zap snap|snapshot [-DLSv] TTL [[-r] dataset]...=

=# zap rep|replicate [-DFLSv] [[[user@]host:]parent_dataset [-r] dataset [[-r] dataset]...]=
=# zap rep|replicate [-DFLSv] [-h host] [[[user@]host:]parent_dataset [-r] dataset [[-r] dataset]...]=

=# zap destroy [-Dlsv] [host[,host]...]=

Expand Down Expand Up @@ -36,6 +36,11 @@
Replicate datasets (recursively for zroot/ROOT) to the remote host bravo, under the =rback/phe= dataset, but this time specify the datasets on the command line. If you use a non-default ssh port, specify it in =~/.ssh/config=.
#+BEGIN_SRC sh
# zap rep zap@bravo:rback/phe -r zroot/ROOT zroot/usr/home/jrm
#+END_SRC
Replicate datasets that originated from the host awarnach to the remote host bravo, under the zback/phe dataset. If you use a non-default ssh port, specify it in =~/.ssh/config=.
#+BEGIN_SRC sh
# zfs set zap:rep='zap@bravo:zback/phe' zroot/ROOT zroot/usr/home/jrm
# zap rep -v -h awarnach
#+END_SRC
Destroy expired snapshots. Be verbose.
#+BEGIN_SRC sh
Expand Down
13 changes: 9 additions & 4 deletions zap
Original file line number Diff line number Diff line change
Expand Up @@ -224,16 +224,20 @@ time could not be determined."
done
}

# rep_parse [-CDFLSv] [destination [-r] dataset [[-r] dataset]...]
# rep_parse [-CDFLSv] [-h host] [destination [-r] dataset [[-r] dataset]...]
rep_parse () {
while getopts ":CDFLSv" opt; do
while getopts ":CDFLSvh:" opt; do
case $opt in
C) C_opt=1 ;;
D) D_opt='-D' ;;
L) L_opt=1 ;;
S) S_opt=1 ;;
v) v_opt='-v' ;;
F) F_opt='-F' ;;
h)
hn="$OPTARG"
(echo "$hn" | grep -Eq "$hostalone") || fatal "Invalid hostname $hn."
;;
\?) fatal "Invalid rep_parse() option: -$OPTARG." ;;
esac
done
Expand All @@ -244,7 +248,7 @@ rep_parse () {
else # use compression by default
C_opt='-c'
fi
[ -n "$v_opt" ] && printf '%s\nReplicating...\n' "$(date)"
[ -n "$v_opt" ] && printf '%s\nReplicating %s...\n' "$(date)" "$hn"
if [ -z "$*" ]; then # use zap:rep property to replicate
for f in $(zfs list -H -o name -t volume,filesystem); do
dest=$(zfs get -H -o value zap:rep "$f")
Expand Down Expand Up @@ -453,7 +457,7 @@ a resilver in progress."
warn "Failed to replicate $1."
elif ! lsnap=$(zfs list -rd1 -H -tsnap -o name -S creation "$1" \
| grep -m1 "@ZAP_${hn}_") || [ -z "$lsnap" ]; then
warn "Failed to find the newest local snapshot for $1."
warn "Failed to find the newest local snapshot of $hn for $1."
else
l_ts=$(ss_ts "$(ss_st "$lsnap")")
[ "${1#*/}" = "${1}" ] || fs="/${1#*/}"
Expand Down Expand Up @@ -581,6 +585,7 @@ fi
# portability of {} in egrep is uncertain
dsptn='^\w[[:alnum:]_.:-]*(/[[:alnum:]_\.:-]+)*$'
hostptn='^((\w|\w[[:alnum:]-]*\w)\.)*(\w|\w[[:alnum:]-]*\w)$'
hostalone='^(\w|\w[[:alnum:]-]*\w)$'
# goo.gl/t3meuX (Stackoverflow answer about IP regexp)
ipv4ptn="^((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|\
1{0,1}[0-9]){0,1}[0-9])$"
Expand Down
25 changes: 23 additions & 2 deletions zap.1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.Dd October 27, 2020
.Dd May 9, 2021
.Dt ZAP 1
.Os
.Sh NAME
Expand All @@ -14,6 +14,7 @@
.Nm
.Ar rep Ns | Ns Ar replicate
.Op Fl CDFLSv
.Op Fl h Ar host
.Oo Oo Op Ar user Ns @ Oc Ns Ar host Ns : Ns
.Ar parent_dataset
.Op Fl r
Expand Down Expand Up @@ -93,7 +94,13 @@ after replication an attempt is made to set
.Sy canmount
to
.Sy noauto
on the remote side. This is done to prevent mountpoint collisions.
on the remote side. This is done to prevent mountpoint collisions. By default,
snapshots originating from the local host (as returned by
.Ic hostname -s Ns
) are replicated, but
.Ic -h host
can be used to replicate snapshots originating from
.Ic host Ns .
.Pp
.Ss Ar destroy
Use the
Expand All @@ -119,6 +126,12 @@ Supply
to
.Ar zfs receive Ns
, which destroys remote changes that do not exist on the sending side.
.It Fl h Ar host
Replicate snapshots originating from
.Ic host
instead of those originating from the local host (as returned by
.Ic hostname -s Ns
).
.It Fl L
Do not operate on snapshots if the pool has a resilver in progress. This is the
default for the
Expand Down Expand Up @@ -181,6 +194,14 @@ line. If you use a non-default ssh port, specify it in ~/.ssh/config.
zap rep zap@bravo:rback/phe -r zroot/ROOT zroot/usr/home/jrm
.Ed
.Pp
Replicate datasets originating from awarnach to the remote host bravo, under the
zback/phe dataset. If you use a non-default ssh port, specify it in
~/.ssh/config.
.Bd -literal -offset indent
zfs set zap:rep='zap@bravo:zback/phe' zroot/ROOT zroot/usr/home/jrm
zap rep -v -h awarnach
.Ed
.Pp
Destroy expired snapshots. Be verbose.
.Bd -literal -offset indent
zap destroy -v
Expand Down

0 comments on commit ae320a3

Please sign in to comment.