Created
September 11, 2008 22:32
-
-
Save chrisbloom7/10330 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
task :write => :environment do | |
dir = RAILS_ROOT + '/db/backup' | |
FileUtils.mkdir_p(dir) | |
FileUtils.chdir(dir) | |
interesting_tables.each do |tbl| | |
sql ||= ActiveRecord::Base.connection() | |
if (records = sql.execute("SELECT * FROM " + tbl) rescue false) | |
puts "Writing #{tbl}..." | |
collection = Array.new; records.each_hash(){|rec| collection.push rec } | |
File.open("#{tbl}.yml", 'w+') { |f| YAML.dump collection, f } | |
else | |
puts "Skipping #{tbl}..." | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment