diff --git a/zsc-sync.sh b/zsc-sync.sh index fa1e245..d89ec71 100755 --- a/zsc-sync.sh +++ b/zsc-sync.sh @@ -28,12 +28,13 @@ fi handle_dataset() { DATASET=$1 - D=$2 - W=$3 - M=$4 - Y=$5 + RECURSIVE=$2 + D=$3 + W=$4 + M=$5 + Y=$6 - PREFIX=$6 + PREFIX=$7 if test -z "$PREFIX"; then PREFIX="zsc-" fi @@ -42,14 +43,10 @@ handle_dataset() { PREFIX="" fi - RECURSIVE=$7 - if [ $recusive = 'true' ]; then - echo "Recursive" - fi - TARGET_REMOTE_DATASET="$REMOTE_ROOT_DATASET/"$(echo -e $DATASET | sed -r "s/\//_/g") - echo "--- $DATASET -> $TARGET_REMOTE_DATASET ---" + echo "[$DATASET -> $TARGET_REMOTE_DATASET]" + echo -e ### Resume existing transfer ### @@ -68,6 +65,7 @@ handle_dataset() { echo "Remote snapshots: ${#REMOTE_SNAPSHOTS[@]}" echo "Local snapshots: ${#LOCAL_SNAPSHOTS[@]}" + echo -e for local_snapshot in "${LOCAL_SNAPSHOTS[@]}"; do echo "Syncing local snapshot $local_snapshot ..." @@ -87,9 +85,12 @@ handle_dataset() { echo "> Needs sync" TO_SNAPSHOT=$local_snapshot fi + + echo -e done echo "Snapshot are synchronized up to $FROM_SNAPSHOT" + echo -e if test ! -z "$TO_SNAPSHOT"; then echo "Synchronizing snapshots from $FROM_SNAPSHOT to $TO_SNAPSHOT ..." @@ -97,16 +98,18 @@ handle_dataset() { if test ! -z "$FROM_SNAPSHOT"; then incr="-I $FROM_SNAPSHOT" fi - if [ $recusive = 'true' ]; then + if [ $RECURSIVE = true ] ; then recu="-R" fi - zfs send -v -p $recu $incr $TO_SNAPSHOT | ssh $REMOTE zfs receive -F -s $TARGET_REMOTE_DATASET || return 1 + zfs send -v -p $recu $incr "$DATASET@$TO_SNAPSHOT" | ssh $REMOTE zfs receive -F -s "$TARGET_REMOTE_DATASET" || return 1 echo "Done" fi } -cat "$ZSC_CONFIG" | while IFS=: read dataset recursive d w m y prefix; do + +for line in $(cat "$ZSC_CONFIG") ; do + IFS=: read dataset recursive d w m y prefix <<< "$line" echo "| ##### Dataset: $dataset Recursive: $recursive Prefix: $prefix d: $d w: $w m: $m y: $y #####" if [ $recursive = "true" ]; then @@ -119,7 +122,7 @@ cat "$ZSC_CONFIG" | while IFS=: read dataset recursive d w m y prefix; do #done fi - handle_dataset $dataset $d $w $m $y $prefix $recursive | awk '{print "| " $0}' || exit 1 + handle_dataset $dataset $recursive $d $w $m $y $prefix | awk '{print "| " $0}' || exit 1 echo -e "----------------------------------------------------------------------" done