lib/eycap/recipes/database.rb in engineyard-eycap-0.4.3 vs lib/eycap/recipes/database.rb in engineyard-eycap-0.4.4

- old
+ new

@@ -11,35 +11,21 @@ desc "Clone Production Database to Staging Database." task :clone_prod_to_staging, :roles => :db, :only => { :primary => true } do # This task currently runs only on traditional EY offerings. # You need to have both a production and staging environment defined in - # your deploy.rb file. + # your deploy.rb file. backup_name on_rollback { run "rm -f #{backup_file}" } - run("cat #{shared_path}/config/database.yml") { |channel, stream, data| @environment_info = YAML.load(data)[rails_env] } + run("cat #{shared_path}/config/database.yml") { |channel, stream, data| @environment_info = YAML.load(data)[rails_env] } - # If the production db hostname has a trailing -master string, substitute - # it with -replica. - # Elsif the production db hostname doesn't have a trailing -master, just - # append -replica. - # Else you're using PostgreSQL and we'll dump it that way. - - if @environment_info['adapter'] == 'mysql' && production_dbhost.scan('-master') == true - run "mysqldump --add-drop-table -u #{dbuser} -h #{production_dbhost.gsub('-master', '-replica')} #{production_database} -p > #{backup_file}" do |ch, stream, out| + if @environment_info['adapter'] == 'mysql' + dbhost = @environment_info['host'] + dbhost = environment_dbhost.sub('-master', '') + '-replica' if dbhost != 'localhost' # added for Solo offering, which uses localhost + run "mysqldump --add-drop-table -u #{dbuser} -h #{dbhost} -p #{environment_database} | bzip2 -c > #{backup_file}.bz2" do |ch, stream, out | ch.send_data "#{dbpass}\n" if out=~ /^Enter password:/ end - run "mysql -u #{dbuser} -p -h #{staging_dbhost} #{staging_database} < #{backup_file}" do |ch, stream, out| - ch.send_data "#{dbpass}\n" if out=~ /^Enter password:/ - end - elsif @environment_info['adapter'] == 'mysql' && production_dbhost.scan('-master') != true - run "mysqldump --add-drop-table -u #{dbuser} -h #{production_dbhost + '-replica'} #{production_database} -p > #{backup_file}" do |ch, stream, out| - ch.send_data "#{dbpass}\n" if out=~ /^Enter password:/ - end - run "mysql -u #{dbuser} -p -h #{staging_dbhost} #{staging_database} < #{backup_file}" do |ch, stream, out| - ch.send_data "#{dbpass}\n" if out=~ /^Enter password:/ - end else run "pg_dump -W -c -U #{dbuser} -h #{production_dbhost} -f #{backup_file} #{production_database}" do |ch, stream, out| ch.send_data "#{dbpass}\n" if out=~ /^Password:/ end run "psql -W -U #{dbuser} -h #{staging_dbhost} -f #{backup_file} #{staging_database}" do |ch, stream, out|