Sha256: 415289e08dfb2e9efab8d87a020225aaee6f81b61c7f60c2d633656c3c8120a7

Contents?: true

Size: 1.69 KB

Versions: 1

Compression:

Stored size: 1.69 KB

Contents

Capistrano::Configuration.instance(:must_exist).load do

  namespace :db do
    task :backup_name, :only => { :primary => true } do
      now = Time.now
      run "mkdir -p #{shared_path}/db_backups"
      backup_time = [now.year,now.month,now.day,now.hour,now.min,now.sec].join('-')
      set :backup_file, "#{shared_path}/db_backups/#{environment_database}-snapshot-#{backup_time}.sql"
    end
  
    desc "Clone Production Database to Staging Database."
    task :clone_prod_to_staging, :roles => :db, :only => { :primary => true } do
      backup_name
      on_rollback { run "rm -f #{backup_file}" }
      run "mysqldump --add-drop-table -u #{dbuser} -h #{production_dbhost}-replica -p#{dbpass} #{production_database} > #{backup_file}"
      run "mysql -u #{dbuser} -p#{dbpass} -h #{staging_dbhost} #{staging_database} < #{backup_file}"
      run "rm -f #{backup_file}"
    end
  
    desc "Backup your database to shared_path+/db_backups"
    task :dump, :roles => :db, :only => {:primary => true} do
      backup_name
      run "mysqldump --add-drop-table -u #{dbuser} -h #{environment_dbhost}-replica -p#{dbpass} #{environment_database} | bzip2 -c > #{backup_file}.bz2"
    end
    
    desc "Sync your production database to your local workstation"
    task :clone_to_local, :roles => :db, :only => {:primary => true} do
      backup_name
      dump
      get "#{backup_file}.bz2", "/tmp/#{application}.sql.gz"
      development_info = YAML.load_file("config/database.yml")['development']
      run_str = "bzcat /tmp/#{application}.sql.gz | mysql -u #{development_info['username']} -p#{development_info['password']} -h #{development_info['host']} #{development_info['database']}"
      %x!#{run_str}!
    end
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
engineyard-eycap-0.3.3 lib/eycap/recipes/database.rb