Answer the question
In order to leave comments, you need to log in
Automating the transfer of hundreds of WordPress sites from one VPS to another?
We are moving from an old VPS to a new one - more powerful, but with less disk space. There are more than a hundred WordPress sites on the
old VPS You need to transfer selectively (not all of them) to the new VPS
Doing it manually is very tedious. I would like to automate this process as much as possible.
I'm thinking of creating a shell script with which I'll go through all the folders of the sites I need, put their database backups inside:
1) go through the selected folders inside the directory , I don't know how to do it, tell me?
2) for each site, define its database, since these are Wordpress sites, then:
you need to somehow read DB_USER, DB_PASSWORD, DB_NAME from wp-config.php
file in the folder of each site,
I think that the solution is here: https://stackoverflow.com/questions/7586995/read-v...
3) then the backup itself:
mysqldump -u USER -pPASSWORD DATABASE | gzip -9 > dump.sql.gz
rsync -rvp old_vps_path_site [email protected]:/new_vps_path_site
mysql -u root
create database $DB_NAME;
grant all privileges on $DB_NAME.* to [email protected]'localhost' identified by $DB_PASSWORD;
FLUSH PRIVILEGES;
gunzip < dump.sql.gz | mysql -hlocalhost -u$DB_USER -p$DB_PASSWORD $DB_NAME
rm -f dump.sql.gz
Answer the question
In order to leave comments, you need to log in
DEST_WWW_PATH="/path/to/www/folder"
CURRENT_PATH=$(pwd)
SITE_FOLDERS=("site.ru" "site2.ru")
for SITE_FOLDER in ${SITE_FOLDERS[@]}; do
CURRENT_FOLDER="${CURRENT_PATH}/${SITE_FOLDER}"
DB_NAME=$(/bin/grep -oP "define\(['\"]DB_NAME['\"],\s*['\"]\K[^'\"]+(?=[\'\"]\s*\)\s*;)" "${CURRENT_FOLDER}/wp-config.php")
DB_USER=$(/bin/grep -oP "define\(['\"]DB_USER['\"],\s*['\"]\K[^'\"]+(?=[\'\"]\s*\)\s*;)" "${CURRENT_FOLDER}/wp-config.php")
DB_PASSWORD=$(/bin/grep -oP "define\(['\"]DB_PASSWORD['\"],\s*['\"]\K[^'\"]+(?=[\'\"]\s*\)\s*;)" "${CURRENT_FOLDER}/wp-config.php")
/usr/bin/mysqldump -u $DB_USER -p$DB_PASSWORD $DB_NAME | /bin/gzip -9 > dump.sql.gz
/usr/bin/rsync -rvp [email protected]:"${DEST_WWW_PATH}/${SITE_FOLDER}/" $CURRENT_FOLDER
/bin/rm -f dump.sql.gz
done
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question