Skip to content

Instantly share code, notes, and snippets.

@chales
Last active October 28, 2021 20:58
Show Gist options
  • Save chales/2635760 to your computer and use it in GitHub Desktop.
Save chales/2635760 to your computer and use it in GitHub Desktop.
Drush aliases full featured base file for Local, Staging, Development and Production environments such as an Acquia or Pantheon hosted site. In this version the "structure-tables" array is setup for a Drupal 6 set of core tables and common contrib module tables (CCK and Views). You should modify the array and add or remove tables to match your b…
<?php
/**
* Setup This File:
* Look for strings wrapped in { } and update them to match your environments.
* e.g. {project-short-name} is the abreviation name to replace throughout.
*/
/**
* Site aliases for {project-short-name}
* Save this file as {project-short-name}.aliases.drushrc.php and place it
* inside you ~/.drush/ directory. (~/ means your home path)
*
* Some protection has been added to prevent accidental harm to production
* environments but please be careful!
*
* Drush commands are in the form of source-environment -> target-environment
* So for syncs that means "Copy From-environment over To-environment"
*/
/**
* Rsync Examples
*
* rsync Usage Examples:
* To sync files from the production site to your local site:
* $ drush rsync @{project-short-name}.prod:%files @{project-short-name}.local:%files
*
* To sync files from the prod site to staging site:
* $ drush rsync @{project-short-name}.prod:%files @{project-short-name}.stage:%files
*/
/**
* DB Sync Options and Examples
*
* Skipping Cache Table Data:
* Excluding cache table data, and some other unneeded data is set as a default
* but the table list should be updated periodically for projects under
* development. Several common tables for core and and contrib modules are
* listed but commented out.
*
* Sanitization:
* You can sanitize (secure) user email and passwords for security, to prevent
* spam from test updates, etc. This is done after the db has been downloaded if
* the target is remote (normally).
* See note in the local alias below to enable sanitization. Once enabled you
* you will be asked if you wish to sanitize the users after a local target sync.
*
* DB Dumps:
* sql-sync db dumps are normally cached for 24hrs and this has been overridden
* in this file so only fresh data is used.
* Dumps are sent to /tmp but can be changed in the below config.
* If you wish to retain dated sql dump files for backups see the note in the
* local site alias below.
*
* sql-sync Usage Examples:
* To copy the DB from the dev site to your local build:
* $ drush sql-sync @{project-short-name}.dev @{project-short-name}.local
*
* From production to your local build:
* $ drush sql-sync @{project-short-name}.prod @{project-short-name}.local
* $ drush sql-sync @{project-short-name}.dev @{project-short-name}.local
*/
/**
* Local alias
* Set the root, uri and path values to point to your local install.
* Enable optional settings if desired.
*/
$aliases['{project-short-name}.local'] = array(
// local path to docroot
'root' => '{/path/to/local-project}',
'uri' => '{local-uri}',
'path-aliases' => array(
'%dump-dir' => '/tmp',
'%files' => 'sites/default/files',
// Optional: Uncomment and specify a local path to retain db dumps.
#'%dump' => '~/Sites/drush-dumps/{project-short-name}-'. date('Ymd-His') .'.sql',
),
// Optional: Uncomment the sanitze option to sanitize the DB dump post sync.
// You will be given a y/n option for this.
'target-command-specific' => array (
'sql-sync' => array (
#'sanitize' => '1',
'confirm-sanitizations' => '1',
),
),
);
// Staging
$aliases['{project-short-name}.stage'] = array(
'remote-host' => '{remote-host}',
'remote-user' => '{remote-user}',
// This ssh option allows you to proxy through an intermediary server to the
// destination host. Useful if the destination server has restricted access.
// netcat is needed on the intermediary and you will need ssh agent forwarding.
#'ssh-options' => '-o "ProxyCommand ssh {proxy-host} nc %h %p 2> /dev/null"',
'site' => '{sitename}',
'root' => '{/path/to/stage-project}',
'uri' => '{stage-uri}',
'path-aliases' => array(
'%dump-dir' => '/tmp',
'%files' => 'sites/default/files',
),
'command-specific' => array (
'rsync' => array(
'exclude-paths' => 'backup_migrate:cache:css:imagecache:imagefield_thumbs:js:*.gz',
),
'sql-sync' => array (
// Add no-cache option to make sure you are getting a new DB snapshot
'no-cache' => TRUE,
// The --no-ordered-dump option can help reduce the dump size.
'--no-ordered-dump' => TRUE,
// Tables to completely skip.
'skip-tables' => array(
'skip' => array('__ACQUIA_MONITORING', '__acquia_monitoring'),
),
'skip-tables-key' => 'skip',
// Exclude cache and other trashable table data to reduce overhead.
'structure-tables' => array(
'common' => array(
// Skip data from these tables.
// NOTE: Update this list to match your project!
// Core
'cache',
# 'cache_block',
'cache_filter',
'cache_form',
'cache_menu',
'cache_page',
# 'cache_rules',
# 'cache_update',
'history',
# 'search_dataset',
# 'search_index',
# 'search_node_links',
# 'search_total',
'sessions',
'watchdog',
// Contrib
# 'cache_content',
# 'cache_hierarchical_select';
# 'cache_views_data',
# 'cache_views',
# 'views_object_cache',
# 'ctools_css_cache',
# 'ctools_object_cache',
# 'votingapi_cache',
),
),
// Comment out structure-tables-key to disable this option.
'structure-tables-key' => 'common',
),
),
);
// Development
$aliases['{project-short-name}.dev'] = array(
'parent' => '@{project-short-name}.stage',
// Uncomment if this is on a different server from stage.
# 'remote-host' => '{remote-host-dev}',
# 'remote-user' => '{remote-user-dev}',
'root' => '{/path/to/dev-project}',
'uri' => '{dev-uri}',
);
// Production
$aliases['{project-short-name}.prod'] = array(
'parent' => '@{project-short-name}.stage',
// Uncomment if this is on a different server from stage.
# 'remote-host' => '{remote-host-prod}',
# 'remote-user' => '{remote-user-prod}',
'root' => '{/path/to/prod-project}',
'uri' => '{prod-uri}',
// We want to prevent accidental overwrites to Production so we enforce
// 'simulate' for sql-sync and rsync if the target environment is production.
'target-command-specific' => array (
'sql-sync' => array (
'simulate' => '1',
),
'rsync' => array (
'simulate' => '1',
),
),
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment