Fixed BR->BG.

This commit is contained in:
Otho 2022-11-20 21:51:03 -05:00
parent 81fc6126c6
commit 6234584bd1
Signed by: Otho
GPG Key ID: 16C720CD3BBE21D9

View File

@ -18,24 +18,24 @@ datasets_file="datasets.txt"
list_active_datasets() list_active_datasets()
{ {
zfs list | tail -n +2 | cut -d' ' -f1|grep ${BR_ROOT} zfs list | tail -n +2 | cut -d' ' -f1|grep ${BG_ROOT}
} }
read_datasets() { read_datasets() {
while read BR_REMOTE_ADDR BR_REMOTE_PORT BR_REMOTE_ROOT BR_REMOTE_USER; do while read BG_REMOTE_ADDR BG_REMOTE_PORT BG_REMOTE_ROOT BG_REMOTE_USER; do
case $BR_REMOTE_ADDR in case $BG_REMOTE_ADDR in
\#*) continue;; \#*) continue;;
esac esac
if [ $BR_TEST_MODE = "TRUE" ]; then if [ $BG_TEST_MODE = "TRUE" ]; then
echo zfs send -R ${BR_ROOT}@${BR_NEW_SNAPSHOT} echo zfs send -R ${BG_ROOT}@${BG_NEW_SNAPSHOT}
echo ssh -i ~/.ssh/id_rsa -o port=${BR_REMOTE_PORT} \ echo ssh -i ~/.ssh/id_rsa -o port=${BG_REMOTE_PORT} \
${BR_REMOTE_USER}@${BR_REMOTE_ADDR} \ ${BG_REMOTE_USER}@${BG_REMOTE_ADDR} \
zfs receive -vu ${BR_REMOTE_ROOT} zfs receive -vu ${BG_REMOTE_ROOT}
else else
zfs send -R ${BR_ROOT}@${BR_NEW_SNAPSHOT} | zfs send -R ${BG_ROOT}@${BG_NEW_SNAPSHOT} |
ssh -i ~/.ssh/id_rsa -o port=${BR_REMOTE_PORT} \ ssh -i ~/.ssh/id_rsa -o port=${BG_REMOTE_PORT} \
${BR_REMOTE_USER}@${BR_REMOTE_ADDR} \ ${BG_REMOTE_USER}@${BG_REMOTE_ADDR} \
zfs receive -dvu ${BR_REMOTE_ROOT} zfs receive -dvu ${BG_REMOTE_ROOT}
fi fi
done < ${datasets_file} done < ${datasets_file}
} }
@ -45,14 +45,14 @@ read_datasets() {
create_datasets() { create_datasets() {
# should compare_datasets and only create missing or possibly error. # should compare_datasets and only create missing or possibly error.
for dataset in `cat ${datasets_file}`; do for dataset in `cat ${datasets_file}`; do
zfs create -p ${BR_ROOT}/$dataset zfs create -p ${BG_ROOT}/$dataset
done done
} }
get_latest_snapshot() get_latest_snapshot()
{ {
zfs list -t snapshot | zfs list -t snapshot |
grep ${BR_ROOT} | grep ${BG_ROOT} |
tail -n1 | tail -n1 |
cut -d'@' -f2 | cut -d'@' -f2 |
cut -d' ' -f 1 cut -d' ' -f 1
@ -60,68 +60,68 @@ get_latest_snapshot()
setup_aggregator() setup_aggregator()
{ {
zfs allow -u ${BR_USER} send,snapshot,hold ${BR_ROOT} zfs allow -u ${BG_USER} send,snapshot,hold ${BG_ROOT}
create_datasets create_datasets
} }
setup_mirror() setup_mirror()
{ {
zfs create -p $BR_ROOT zfs create -p $BG_ROOT
create_datasets create_datasets
zfs allow -u ${BR_USER} send,snapshot,hold ${BR_ROOT} zfs allow -u ${BG_USER} send,snapshot,hold ${BG_ROOT}
zfs allow -u ${BR_USER} \ zfs allow -u ${BG_USER} \
compression,mountpoint,receive,create,mount ${BR_ROOT} compression,mountpoint,receive,create,mount ${BG_ROOT}
} }
create_snapshot() create_snapshot()
{ {
id="`date -I`-`date +%s`" id="`date -I`-`date +%s`"
if [ $BR_TEST_MODE = "TRUE" ]; then if [ $BG_TEST_MODE = "TRUE" ]; then
echo zfs snapshot -r ${BR_ROOT}@${id} echo zfs snapshot -r ${BG_ROOT}@${id}
else else
zfs snapshot -r ${BR_ROOT}@${id} zfs snapshot -r ${BG_ROOT}@${id}
fi fi
} }
send_single_snapshot() send_single_snapshot()
{ {
BR_NEW_SNAPSHOT=`get_latest_snapshot` BG_NEW_SNAPSHOT=`get_latest_snapshot`
tail -n +2 ${nodes_file} > sendnodes.tmp tail -n +2 ${nodes_file} > sendnodes.tmp
while read BR_REMOTE_ADDR BR_REMOTE_PORT BR_REMOTE_ROOT BR_REMOTE_USER; do while read BG_REMOTE_ADDR BG_REMOTE_PORT BG_REMOTE_ROOT BG_REMOTE_USER; do
case $BR_REMOTE_ADDR in case $BG_REMOTE_ADDR in
\#*) continue;; \#*) continue;;
esac esac
if [ $BR_TEST_MODE = "TRUE" ]; then if [ $BG_TEST_MODE = "TRUE" ]; then
echo zfs send -R ${BR_ROOT}@${BR_NEW_SNAPSHOT} echo zfs send -R ${BG_ROOT}@${BG_NEW_SNAPSHOT}
echo ssh -i ~/.ssh/id_rsa -o port=${BR_REMOTE_PORT} \ echo ssh -i ~/.ssh/id_rsa -o port=${BG_REMOTE_PORT} \
${BR_REMOTE_USER}@${BR_REMOTE_ADDR} \ ${BG_REMOTE_USER}@${BG_REMOTE_ADDR} \
zfs receive -dvu ${BR_REMOTE_ROOT} zfs receive -dvu ${BG_REMOTE_ROOT}
else else
zfs send -R ${BR_ROOT}@${BR_NEW_SNAPSHOT} | zfs send -R ${BG_ROOT}@${BG_NEW_SNAPSHOT} |
ssh -i ~/.ssh/id_rsa -o port=${BR_REMOTE_PORT} \ ssh -i ~/.ssh/id_rsa -o port=${BG_REMOTE_PORT} \
${BR_REMOTE_USER}@${BR_REMOTE_ADDR} \ ${BG_REMOTE_USER}@${BG_REMOTE_ADDR} \
zfs receive -dvu ${BR_REMOTE_ROOT} zfs receive -dvu ${BG_REMOTE_ROOT}
fi fi
done < sendnodes.tmp done < sendnodes.tmp
rm sendnodes.tmp rm sendnodes.tmp
if [ $BR_TEST_MODE = "TRUE" ]; then if [ $BG_TEST_MODE = "TRUE" ]; then
: :
else else
echo $BR_NEW_SNAPSHOT > "old-snapshot.txt" echo $BG_NEW_SNAPSHOT > "old-snapshot.txt"
fi fi
} }
send_incremental_snapshot() send_incremental_snapshot()
{ {
BR_NEW_SNAPSHOT=`get_latest_snapshot` BG_NEW_SNAPSHOT=`get_latest_snapshot`
echo Will send $BR_NEW_SNAPSHOT echo Will send $BG_NEW_SNAPSHOT
#while read BR_REMOTE_ADDR BR_REMOTE_PORT BR_REMOTE_ROOT BR_REMOTE_USER; do #while read BG_REMOTE_ADDR BG_REMOTE_PORT BG_REMOTE_ROOT BG_REMOTE_USER; do
# zfs send -R -i `cat old-snapshot.txt` ${BR_ROOT}@${BR_NEW_SNAPSHOT} | # zfs send -R -i `cat old-snapshot.txt` ${BG_ROOT}@${BG_NEW_SNAPSHOT} |
# ssh -i ~/.ssh/id_rsa -o port=${BR_REMOTE_PORT} \ # ssh -i ~/.ssh/id_rsa -o port=${BG_REMOTE_PORT} \
# ${BR_REMOTE_USER}@${BR_REMOTE_ADDR} \ # ${BG_REMOTE_USER}@${BG_REMOTE_ADDR} \
# zfs receive -dvu ${BR_REMOTE_ROOT}@${BR_NEW_SNAPSHOT} # zfs receive -dvu ${BG_REMOTE_ROOT}@${BG_NEW_SNAPSHOT}
#done #done
echo $BR_NEW_SNAPSHOT > "old-snapshot.txt" echo $BG_NEW_SNAPSHOT > "old-snapshot.txt"
} }
@ -132,11 +132,11 @@ set -- `getopt "tl:" "$@"` || {
echo "Usage: `basename $0` [-tl] [command]" 1>&2 echo "Usage: `basename $0` [-tl] [command]" 1>&2
exit 1 exit 1
} }
BR_TEST_MODE=FALSE BG_TEST_MODE=FALSE
while :; do while :; do
case "$1" in case "$1" in
-t) -t)
BR_TEST_MODE=TRUE BG_TEST_MODE=TRUE
echo Test mode. echo Test mode.
;; ;;
--) shift; break ;; --) shift; break ;;
@ -144,7 +144,7 @@ while :; do
shift shift
done done
read BR_HOST BR_PORT BR_ROOT BR_USER < ${nodes_file} read BG_HOST BG_PORT BG_ROOT BG_USER < ${nodes_file}
if [ ! -f ${nodes_file} ]; then echo "No nodes specified."; exit 2; fi if [ ! -f ${nodes_file} ]; then echo "No nodes specified."; exit 2; fi