diff --git a/backup.sh b/backup.sh index 5e17821..d65df39 100755 --- a/backup.sh +++ b/backup.sh @@ -29,17 +29,33 @@ esac ORIGIN_PERMS="send,snapshot,hold" MIRROR_PERMS="compression,receive,create" -GRAPH_DATASETS_RAW=`cat $datasets_file` -GRAPH_DATASETS=`for dataset in $GRAPH_DATASETS_RAW; do +SEND_DATASETS="" +SNAPSHOT_DATASETS="" +while read dataset dataset_options; do case $dataset in \#*) continue;; esac - echo -n "$dataset " -done` + + snapshot_dataset="yes" + send_dataset="yes" + case $dataset_options in + *"nosnap"* ) snapshot_dataset="";; + esac + case $dataset_options in + *"nosend"* ) send_dataset="";; + esac + + if [ $send_dataset ]; then + SEND_DATASETS="$SEND_DATASETS $dataset" + fi + if [ $snapshot_dataset ]; then + SNAPSHOT_DATASETS="$SNAPSHOT_DATASETS $dataset" + fi +done < datasets.txt list_datasets() { - for dataset in $GRAPH_DATASETS; do + for dataset in $SEND_DATASETS; do zfs list -H $dataset done } @@ -49,12 +65,12 @@ list_remote_datasets() { echo "=== $user@$addr $zroot ===" if [ $BG_TEST_MODE = "TRUE" ]; then echo ssh -i ~/.ssh/id_rsa -o port=$ssh_port $user@$addr\ - "sh -c 'for dataset in $GRAPH_DATASETS; + "sh -c 'for dataset in $SEND_DATASETS; do zfs list -H $zroot/\$dataset; done'" else ssh -i ~/.ssh/id_rsa -o port=$ssh_port $user@$addr \ - "sh -c 'for dataset in $GRAPH_DATASETS; + "sh -c 'for dataset in $SEND_DATASETS; do zfs list -H $zroot/\$dataset; done';" fi @@ -75,7 +91,7 @@ get_latest_remote_snapshot() zfs_allow_origin() { - for dataset in $GRAPH_DATASETS; do + for dataset in $SEND_DATASETS; do if [ $BG_TEST_MODE = "TRUE" ]; then echo zfs allow -u $LOCAL_USER $ORIGIN_PERMS $dataset else @@ -90,12 +106,12 @@ zfs_allow_mirrors() echo "=== $user@$addr $zroot ===" if [ $BG_TEST_MODE = "TRUE" ]; then echo ssh -i ~/.ssh/id_rsa -o port=$ssh_port $user@$addr \ - "for dataset in $GRAPH_DATASETS; do + "for dataset in $SEND_DATASETS; do zfs allow -u $user $MIRROR_PERMS $zroot/\$dataset done" else ssh -i ~/.ssh/id_rsa -o port=$ssh_port $user@$addr \ - "for dataset in $GRAPH_DATASETS; do + "for dataset in $SEND_DATASETS; do zfs allow -u $user $MIRROR_PERMS $zroot/\$dataset done" fi @@ -105,7 +121,7 @@ zfs_allow_mirrors() create_snapshots() { snapshot_id="`date -I`-`date +%s`-$LOCAL_TZ" - for dataset in $GRAPH_DATASETS; do + for dataset in $SNAPSHOT_DATASETS; do if [ $BG_TEST_MODE = "TRUE" ]; then echo zfs snapshot $ZFS_SNAPSHOT_OPTS $dataset@$snapshot_id else @@ -118,7 +134,7 @@ send_latest() { while read addr user ssh_port zroot; do echo "=== $user@$addr $zroot ===" - for dataset in $GRAPH_DATASETS; do + 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 \| \ @@ -138,7 +154,7 @@ send_increment() { while read addr user ssh_port zroot; do echo "=== $user@$addr $zroot ===" - for dataset in $GRAPH_DATASETS; do + for dataset in $SEND_DATASETS; do origin_snapshot=`get_latest_snapshot` remote_snapshot=`get_latest_remote_snapshot` if [ $BG_TEST_MODE = "TRUE" ]; then