Reputation: 183
hi i want to create a backup rsync script, and i want to create a additional copy of the sate of one folder at the beginning of the month and compare the changes to the end of the month my questing: ho can i run a rsync job after the previous has finished, so i don't delete the backup dir bevor i compared the changes and backed them up?
for now if have:
if [ $MONTH -eq 1] && [ $DAY -eq 1]; then
rsync -a --forece --ignore-errors --compare-des=$MONTH_COMPARE $EXCLUDE_STRING $SOURCE_LOC ssh $TARGET_DIR/$LASTYEAR/12
rsync -a --forece --ignore-errors --delete --update $EXCLUDE_STRING $SOURCE_LOC ssh $MONTH_COMPARE
it is important, that the second you doesn't start bevor the fist one has finished
Upvotes: 1
Views: 1102
Reputation: 650
Delimine both rsync
commands with &&
operator.
This operator ensures, that the second command executes only if the fist one is finished succesfully (returns exit code 0).
So, your code will be
if [ $MONTH -eq 1] && [ $DAY -eq 1]; then
rsync -a --forece --ignore-errors --compare-des=$MONTH_COMPARE $EXCLUDE_STRING $SOURCE_LOC ssh $TARGET_DIR/$LASTYEAR/12 &&
rsync -a --forece --ignore-errors --delete --update $EXCLUDE_STRING $SOURCE_LOC ssh $MONTH_COMPARE
You can also put those rsync
lines into standalone script and launch it with cron
on desired time, so you would not need the date condition.
Upvotes: 1