Reputation: 21025
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
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
Reputation: 43949
To backup:
mysqldump -u user -p DATABASE > backup.sql
To import:
mysql -u user -p DATABASE < backup.sql
Upvotes: 2
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
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