Skip to content

Instantly share code, notes, and snippets.

@stirtingale
Created June 3, 2019 08:45
Show Gist options
  • Save stirtingale/61713b4de3d93de9382a455409d1928f to your computer and use it in GitHub Desktop.
Save stirtingale/61713b4de3d93de9382a455409d1928f to your computer and use it in GitHub Desktop.
Sync DB Script
#!/bin/bash
#
#
SITELIST=~/dbbackup/sitelist-wp-sites.sdata
find ~/public_html -type f -name wp-config.php -print > ${SITELIST}
while read LINE
do
USER=`whoami`
NEWUSERDB=`whoami`'_wp'
DBNAME=`cat ${LINE} | grep DB_NAME | cut -d \' -f 4`
DBUSER=`cat ${LINE} | grep DB_USER | cut -d \' -f 4`
DBPWD=`cat ${LINE} | grep DB_PASSWORD | cut -d \' -f 4`
# set up new user/password
perl -pi -e "s/$DBNAME/$NEWUSERDB/g" ${LINE}
perl -pi -e "s/$DBUSER/$NEWUSERDB/g" ${LINE}
# create DB
uapi Mysql create_database name="$NEWUSERDB"
uapi Mysql create_user name="$NEWUSERDB" password="$DBPWD"
uapi Mysql set_privileges_on_database user="$NEWUSERDB" database="$NEWUSERDB" privileges=ALL
# import
DBBACKUPFILE=~/migrate.sql
/usr/bin/mysql -u ${NEWUSERDB} -p${DBPWD} $NEWUSERDB < $DBBACKUPFILE
# CLEAN UP
rm ~/migrate.sql
rm ~/migrateinflate.sh
done < ${SITELIST}
#
# End of file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment