don’t kill your live site with a sql-sync

We have a shared alias file that represents every site that we work with. For example


@abcstage
@abctest
@abclive

are all valid aliases. Developers would have access to stage and test, while live only works for privileged users.

But, we still want to make sure that no funny business goes on.

Create a file, ~/.drush/policy.drush.inc

function drush_policy_sql_sync_validate($source = NULL, $destination = NULL) {
  if (strpos($destination, 'live') !== FALSE) {
    return drush_set_error(dt('Per ~/.drush/policy.drush.inc, you may never overwrite the production database.'));
  }
  if (strpos($source, 'stage') !== FALSE && strpos($destination, 'test') !== FALSE) {
    return drush_set_error(dt('Dumping from stage to test is a terrible idea.'));
  }
  if (strpos($source, 'stage') !== FALSE && strpos($destination, 'live') !== FALSE) {
    return drush_set_error(dt('Dumping from stage to live is even worse.'));
  }
}

This will ensure that nobody can accidentally sql-sync to a live site. You can adjust the criteria as need be.