Reputation: 183
Hi I wrote a bash script for my backup procedure and i monitor a folder and sync the target dir to this folder every month and the changes to a mother dir every day.
I want the second rsync process to start after the first has finished I implemented it with the wait command, but it doesn't work:
if [ ! -f $MONTH_COMPARE/monat-$MONTH-compare.log ]; then
rsync -avh --force --delete --update --log-file=$MONTH_COMPARE/monat-$MONTH-compare.log $SOURCE_LOC $MONTH_COMPARE &
fi
wait
if [[ $MONTH -eq 1] && [ $DAY -eq 1]]; then
rm -rf $BACKUP_DIR/$LASTYEAR/12
mkdir $BACKUP_DIR/$LASTYEAR/12
#compare changes of last month to backup year month
rsync -avh --force --ignore-errors --log-file=$BACKUP_DIR/$LASTYEAR/12/monat-$MONTH.log --compare-des=$MONTH_COMPARE $SOURCE_LOC $BACKUP_DIR/$LASTYEAR/12 &&
#update aktuell with day changes
rsync -avh --force --ignore-errors --delete --update --log-file=$BACKUP_DIR/$YEAR/$MONTH/$DAY/tag-$DAY.log --backup-dir=$BACKUP_DIR/$YEAR/$MONTH/$DAY $SOURCE_LOC $TARGET_DIR &&
#update the month compare folder da 1. des neuen monats
rsync -avh --force --ignore-errors --delete --update --log-file=$MONTH_COMPARE/monat-$MONTH-compare.log $SOURCE_LOC $MONTH_COMPARE &
fi
wait
how to accomplish this?
Upvotes: 2
Views: 3178
Reputation: 40539
You are running rsync in the background (&) and then waiting for it. Why not just run it normally (without the &) and so you won't need to wait. The next command will only execute after the first rsync is finished.
Upvotes: 2