Chen Kinnrot
Chen Kinnrot

Reputation: 21025

Ruby on Rails exporting data

I got a rails site and a mysql db. I need to perform archiving one of my models. What are my options? does rails got some built in capabilities? does mysql got any?

Upvotes: 0

Views: 2651

Answers (5)

edwardsharp
edwardsharp

Reputation: 1242

You could consider using ActiveRecord associations and building a simple callback function that could export your data to some other format (pdf, csv, html, or whatever wild example). Listen for a success from the callback function and then call your .destroy() or .delete() or whatever garbage method you choose on SomeObject.

look into Association_callbacks here: http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html

options aside, mysqldump is pretty darn efficient!

Upvotes: 0

Mohit Jain
Mohit Jain

Reputation: 43949

To backup:

 mysqldump -u user -p DATABASE > backup.sql

To import:

 mysql -u user -p DATABASE < backup.sql

Upvotes: 2

H6_
H6_

Reputation: 32837

If you need some easy database backup, I would suggest to take a look on either mysqdump or mysqlhotcopy (see also the MySQL Backup methods). You can combine this with a cronjob which runs frequently and executes the backup task.

Upvotes: 1

Sameer C
Sameer C

Reputation: 2797

rake db:dump will dump your schema and the contents of your database.
rake db:load will load the contents of the dump back into your db

Upvotes: 2

Simone Carletti
Simone Carletti

Reputation: 176472

I suggest you to use the mysqldump export utility.

Upvotes: 3

Related Questions