Skip to content

Instantly share code, notes, and snippets.

@bluefuton
Created October 28, 2010 15:58
Show Gist options
  • Save bluefuton/651662 to your computer and use it in GitHub Desktop.
Save bluefuton/651662 to your computer and use it in GitHub Desktop.
Capistrano: clone dev database to another stage (for example - cap staging mysql:clone_dev_db)
namespace :mysql do
task :clone_dev_db do
require 'ostruct'
db_config = OpenStruct.new(YAML.load_file("config/database.yml"))
dev_db = db_config.development
stage_db = db_config.send(stage)
cmd = "mysqldump -u #{dev_db['username']} -h #{dev_db['host']} -p'#{dev_db['password']}' #{dev_db['database']} " +
"--add-drop-table | mysql -u #{stage_db['username']} -p'#{stage_db['password']}' -h #{stage_db['host']} #{stage_db['database']}"
run cmd
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment