Kevin Marsh

rake db:production:clone

I’ve been using this little rake ditty for awhile, to refresh my current development database with data from the production server:

namespace :db do
  namespace :production do
    desc "Recreate the local development database as a clone of the remote production database" 
    task :clone do
      system %Q(ssh [db_host] "rm /tmp/out.sql.bz2; mysqldump -uroot -p [production_database_name] > /tmp/out.sql; bzip2 /tmp/out.sql")
      system %Q(scp [db_host]:/tmp/out.sql.bz2 .)
      system %Q(bzcat out.sql.bz2 | mysql -uroot -D[development_database_name])
      system %Q(rm out.sql.bz2)
    end
  end
end

Of course, you’ll have to change the bits in brackets to fit your particular situation.

Now, this obviously isn’t for everyone, but for small-to-medium sized databases it works pretty well and helps you work with real data.

Others' Comments

  1. Bruno Miranda said on June 21, 2008 @ 06:40 PM:

    This is AWESOME! Thx.

Your Comments

Your name:

Your email:

Your blog:

Your comment: