Added option to not have remote zroot.

This commit is contained in:
Otho 2023-01-08 03:01:38 -05:00
parent dab6a41c38
commit d4598beff5
Signed by: Otho
GPG Key ID: 16C720CD3BBE21D9

View File

@ -63,15 +63,21 @@ list_datasets()
list_remote_datasets() { list_remote_datasets() {
while read addr user ssh_port zroot; do while read addr user ssh_port zroot; do
echo "=== $user@$addr $zroot ===" echo "=== $user@$addr $zroot ==="
if [ $zroot ]; then
case $zroot in
*"/") ;;
*) zroot="$zroot/" ;;
esac
fi
if [ $BG_TEST_MODE = "TRUE" ]; then if [ $BG_TEST_MODE = "TRUE" ]; then
echo ssh -i ~/.ssh/id_rsa -o port=$ssh_port $user@$addr\ echo ssh -i ~/.ssh/id_rsa -o port=$ssh_port $user@$addr\
"sh -c 'for dataset in $SEND_DATASETS; "sh -c 'for dataset in $SEND_DATASETS;
do zfs list -H $zroot/\$dataset; do zfs list -H $zroot\$dataset;
done'" done'"
else else
ssh -i ~/.ssh/id_rsa -o port=$ssh_port $user@$addr \ ssh -i ~/.ssh/id_rsa -o port=$ssh_port $user@$addr \
"sh -c 'for dataset in $SEND_DATASETS; "sh -c 'for dataset in $SEND_DATASETS;
do zfs list -H $zroot/\$dataset; do zfs list -H $zroot\$dataset;
done';" done';"
fi fi
done < sendnodes.tmp done < sendnodes.tmp
@ -84,8 +90,14 @@ get_latest_snapshot()
get_latest_remote_snapshot() get_latest_remote_snapshot()
{ {
if [ $zroot ]; then
case $zroot in
*"/") ;;
*) zroot="$zroot/" ;;
esac
fi
ssh -i ~/.ssh/id_rsa -o port=$ssh_port $user@$addr \ ssh -i ~/.ssh/id_rsa -o port=$ssh_port $user@$addr \
"zfs list -t snapshot $zroot/$dataset | "zfs list -t snapshot $zroot\$dataset |
tail -n1|cut -d'@' -f2|cut -d' ' -f 1" tail -n1|cut -d'@' -f2|cut -d' ' -f 1"
} }
@ -104,15 +116,21 @@ zfs_allow_mirrors()
{ {
while read addr user ssh_port zroot; do while read addr user ssh_port zroot; do
echo "=== $user@$addr $zroot ===" echo "=== $user@$addr $zroot ==="
if [ $zroot ]; then
case $zroot in
*"/") ;;
*) zroot="$zroot/" ;;
esac
fi
if [ $BG_TEST_MODE = "TRUE" ]; then if [ $BG_TEST_MODE = "TRUE" ]; then
echo ssh -i ~/.ssh/id_rsa -o port=$ssh_port $user@$addr \ echo ssh -i ~/.ssh/id_rsa -o port=$ssh_port $user@$addr \
"for dataset in $SEND_DATASETS; do "for dataset in $SEND_DATASETS; do
zfs allow -u $user $MIRROR_PERMS $zroot/\$dataset zfs allow -u $user $MIRROR_PERMS $zroot\$dataset
done" done"
else else
ssh -i ~/.ssh/id_rsa -o port=$ssh_port $user@$addr \ ssh -i ~/.ssh/id_rsa -o port=$ssh_port $user@$addr \
"for dataset in $SEND_DATASETS; do "for dataset in $SEND_DATASETS; do
zfs allow -u $user $MIRROR_PERMS $zroot/\$dataset zfs allow -u $user $MIRROR_PERMS $zroot\$dataset
done" done"
fi fi
done < sendnodes.tmp done < sendnodes.tmp
@ -134,17 +152,23 @@ send_latest()
{ {
while read addr user ssh_port zroot; do while read addr user ssh_port zroot; do
echo "=== $user@$addr $zroot ===" echo "=== $user@$addr $zroot ==="
if [ $zroot ]; then
case $zroot in
*"/") ;;
*) zroot="$zroot/" ;;
esac
fi
for dataset in $SEND_DATASETS; do for dataset in $SEND_DATASETS; do
origin_snapshot=`get_latest_snapshot $dataset` origin_snapshot=`get_latest_snapshot $dataset`
if [ $BG_TEST_MODE = "TRUE" ]; then if [ $BG_TEST_MODE = "TRUE" ]; then
echo zfs send $ZFS_SEND_OPTS $dataset@$origin_snapshot \| \ echo zfs send $ZFS_SEND_OPTS $dataset@$origin_snapshot \| \
ssh -i ~/.ssh/id_rsa -o port=$ssh_port $user@$addr \ ssh -i ~/.ssh/id_rsa -o port=$ssh_port $user@$addr \
zfs recv $ZFS_RECV_OPTS $zroot/$dataset zfs recv $ZFS_RECV_OPTS $zroot$dataset
else else
zfs send $ZFS_SEND_OPTS $dataset@$origin_snapshot | zfs send $ZFS_SEND_OPTS $dataset@$origin_snapshot |
ssh -i ~/.ssh/id_rsa -o port=$ssh_port \ ssh -i ~/.ssh/id_rsa -o port=$ssh_port \
$user@$addr \ $user@$addr \
zfs recv $ZFS_RECV_OPTS $zroot/$dataset zfs recv $ZFS_RECV_OPTS $zroot$dataset
fi fi
done done
done < sendnodes.tmp done < sendnodes.tmp
@ -154,6 +178,12 @@ send_increment()
{ {
while read addr user ssh_port zroot; do while read addr user ssh_port zroot; do
echo "=== $user@$addr $zroot ===" echo "=== $user@$addr $zroot ==="
if [ $zroot ]; then
case $zroot in
*"/") ;;
*) zroot="$zroot/" ;;
esac
fi
for dataset in $SEND_DATASETS; do for dataset in $SEND_DATASETS; do
origin_snapshot=`get_latest_snapshot` origin_snapshot=`get_latest_snapshot`
remote_snapshot=`get_latest_remote_snapshot` remote_snapshot=`get_latest_remote_snapshot`
@ -162,13 +192,13 @@ send_increment()
-i $dataset@$remote_snapshot \ -i $dataset@$remote_snapshot \
$dataset@$origin_snapshot \| \ $dataset@$origin_snapshot \| \
ssh -i ~/.ssh/id_rsa -o port=$ssh_port $user@$addr \ ssh -i ~/.ssh/id_rsa -o port=$ssh_port $user@$addr \
zfs recv $ZFS_RECV_OPTS $zroot/$dataset zfs recv $ZFS_RECV_OPTS $zroot$dataset
else else
zfs send $ZFS_SEND_OPTS \ zfs send $ZFS_SEND_OPTS \
-i $dataset@$remote_snapshot \ -i $dataset@$remote_snapshot \
$dataset@$origin_snapshot | $dataset@$origin_snapshot |
ssh -i ~/.ssh/id_rsa -o port=$ssh_port $user@$addr \ ssh -i ~/.ssh/id_rsa -o port=$ssh_port $user@$addr \
zfs recv $ZFS_RECV_OPTS $zroot/$dataset zfs recv $ZFS_RECV_OPTS $zroot$dataset
fi fi
done done
done < sendnodes.tmp done < sendnodes.tmp