Upgrade Your Drupal Skills

We trained 1,000+ Drupal Developers over the last decade.

See Advanced Courses NAH, I know Enough

My sync2dev script on Mac

Parent Feed: 

Submitted by clemens on Mon, 2016/05/09 - 12:58pm

We could use the several drush + shell commands manually but why not script this? This is how I do this on Mac OSX which has it's own quirks.

Place the follow script into the parent dir of your drupal root as sync2dev. This way you can control all you DEV sites in a similar way. ../sync2dev

Content of sync2dev by https://twitter.com/ClemensTolboom

# Show commands executed
set -x

# --simulate does not work
# DRUSH_OPTS="--yes --verbose --simulate"

# Say yes to the dress
DRUSH_OPTS="--yes"

# --no does not work for registry-rebuild or features-status
# DRUSH_OPTS="--no"

# simulate seems gone as an option
# DRUSH_OPTS="--simulate"

# Source alias
[email protected]
# [email protected]

# Target
[email protected]
DRUPAL_ROOT=/Users/clemens/Sites/my-site/dev/www

# Where to find the files
SITE_DIR=default

# What user and group to set
USER=clemens
GROUP=_www

# Make sure sudo command is executable later on
sudo echo "Thanks."

# Sync database
drush $DRUSH_OPTS $DRUSH_ALIAS_DEV sql-drop
drush $DRUSH_OPTS sql-sync $DRUSH_ALIAS_REMOTE $DRUSH_ALIAS_DEV

# Fix before receiving files
sudo chown -R $USER $DRUPAL_ROOT/sites/$SITE_DIR/files
sudo chown -R $USER $DRUPAL_ROOT/sites/$SITE_DIR/private
sudo chgrp -R $GROUP $DRUPAL_ROOT/sites/$SITE_DIR/files

# Get the files
drush $DRUSH_OPTS rsync $DRUSH_ALIAS_REMOTE:%files $DRUSH_ALIAS_DEV:%files

# Fix after receiving
sudo chown -R $USER $DRUPAL_ROOT/sites/$SITE_DIR/files
sudo chown -R $USER $DRUPAL_ROOT/sites/$SITE_DIR/private
sudo chgrp -R $GROUP $DRUPAL_ROOT/sites/$SITE_DIR/files

# Drupal 7 variant of cache-rebuild
drush $DRUSH_OPTS $DRUSH_ALIAS_DEV registry-rebuild

# Login to site
drush $DRUSH_OPTS $DRUSH_ALIAS_DEV user-login

# Make sure drush finds the features drush extension
drush cc drush

# List features with changes
drush $DRUSH_OPTS $DRUSH_ALIAS_DEV features-list --state=db
Author: 
Original Post: 

About Drupal Sun

Drupal Sun is an Evolving Web project. It allows you to:

  • Do full-text search on all the articles in Drupal Planet (thanks to Apache Solr)
  • Facet based on tags, author, or feed
  • Flip through articles quickly (with j/k or arrow keys) to find what you're interested in
  • View the entire article text inline, or in the context of the site where it was created

See the blog post at Evolving Web

Evolving Web