Using SQL-sync & rsync in Drush
An often unsung advantage that Drush can give you is the ability to quickly sync your Drupal installations between multiple environments.
One of main draws to Drush is the library's ability to make developer lives easier. There are two simple commands that work using Drush aliases that can help sync database and files between multiple Drupal instances. First we'll go over setting up an alias file for Drush. After that, we'll document the usage of Drush's SQL-sync and rsync commands.
Create a file to store your aliases that is readable by Drush.
If it does not exist already, create a .drush folder in your home directory.
$ mkdir ~/.drush
Create an aliases file for the current project that you are setting up
$ vim ~/.drush/aliases.drushrc.php
You can call this file WHATEVER.aliases.drushrc.php or even just put this code in your drushrc.php file. One tactic might be to divide *.aliases.drushrc.php into different files per-project or per-environment Shown below is a template for setting up a local and remote alias for a given site. The 'local' alias is configured for OSX while the 'remote' aliases are configured for Ubuntu.
Your actual configuration will vary, but this should suffice as an example:
Using the $aliases array, one can define as many aliases as they need. There are three aliases listed above. A 'parent' alias can be created and child aliases can inherit their parent's attributes. In the example, 'remote' is a parent to the 'prometsource.dev' alias. This can be very useful if you want to create aliases for multiple sites that are hosted by the same environment. Now that we have aliases defined for our remote and local Drupal sites, we can sync database and files between them.
Import the remote database to your local database
$ drush SQL-sync @prometsource.dev @prometsource.local
There are many --flags for drush SQL-sync listed here: http://drush.ws/#SQL-sync One of the most important ones to note is '--no-cache' - you will find this flag useful if you are syncing your database more than once every 24 hrs and you want to be using a new db dump rather than a cached version of the db dump. Note that we defined a '%dump-dir' in our aliases settings. You can find recent db dumps in this folder. Drush must have permissions to write to the folder in order to successfully SQL-sync your db dump.
Import the remote files to your local files folder
$ drush rsync @prometsource.dev:%files/ @prometsource.local:%files
This command will pull down the entire files directory from the remote site to the local site. This may take quite some time. Drush does not provide any indication that it is working outside of holding up your command line interface from accepting a new command until it is done. You can use a network monitor, such as the program that comes with OSX utilites, to actually see the files being downloaded and track progress. There are many --flags for drush rsync as well, and they are listed here: http://drush.ws/#core-rsync
Generally, we do not condone a workflow that calls for consistent SQL-sync back and forth between development to staging and production sites. However, these commands can be very useful for setting up a new local testing environment from an existing project. The value of being able to automatically sync files and database should be apparent at this point!