Syncing Environments Using Drush

Share this post

 

Now that you have learned what a helpful tool Drush can be for all Drupal developers, let’s think about how this, in combination with other command line tools, can make your jobs even easier. Any professional establishment will use version control and multiple environments, such as Sandbox (Development), Staging, and/or Production in order to maintain and modify code. In combination with Drush and some shell scripting, this can make for some very powerful tools.

When bringing a Drupal site from one environment to another there are generally three things to worry about:

  1. Code Base
  2. Database
  3. Media

Each part requires different tools to be used. The code base can be handled simply by using whatever version control is being utilized for the project. The database could be handled by mysql and the media using scp or rsync. If you have already set up aliases however, the last two steps can be handled rather easily using Drush.

  • drush sql-sync @production @dev
  • drush rsync @production:%files @dev:%files

If the alias files are set up correctly for each installation, these two commands will handle the last two parts. The above two commands will pull down the database on production and move it into the development environment. This saves a lot of time by not having to SSH into that environment’s server and move the files manually.

Making sure aliases are set up correctly is a key part in the database sync. There are options available that will allow you to ignore some tables. This is useful in the case of the Cache tables as well as Watchdog. For larger databases it has the potential to save some time.

Once you have the hang of the different functionalities, get creative and think about what could be automated in your current processes. Some suggestions include:

  • Updating client’s modules / Drupal core
  • Automatically generating aliases
  • Onboarding clients

The fact is, the possibilities are endless; and with a tool as versatile as Drush there is no limit to how it can help a Drupal developer with their work.

Insights

600+ articles to give you key insights for your projects

8 Simple Ways to Improve Your Website Security

8 Simple Ways to Improve Your Website Security

With cyber threats becoming increasingly sophisticated, it’s essential to implement robust security measures to safeguard your website and the sensitive information it holds.  You know that you need to keep your website safe from the bad guys, but once you venture...

The Dilemma of Estimates

The Dilemma of Estimates

Estimates serve as the cornerstone of any website project, providing clients with a roadmap for budgeting, planning, and expectation management. They offer a glimpse into the intricate tapestry of tasks, timelines, and resources needed to bring a website to life....

Config Sync Overview

Config Sync Overview

When Drupal 8 was released, it came with Configuration Syncing functionality. This has been a staple ever since for Drupal 9, Drupal 10, and beyond. Configuration Syncing was a game changer and one of my favorite features in Drupal Core. The days before config sync...