Search

(safely) Playing with your production data

Derek

2 min read

May 16, 2007

(safely) Playing with your production data

Sometimes our Ruby on Rails apps work perfectly with test data, but when they go to production, errors creep in. Debugging errors on a production server is a pain and a bit dangerous.

Here’s what we do to quickly and safely debug issues on our production servers:

1. Add the following capistrano task to create an SQL dump of your data. If it’s a large database, it may be worthwhile to compress the SQL dump as well.

 desc "Exports the production db to the home directory of user" task :db_dump, :roles => [:app, :db] do   run("mysqldump -u #{database_username} --password=#{database_password} #{application}_production > production.sql") end 

2. Create the following rake tasks to grab database dump and import the data locally.

 namespace :db do   desc 'Grab a dump of the production database on the server and places it in db/production.sql.'   task :get_production do      `cap db_dump`     `scp DEPLOY_USER@SERVER_NAME.slingshothosting.com:production.sql #{RAILS_ROOT}/db/production.sql`   end      desc 'Imports the database dump of file db/production.sql into development.'   task :import do      `mysql -u root app_name_development < db/production.sql`   end      desc 'Grabs a dump of the production database from the server and imports the data into the local development database.'   task :get_import => [ :get_production, :import ] end 

3. Install the Firefox plugin Server Switcher to make it easy to switch between the production and local server in your web browser.

4. Disable mail in your development box – it’s not a good feeling when you realize you’ve emailed several thousand users while testing out a newsletter script.

 config.action_mailer.delivery_method = :test 

Steve Sparks

Reviewer Big Nerd Ranch

Steve Sparks has been a Nerd since 2011 and an electronics geek since age five. His primary focus is on iOS, watchOS, and tvOS development. He plays guitar and makes strange and terrifying contraptions. He lives in Atlanta with his family.

Speak with a Nerd

Schedule a call today! Our team of Nerds are ready to help

Let's Talk

Related Posts

We are ready to discuss your needs.

Not applicable? Click here to schedule a call.

Stay in Touch WITH Big Nerd Ranch News