mirror of
https://asciireactor.com/o4data/zfs-backup.git
synced 2024-11-22 01:45:06 +00:00
Added option to not have remote zroot.
This commit is contained in:
parent
dab6a41c38
commit
d4598beff5
48
backup.sh
48
backup.sh
@ -63,15 +63,21 @@ list_datasets()
|
||||
list_remote_datasets() {
|
||||
while read addr user ssh_port zroot; do
|
||||
echo "=== $user@$addr $zroot ==="
|
||||
if [ $zroot ]; then
|
||||
case $zroot in
|
||||
*"/") ;;
|
||||
*) zroot="$zroot/" ;;
|
||||
esac
|
||||
fi
|
||||
if [ $BG_TEST_MODE = "TRUE" ]; then
|
||||
echo ssh -i ~/.ssh/id_rsa -o port=$ssh_port $user@$addr\
|
||||
"sh -c 'for dataset in $SEND_DATASETS;
|
||||
do zfs list -H $zroot/\$dataset;
|
||||
do zfs list -H $zroot\$dataset;
|
||||
done'"
|
||||
else
|
||||
ssh -i ~/.ssh/id_rsa -o port=$ssh_port $user@$addr \
|
||||
"sh -c 'for dataset in $SEND_DATASETS;
|
||||
do zfs list -H $zroot/\$dataset;
|
||||
do zfs list -H $zroot\$dataset;
|
||||
done';"
|
||||
fi
|
||||
done < sendnodes.tmp
|
||||
@ -84,8 +90,14 @@ get_latest_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 \
|
||||
"zfs list -t snapshot $zroot/$dataset |
|
||||
"zfs list -t snapshot $zroot\$dataset |
|
||||
tail -n1|cut -d'@' -f2|cut -d' ' -f 1"
|
||||
}
|
||||
|
||||
@ -104,15 +116,21 @@ zfs_allow_mirrors()
|
||||
{
|
||||
while read addr user ssh_port zroot; do
|
||||
echo "=== $user@$addr $zroot ==="
|
||||
if [ $zroot ]; then
|
||||
case $zroot in
|
||||
*"/") ;;
|
||||
*) zroot="$zroot/" ;;
|
||||
esac
|
||||
fi
|
||||
if [ $BG_TEST_MODE = "TRUE" ]; then
|
||||
echo ssh -i ~/.ssh/id_rsa -o port=$ssh_port $user@$addr \
|
||||
"for dataset in $SEND_DATASETS; do
|
||||
zfs allow -u $user $MIRROR_PERMS $zroot/\$dataset
|
||||
zfs allow -u $user $MIRROR_PERMS $zroot\$dataset
|
||||
done"
|
||||
else
|
||||
ssh -i ~/.ssh/id_rsa -o port=$ssh_port $user@$addr \
|
||||
"for dataset in $SEND_DATASETS; do
|
||||
zfs allow -u $user $MIRROR_PERMS $zroot/\$dataset
|
||||
zfs allow -u $user $MIRROR_PERMS $zroot\$dataset
|
||||
done"
|
||||
fi
|
||||
done < sendnodes.tmp
|
||||
@ -134,17 +152,23 @@ send_latest()
|
||||
{
|
||||
while read addr user ssh_port zroot; do
|
||||
echo "=== $user@$addr $zroot ==="
|
||||
if [ $zroot ]; then
|
||||
case $zroot in
|
||||
*"/") ;;
|
||||
*) zroot="$zroot/" ;;
|
||||
esac
|
||||
fi
|
||||
for dataset in $SEND_DATASETS; do
|
||||
origin_snapshot=`get_latest_snapshot $dataset`
|
||||
if [ $BG_TEST_MODE = "TRUE" ]; then
|
||||
echo zfs send $ZFS_SEND_OPTS $dataset@$origin_snapshot \| \
|
||||
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
|
||||
zfs send $ZFS_SEND_OPTS $dataset@$origin_snapshot |
|
||||
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
|
||||
done
|
||||
done < sendnodes.tmp
|
||||
@ -154,6 +178,12 @@ send_increment()
|
||||
{
|
||||
while read addr user ssh_port zroot; do
|
||||
echo "=== $user@$addr $zroot ==="
|
||||
if [ $zroot ]; then
|
||||
case $zroot in
|
||||
*"/") ;;
|
||||
*) zroot="$zroot/" ;;
|
||||
esac
|
||||
fi
|
||||
for dataset in $SEND_DATASETS; do
|
||||
origin_snapshot=`get_latest_snapshot`
|
||||
remote_snapshot=`get_latest_remote_snapshot`
|
||||
@ -162,13 +192,13 @@ send_increment()
|
||||
-i $dataset@$remote_snapshot \
|
||||
$dataset@$origin_snapshot \| \
|
||||
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
|
||||
zfs send $ZFS_SEND_OPTS \
|
||||
-i $dataset@$remote_snapshot \
|
||||
$dataset@$origin_snapshot |
|
||||
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
|
||||
done
|
||||
done < sendnodes.tmp
|
||||
|
Loading…
Reference in New Issue
Block a user