ofl import database script
#! /bin/bash
db_name='ofl_local'
remotedb='https://s3-eu-west-1.amazonaws.com/jbgbackups/ofldotcom/ofldotcom.sql.dump.gz'
cd /var/www/vhosts/oakfurnitureland.com/production/htdocs
wget $remotedb
echo "...Unzip ofl database"
gunzip ofldotcom.sql.dump.gz
mv ofldotcom.sql.dump export.sql
echo "...Remove DB (if exists)"
/usr/bin/mysqladmin -uroot -proot drop $db_name
echo "...Re-add DB"
/usr/bin/mysqladmin -hlocalhost -uroot -proot create $db_name
echo "...Find and replace on database"
sed -i "s|www.oakfurnitureland.com|ofl-local.space48.com|g" ./export.sql
sed -i "s|oakfurnitureland.com|ofl-local.space48.com|g" ./export.sql
echo "...Import production database to local"
/usr/bin/mysql -hlocalhost -uroot -proot $db_name < ./export.sql
echo "...Disabling google analytics"
mysql -u root -proot -e "UPDATE ofl_local.core_config_data SET value='0' WHERE path='google/analytics/active'"
mysql -u root -proot -e "UPDATE ofl_local.core_config_data SET value='0' WHERE path='googletagmanager/googletagmanager/enabled'"
echo "...Clean up files on local"
rm -f export.sql
rm -f ofldotcom.sql.dump
rm -f ofldotcom.sql.dump.gz