From 1397c9c127c80716a864533cf074b5cf9b93f0b0 Mon Sep 17 00:00:00 2001 From: Otho Date: Mon, 16 Jan 2023 19:19:06 -0500 Subject: [PATCH] Added remote zfs option. --- backup.sh | 46 +++++++++++++++++++++++++++++----------------- 1 file changed, 29 insertions(+), 17 deletions(-) diff --git a/backup.sh b/backup.sh index 9b87220..e30ea7c 100755 --- a/backup.sh +++ b/backup.sh @@ -9,9 +9,9 @@ nodes_file="nodes.txt" datasets_file="datasets.txt" ### datasets.txt -# -# -# +# [remote dataset] +# [remote dataset] +# [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