Created
August 15, 2017 03:01
-
-
Save jez500/120277b91f0d287c524b8180feb47439 to your computer and use it in GitHub Desktop.
Sync remote DB to local with backup, run composer, run compass, ready for new feature
This file contains hidden or 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
# Sync a D8 database and enable dev modules. | |
# Usage: sync_d8 [site folder] [site alias] [alias env to get db from] | |
# Example: sync_d8 boral boral dev | |
function sync_d8() { | |
local site="$1" | |
local alias="@$2" | |
local env="$3" | |
local site_dir=~/sites/"$site" | |
local backup_dir=~/sites/db_backups/"$site" | |
echo "=== Running $1 DB sync (with backup), composer install & config import ===" | |
# Dump the current DB | |
cd ${site_dir}/docroot | |
mkdir -p ${backup_dir} | |
drush sql-dump -y --gzip --result-file=${backup_dir}/local_latest_dump_$(date +%Y%m%d\-%H%M).sql | |
# Delete the oldest of 5 files | |
cd ${backup_dir} | |
ls -t | sed -e '1,3d' | xargs -d '\n' rm | |
# Drop the current DB | |
cd ${site_dir}/docroot | |
drush sql-drop -y | |
# Sync the local DB with UAT | |
drush sql-sync ${alias}.${env} @self -y | |
# Run composer updates | |
cd ${site_dir} | |
composer install | |
bin/phing compass:compile | |
# Import Drupal config | |
cd ${site_dir}/docroot | |
# drush cim -y | |
# Enable some dev modules (thanks to Jez) | |
drush en -y devel kint config_devel stage_file_proxy browsersync | |
# Create login link | |
drush ${alias}.local uli admin | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Expects your site to live in
~/sites/sitename
which contains adocroot
if this is not the case, update line 8 to reflect the local folder location