Last active
November 2, 2017 00:39
-
-
Save fribibb/f9deb6ff53178ea36ccd to your computer and use it in GitHub Desktop.
govCMS Site Sync
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Expects x paramters (drush alias of remote site | netXXX number | docroot of local instance | DB name) | |
# e.g. bash ~/govcms-site-sync.sh govcms.sprintgovcms.govcms.acsitefactory.com 2111 ~/Desktop/govCMS/govcms.local govcms | |
clear | |
if [ "$#" != "4" ]; then | |
echo "Requires 4 Paramters: " | |
echo "{drush alias} {netXXX number - get this from source code of ACSF site} {docroot of local instance} {DB name}" | |
echo "e.g. ~/govcms-site-sync.sh govcms.sprintgovcms.govcms.acsitefactory.com 2111 ~/Desktop/govCMS/govcms.local govcms" | |
else | |
ALIAS="$1" | |
NET_FILE="$2" | |
DOCROOT="$3" | |
DBNAME="$4" | |
SQL_DUMP="/tmp/govcms_remote.sql" | |
echo "⏳ SQL Sync" | |
echo " Downloading SQL dump" | |
drush @$ALIAS sql-dump > $SQL_DUMP || echo "⚠️ Error downloading SQL dump" | |
echo " Tidying up SQL export" | |
# removes warning that tends to apear as the first line of the export | |
sed -i.bak '/Warning: Using a password on the command line interface can be insecure./d' $SQL_DUMP | |
echo " Importing SQL" | |
drush -r $DOCROOT sql-cli < $SQL_DUMP || echo "⚠️ Error importing SQL dump" | |
echo " Deleting SQL" | |
rm $SQL_DUMP || echo "⚠️ Error deleting temporary SQL dump" | |
rm $SQL_DUMP.bak || echo "⚠️ Error deleting backup SQL dump" | |
echo "☑️ " | |
echo "" | |
echo "⏳ Files Sync" | |
drush -y -r $DOCROOT rsync -avz @$ALIAS:/var/www/html/govcms.01live/docroot/sites/g/files/net$NET_FILE/f/ $DOCROOT/sites/default/files/ | |
mkdir -p $DOCROOT/sites/g/files/net$NET_FILE | |
ln -s $DOCROOT/sites/default/files $DOCROOT/sites/g/files/net$NET_FILE/f &> /dev/null | |
# creates symlinks so theme imgs etc work locally | |
mkdir -p $DOCROOT/sites/g/files/net$NET_FILE/themes/site/ >> /dev/null | |
ln -s $DOCROOT/sites/all/themes/ $DOCROOT/sites/g/files/net$NET_FILE/themes/site >> /dev/null | |
echo "☑️ " | |
echo "" | |
# Stops the "The following module is missing from the file system: acsf"* warnings from showing up locally | |
echo "⏳ Remove ACSF plugin rows from DB" | |
cd $DOCROOT | |
echo "DELETE FROM system WHERE name LIKE 'acsf%';" | $(drush sql-connect) && drush cc all | |
echo "☑️ " | |
echo "" | |
echo "⏳ Remove govCMS tweaks plugin row from DB" | |
cd $DOCROOT | |
echo "DELETE FROM system WHERE name LIKE 'govcms_tweaks';" | $(drush sql-connect) && drush cc all | |
echo "☑️ " | |
echo "" | |
echo "⏳ Disable Shield and set tmp dir" | |
cd $DOCROOT | |
drush dis shield -y | |
drush vset "file_temporary_path" "/tmp/" | |
echo "☑️ " | |
echo "" | |
echo "⏳ Clear and disable Caches" | |
cd $DOCROOT | |
drush cc all | |
drush vset cache 0 --yes | |
drush vset preprocess_css 0 --yes | |
drush vset preprocess_js 0 --yes | |
echo "☑️ " | |
echo "" | |
echo "⏳ Truncating DB cache tables" | |
cd $DOCROOT | |
echo "SHOW TABLES LIKE 'cache%'" | $(drush sql-connect) | tail -n +2 | xargs -L1 -I% echo "DELETE FROM %;" | $(drush sql-connect) | |
echo "☑️ " | |
echo "" | |
echo "✅ Done." | |
date | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment