mirror of
https://asciireactor.com/o4data/zfs-backup.git
synced 2024-11-21 22:25:06 +00:00
Added remote zfs option.
This commit is contained in:
parent
f3b0b48a76
commit
1397c9c127
46
backup.sh
46
backup.sh
@ -9,9 +9,9 @@ nodes_file="nodes.txt"
|
||||
|
||||
datasets_file="datasets.txt"
|
||||
### datasets.txt
|
||||
# <dataset 1>
|
||||
# <dataset 2>
|
||||
# <dataset 3>
|
||||
# <dataset 1> [remote dataset]
|
||||
# <dataset 2> [remote dataset]
|
||||
# <dataset 3> [remote dataset]
|
||||
# ...
|
||||
|
||||
if [ ! -f $nodes_file ]; then echo "No nodes specified."; exit 2; fi
|
||||
@ -40,12 +40,14 @@ while read dataset dataset_options; do
|
||||
|
||||
snapshot_dataset="yes"
|
||||
send_dataset="yes"
|
||||
case $dataset_options in
|
||||
*"nosnap"* ) snapshot_dataset="";;
|
||||
esac
|
||||
case $dataset_options in
|
||||
*"nosend"* ) send_dataset="";;
|
||||
esac
|
||||
for option in $dataset_options; do
|
||||
case $option in
|
||||
*"nosnap"* ) snapshot_dataset="" ;;
|
||||
*"nosend"* ) send_dataset="" ;;
|
||||
*"remotezfs="*) remotezfs=`echo $option|cut -d'=' -f2` ;
|
||||
dataset="$dataset:$remotezfs" ;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ $send_dataset ]; then
|
||||
SEND_DATASETS="$SEND_DATASETS $dataset"
|
||||
@ -58,6 +60,7 @@ done < datasets.txt
|
||||
list_datasets()
|
||||
{
|
||||
for dataset in $SEND_DATASETS; do
|
||||
dataset=`echo $dataset|cut -d':' -f1`
|
||||
zfs list -H $dataset
|
||||
done
|
||||
}
|
||||
@ -73,13 +76,15 @@ list_remote_datasets() {
|
||||
fi
|
||||
if [ $BG_TEST_MODE = "TRUE" ]; then
|
||||
echo ssh $SSH_SEND_OPTS -o port=$ssh_port $user@$addr\
|
||||
"sh -c 'for dataset in $SEND_DATASETS;
|
||||
do zfs list -H $zroot\$dataset;
|
||||
"sh -c 'for dataset in $SEND_DATASETS; do
|
||||
dataset=`echo \\$dataset|cut -d':' -f2`
|
||||
zfs list -H $zroot\$dataset;
|
||||
done'"
|
||||
else
|
||||
ssh $SSH_SEND_OPTS -o port=$ssh_port $user@$addr \
|
||||
"sh -c 'for dataset in $SEND_DATASETS;
|
||||
do zfs list -H $zroot\$dataset;
|
||||
"sh -c 'for dataset in $SEND_DATASETS; do
|
||||
dataset=`echo \\$dataset|cut -d':' -f2`
|
||||
zfs list -H $zroot\$dataset;
|
||||
done';"
|
||||
fi
|
||||
done < sendnodes.tmp
|
||||
@ -106,6 +111,7 @@ get_latest_remote_snapshot()
|
||||
zfs_allow_origin()
|
||||
{
|
||||
for dataset in $SEND_DATASETS; do
|
||||
dataset=`echo $dataset|cut -d':' -f1`
|
||||
if [ $BG_TEST_MODE = "TRUE" ]; then
|
||||
echo zfs allow -u $LOCAL_USER $ORIGIN_PERMS $dataset
|
||||
else
|
||||
@ -127,11 +133,13 @@ zfs_allow_mirrors()
|
||||
if [ $BG_TEST_MODE = "TRUE" ]; then
|
||||
echo ssh $SSH_SEND_OPTS -o port=$ssh_port $user@$addr \
|
||||
"for dataset in $SEND_DATASETS; do
|
||||
dataset=`echo \\$dataset|cut -d':' -f2`
|
||||
zfs allow -u $user $MIRROR_PERMS $zroot\$dataset
|
||||
done"
|
||||
else
|
||||
ssh $SSH_SEND_OPTS -o port=$ssh_port $user@$addr \
|
||||
"for dataset in $SEND_DATASETS; do
|
||||
dataset=`echo \\$dataset|cut -d':' -f2`
|
||||
zfs allow -u $user $MIRROR_PERMS $zroot\$dataset
|
||||
done"
|
||||
fi
|
||||
@ -161,18 +169,20 @@ send_latest()
|
||||
esac
|
||||
fi
|
||||
for dataset in $SEND_DATASETS; do
|
||||
dataset=`echo $dataset|cut -d':' -f1`
|
||||
remote_dataset=`echo $dataset|cut -d':' -f2`
|
||||
origin_snapshot=`get_latest_snapshot $dataset`
|
||||
if [ $BG_TEST_MODE = "TRUE" ]; then
|
||||
echo zfs send $ZFS_SEND_OPTS $dataset@$origin_snapshot \| \
|
||||
pv -qL $BANDWIDTH_LIMIT \| \
|
||||
ssh $SSH_SEND_OPTS -o port=$ssh_port $user@$addr \
|
||||
zfs recv $ZFS_RECV_OPTS $zroot$dataset
|
||||
zfs recv $ZFS_RECV_OPTS $zroot$remote_dataset
|
||||
else
|
||||
zfs send $ZFS_SEND_OPTS $dataset@$origin_snapshot |
|
||||
pv -qL $BANDWIDTH_LIMIT |
|
||||
ssh $SSH_SEND_OPTS -o port=$ssh_port \
|
||||
$user@$addr \
|
||||
zfs recv $ZFS_RECV_OPTS $zroot$dataset
|
||||
zfs recv $ZFS_RECV_OPTS $zroot$remote_dataset
|
||||
fi
|
||||
done
|
||||
done < sendnodes.tmp
|
||||
@ -189,6 +199,8 @@ send_increment()
|
||||
esac
|
||||
fi
|
||||
for dataset in $SEND_DATASETS; do
|
||||
dataset=`echo $dataset|cut -d':' -f1`
|
||||
remote_dataset=`echo $dataset|cut -d':' -f2`
|
||||
origin_snapshot=`get_latest_snapshot`
|
||||
remote_snapshot=`get_latest_remote_snapshot`
|
||||
if [ $BG_TEST_MODE = "TRUE" ]; then
|
||||
@ -197,14 +209,14 @@ send_increment()
|
||||
$dataset@$origin_snapshot \| \
|
||||
pv -qL $BANDWIDTH_LIMIT \| \
|
||||
ssh $SSH_SEND_OPTS -o port=$ssh_port $user@$addr \
|
||||
zfs recv $ZFS_RECV_OPTS $zroot$dataset
|
||||
zfs recv $ZFS_RECV_OPTS $zroot$remote_dataset
|
||||
else
|
||||
zfs send $ZFS_SEND_OPTS \
|
||||
-i $dataset@$remote_snapshot \
|
||||
$dataset@$origin_snapshot |
|
||||
pv -qL $BANDWIDTH_LIMIT |
|
||||
ssh $SSH_SEND_OPTS -o port=$ssh_port $user@$addr \
|
||||
zfs recv $ZFS_RECV_OPTS $zroot$dataset
|
||||
zfs recv $ZFS_RECV_OPTS $zroot$remote_dataset
|
||||
fi
|
||||
done
|
||||
done < sendnodes.tmp
|
||||
|
Loading…
Reference in New Issue
Block a user