<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>The Napkin ~ A Blog By Highgroove Studios comments on (safely) Playing with your production data</title>
    <link>http://cleanair.highgroove.com/</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>The Napkin ~ A Blog By Highgroove Studios comments</description>
    <item>
      <title>"(safely) Playing with your production data" by derek</title>
      <description>&lt;p&gt;Sometimes our &lt;a href="http://www.rubyonrails.com"&gt;Ruby on Rails&lt;/a&gt; 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.&lt;/p&gt;


	&lt;p&gt;Here&amp;#8217;s what we do to quickly and safely debug issues on our production servers:&lt;/p&gt;


	&lt;p&gt;&lt;strong&gt;1. Add the following capistrano task to create an &lt;span class="caps"&gt;SQL&lt;/span&gt; dump of your data. If it&amp;#8217;s a large database, it may be worthwhile to compress the &lt;span class="caps"&gt;SQL&lt;/span&gt; dump as well.&lt;/strong&gt;&lt;/p&gt;


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

	&lt;p&gt;&lt;strong&gt;2. Create the following rake tasks to grab database dump and import the data locally.&lt;/strong&gt;&lt;/p&gt;


&lt;pre&gt;
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 &amp;lt; 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 =&amp;gt; [ :get_production, :import ]
end
&lt;/pre&gt;

	&lt;p&gt;&lt;strong&gt;3. Install the Firefox plugin &lt;a href="https://addons.mozilla.org/en-US/firefox/addon/2409"&gt;Server Switcher&lt;/a&gt; to make it easy to switch between the production and local server in your web browser.&lt;/strong&gt;&lt;/p&gt;


	&lt;p&gt;&lt;strong&gt;4. Disable mail in your development box &amp;#8211; it&amp;#8217;s not a good feeling when you realize you&amp;#8217;ve emailed several thousand users while testing out a newsletter script.&lt;/strong&gt;&lt;/p&gt;


&lt;pre&gt;
config.action_mailer.delivery_method = :test
&lt;/pre&gt;

</description>
      <pubDate>Thu, 17 May 2007 11:12:00 EST</pubDate>
      <guid>&lt;a href="/articles/2007/05/17/ruby_on_rails_production_data_testing_capistrano_rake"&gt;(safely) Playing with your production data&lt;/a&gt;</guid>
      <link>&lt;a href="/articles/2007/05/17/ruby_on_rails_production_data_testing_capistrano_rake"&gt;(safely) Playing with your production data&lt;/a&gt;</link>
    </item>
  </channel>
</rss>
