schwarz

archive of mindset

schwarz header image 5

Grabbing mysql production databases to your local system with rake

October 06, 2007 · 0 comments

After reading the comments on Nate Clarke's article I decided it would be a good idea to republish the stolen modified script that I found elsewhere (Honestly, I have no idea. If anyone can cite the original author I'll give credit where due)
namespace :db do
desc "Sync your local database with a remote one REMOTE=name_of_database LOCAL=your_local_db"
  task :sync do
    `ssh domain.com "mysqldump --skip-extended-insert -u db_username -p #{ENV['REMOTE']} | bzip2 " | bzcat | mysql -u root #{ENV['LOCAL'] || "app_development"}`
  end
end

The rundown

  • We use this almost daily
  • Use RSA keys and you'll only need to auth once (for the database)
  • I'm using --skip-extended-insert because it will write each query on a new line (for larger databases mysql can be known to crack the shits on a default setup when everything is inserted in a massive chunk)
  • Its using bzip to compress it over the wire (sadly, this was the original authors smarts)

Usage

rake db:sync REMOTE=my_db_with_lots_of_data
This is great for testing your app with different versions of data (for ridiculous migrations and such

→ 0 comments Tags: