Skip to content

Instantly share code, notes, and snippets.

@chrisbloom7
Created September 11, 2008 22:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrisbloom7/10330 to your computer and use it in GitHub Desktop.
Save chrisbloom7/10330 to your computer and use it in GitHub Desktop.
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