I am attempting to make a backup script for my websites but i am having issues with a nested for loop
BACKUP_DIR="/path/to/output"
WEB_DIR="/srv/http"
WEBSITES=($WEB_DIR/website_one $WEB_DIR/website_two)
MYSQLDBS=(database_one database_two)
for WEBSITEBACKUP in $WEBSITES
do
# tar commands here for website directories
for DATABASEBACKUP in $MYSQLDBS
do
# mysql dump commands here for databases
break
done
done
I was hoping that loop 1 would backup the website, then open loop 2 which would backup the database then break out of the inner loop and continue to backup website 2 but once it gets to the inner for loop the second time it backs up the first database again.
My question is, how can i get the nested loop to increment until all databases in the array have been backed up successfully, or is there another way i have overlooked?
For anyone who is wondering, the reason why the databases aren't being backed up in their own for loop is because i am getting the folder name from $WEBSITEBACKUP and i would like the store the databases in the same directory as their website.
CURRENT_BACKUP=`echo $WEBSITEBACKUP | sed "s|\$WEB_DIR||g" | tr "/" "-" | cut -b2-`