Vingtoft Vingtoft - 5 months ago 22
SQL Question

Using cron job + git to automatically backup live database

Im hosting a web system on an Ubuntu instance on AWS. Its very critical that the database is backed up often. I've been looking at automated instance snapshots, but I do not find this solution desirable for two reasons: Its overkill to backup the entire instance, and all guides I've seen recommend only a single backup a day.

Im considering writing a small shell script that uses git to periodically commit changes in the MySQL database and push to a remote repo. The script should be activated by a cron job.

My question is: Will this approach work? I have not seen this solution proposed anywhere, so I suspect that I'm missing something here.
The database will never be larger than 50 mb.

Thanks

Answer

Yes, it will work - I have used something similar for a pet project of mine. Even the output of mysqldump is quite git-friendly, you can view diffs nicely etc.

It's not very common to use git for backups though, which is probably why you have not seen it proposed anywhere. There are solutions designed solely for backups which are preferable over git.