Question

Is it possible to do the following: 1. Hot database backup of mysql database from Rails 3 application 2. Incremental database backup of mysql database from Rails 3 application 3. Cold database backup of mysql database from Rails 3 application 4. Restore any of the above databases ( Hot, incremental and cold) through Rails 3 application.

Please let me know how to achieve this?

Thanks, Sudhir C.N.

Was it helpful?

Solution

Setup some cronjobs. I like to use Whenever for writing them. I run this bash script once per day:

#!/bin/bash

BACKUP_FILENAME="APPNAME_production_`date +%s`.gz"
mysqldump -ce -h MYSQL.HOST.COM -u USERNAME -pPASSWORD APPNAME_production | gzip | uuencode $BACKUP_FILENAME | mail -s "daily backup for `date`" webmaster@yourdomain.com

echo -e "\n====\n== Backed up APPNAME_production to $BACKUP_FILENAME on `date` \n====\n"

And output it to cron.log. This may require some tweaking on your end, but it works great once you get it. E-mails the backup to you once per day as a gzipped file, my database is fairly large and file is under 2000kb right now.

It's not the safest technique, so if you're really concerned that someone might get into your e-mail and get access to the backups (which should have sensitive information encrypted anyways), then you'll have to find another solution.

To restore:

gzip -d APPNAME_production_timestamp.gz
mysql -u USERNAME -pPASSWORD APPNAME_production < APPNAME_production_timestamp.sql

or something similar... I don't need to restore often so I don't know this one off the top of my head, but a quick google search should turn up something if this doesn't work.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top