<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Gudasoft &#187; rake</title>
	<atom:link href="http://www.gudasoft.com/tag/rake/feed" rel="self" type="application/rss+xml" />
	<link>http://www.gudasoft.com</link>
	<description>Impossible is nothing</description>
	<lastBuildDate>Thu, 06 Oct 2011 07:17:13 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.5</generator>
		<item>
		<title>Rake mysql tasks</title>
		<link>http://www.gudasoft.com/english/development/rails-development/05/06/880/rake-mysql-tasks/2009</link>
		<comments>http://www.gudasoft.com/english/development/rails-development/05/06/880/rake-mysql-tasks/2009#comments</comments>
		<pubDate>Wed, 06 May 2009 19:06:13 +0000</pubDate>
		<dc:creator>guda</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[rake]]></category>

		<guid isPermaLink="false">http://www.gudasoft.com/?p=880</guid>
		<description><![CDATA[I have found that I should be quicker if I put the following task in all my small projects. require &#8216;find&#8217; namespace :mysql do desc &#8220;Perform mysql dump on the RAILS_ENV environment&#8221; task :dump =&#62; :environment do db_config = ActiveRecord::Base.configurations[RAILS_ENV] backup_file = &#8220;#{db_config['database']}.sql&#8221; cmd = &#8220;mysqldump -u #{db_config['username']} -p#{db_config['password']} -Q &#8211;add-drop-table -O add-locks=FALSE -O lock-tables=FALSE [...]]]></description>
			<content:encoded><![CDATA[<p>I have found that I should be quicker if I put the following task in all my small projects.<br />
<span id="more-880"></span></p>
<p>require &#8216;find&#8217;<br />
namespace :mysql do<br />
desc &#8220;Perform mysql dump on the RAILS_ENV environment&#8221;<br />
task :dump =&gt; :environment do<br />
db_config = ActiveRecord::Base.configurations[RAILS_ENV]<br />
backup_file = &#8220;#{db_config['database']}.sql&#8221;<br />
cmd = &#8220;mysqldump -u #{db_config['username']} -p#{db_config['password']} -Q &#8211;add-drop-table -O add-locks=FALSE -O lock-tables=FALSE #{db_config['database']} -r #{backup_file}&#8221;<br />
puts cmd<br />
sh cmd<br />
end</p>
<p>desc &#8220;imports the dumped database in the mysql FILE&#8221;<br />
task :import =&gt; :environment do |t, args|<br />
version = ENV["FILE"] ? ENV["FILE"].to_i : nil<br />
raise &#8220;FILE is required&#8221; unless version</p>
<p>db_config = ActiveRecord::Base.configurations[RAILS_ENV]<br />
backup_file = ENV["FILE"]<br />
sh &#8220;mysql -u #{db_config['username']} -p#{db_config['password']} -e \&#8221;CREATE DATABASE IF NOT EXISTS #{db_config['database']}\&#8221; &#8221;<br />
sh &#8220;mysql -u #{db_config['username']} -p#{db_config['password']} #{db_config['database']} &lt; #{backup_file}&#8221;<br />
end</p>
<p>desc &#8220;runs the mysql console for the selected RAILS_ENV&#8221;<br />
task :console =&gt; :environment do<br />
db_config = ActiveRecord::Base.configurations[RAILS_ENV]<br />
backup_file = &#8220;#{db_config['database']}.sql&#8221;<br />
cmd = &#8220;mysql -u #{db_config['username']} -p#{db_config['password']} #{db_config['database']}&#8221;<br />
sh cmd<br />
end</p>
<p>end</p>
<p>The task dumps just make a mysql dump from the current environment. Hmm. The next step is to transfer it with scp to my host.</p>
<p>Grab from <a href="http://errtheblog.com/posts/31-rake-around-the-rosie">here</a> the mysql console task</p>
]]></content:encoded>
			<wfw:commentRss>http://www.gudasoft.com/english/development/rails-development/05/06/880/rake-mysql-tasks/2009/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

