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