fix zsc-sync.sh

This commit is contained in:
Alice Gaudon 2021-03-04 15:22:33 +01:00
parent b2069ce598
commit b2ef084b4e

View File

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