Keeping Development and Production Environments in Sync - pulibrary/pul_library_drupal GitHub Wiki
Generally you wish to clone the Drupal database and site asset files from the production environment to your local development environment. You'll want to set up a drush alias for both your local development site and the remote production in order to keep the commands concise.
Set Up Drush Aliases
In this case we'll do a production alias called "libraryprod" and local development alias called "liblocal". These should be recorded in a file called "aliases.drushrc.php" in your $HOME/.drush directory.
libraryprod
(includes a reference an SSH keypair registered as an authorized key on the production server)
$aliases['libraryprod'] = array(
'uri' => 'http://library.princeton.edu',
'root' => '/var/www/apps/library',
'remote-host' => 'library-prod.princeton.edu',
'remote-user' => 'drupal',
'ssh-options' => '-o PasswordAuthentication=no -i /Users/kevinreiss/.ssh/my_private_ssh_key',
'path-aliases' => array(
'%dump-dir' => '/var/www/backups/prod/',
'%dump' => '/var/www/backups/prod_sql_sync_dump.sql',
'%sites' => '/var/www/apps/library/sites/',
'%files' => 'sites/default/files',
),
'databases' =>
array (
'default' =>
array (
'default' =>
array (
'driver' => 'mysql',
'username' => 'library_prod',
'password' => 'db-password',
'port' => '3306',
'host' => 'localhost',
'database' => 'library_prod',
),
),
),
'command-specific' => array (
'sql-sync' => array (
'simulate' => '1',
),
'rsync' => array (
'simulate' => '0',
),
),
);
librarystage
$aliases['librarystage'] = array(
'uri' => 'http://library-stage.princeton.edu',
'root' => '/var/www/apps/library-stage',
'remote-host' => 'library-dev.princeton.edu',
'remote-user' => 'drupal',
'ssh-options' => '-o PasswordAuthentication=no -i /Users/my-username-/.ssh/drupal_library_stage',
'path-aliases' => array(
'%dump-dir' => '/var/www/backups/stage/',
'%dump' => '/var/www/backups/stage_sql_sync_dump.sql',
'%sites' => '/var/www/apps/library-stage/sites/',
'%files' => 'sites/default/files',
),
'databases' =>
array (
'default' =>
array (
'default' =>
array (
'driver' => 'mysql',
'username' => 'db_user',
'password' => 'db_password',
'port' => '3306',
'host' => 'localhost',
'database' => 'library_stage',
),
),
),
'command-specific' => array (
'sql-sync' => array (
'simulate' => '0',
),
'rsync' => array (
'simulate' => '0',
),
),
);
librarytest
$aliases['librarytest'] = array(
'uri' => 'http://library-test.princeton.edu',
'root' => '/var/www/apps/library-test',
'remote-host' => 'library-dev.princeton.edu',
'remote-user' => 'drupal',
'ssh-options' => '-o PasswordAuthentication=no -i /Users/my-username/.ssh/drupal_library_stage',
'path-aliases' => array(
'%dump-dir' => '/var/www/backups/test/',
'%dump' => '/var/www/backups/test_sql_sync_dump.sql',
'%sites' => '/var/www/apps/library-test/sites/',
'%files' => 'sites/default/files',
),
'databases' =>
array (
'default' =>
array (
'default' =>
array (
'driver' => 'mysql',
'username' => 'db-user',
'password' => 'db-password',
'port' => '3306',
'host' => 'localhost',
'database' => 'library_test',
),
),
),
'command-specific' => array (
'sql-sync' => array (
'simulate' => '0',
),
'rsync' => array (
'simulate' => '0',
),
),
);
liblocal
(your local development site)
$aliases['liblocal'] = array(
'root' => '/Users/kevinreiss/Projects/librarycore/pul_library_drupal',
'uri' => 'http://liblocal.princeton.edu',
'path-aliases' => array(
'%dump-dir' => '/Users/KevinReiss/Projects/librarycore',
'%dump' => '/Users/KevinReiss/Projects/librarycore/sql_sync_dump.sql',
'%sites' => '/Users/KevinReiss/Projects/librarycore/pul_library_drupal/sites/',
'%files' => 'sites/default/files',
),
'command-specific' => array (
'sql-sync' => array (
'simulate' => '0',
'structure-tables' => array(
'custom' => array('cache', 'cache_filter', 'cache_menu', 'cache_page', 'history', 'watchdog'),
),
),
'rsync' => array (
'simulate' => '0',
'mode' => 'rlptDz',
),
),
);
Keeping the database in sync
Run the following sql-sync command that pulls the production database down to your local environment. All data in your local environment will be overwritten.
> drush sql-sync @libraryprod @liblocal
You will destroy data in library_prod and replace with data from library-prod.princeton.edu/library_prod.
You might want to make a backup first, using the sql-dump command.
Do you really want to continue? (y/n): y
Keeping the file system in sync
Run the following rsync command referencing the sites/default/files directory of each site. All files in your local environment will be overwritten.
> drush rsync @libraryprod:%files/ @liblocal:%files
You will destroy data from /Users/kevinreiss/Projects/librarycore/pul_library_drupal/sites/default/files and replace with data from [email protected]:/var/www/apps/library/sites/default/files/
Do you really want to continue? (y/n): y
What Drush Aliases are available
The command "drush sa" will always report back a list of available aliases.
Example Output:
> drush sa
liblocal
libraryprod
librarystage
none
rbsc-dev
rbsc-local
rbsc-stage
self
test
transcriptions