开发者

Ruby on Rails exporting data

I got a rails site and a mysql db. I need to perf开发者_JAVA百科orm archiving one of my models. What are my options? does rails got some built in capabilities? does mysql got any?


I suggest you to use the mysqldump export utility.


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


To backup:

 mysqldump -u user -p DATABASE > backup.sql

To import:

 mysql -u user -p DATABASE < backup.sql


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.


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!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜