Our MySQL database servers host several dozens of databases, with dump file size ranging from 1 to ~100 MB.
Currently, our backup approach is mysqldump
, wrapped in a shell script, and run from a crontab. This has worked great for us. The only main drawback is large storage requirement to store the dump files.
Since MySQL database dump is a text file, naturally I consider storing it in a version control system, such as Subversion. I recall Subversion only store the delta of a file in each commit.
Is this approach recommended? Are there some gotchas we should aware of?
The MySQL documentation might have exactly what you need. Binary incremental backups! (Also great for a poor-mans slave server over rsync/ftp/etc).
binlog mentioned by SirStan is good approach.
alternatively you can run mysqldumps and then use rdiff-backup to create backup of dumpfile. rdiff will keep n last backups [ you decide how many ], and will be quite space efficient, since it keeps only full snapshot of latest version of file + set of diffs allowing it to reconstruct previous versions.
whatever you put in svn, stays in svn. repository only grows - so it's good place to keep your sql schemas, source code and maybe docs; but not actual data from sql.
using svn would take up a huge amount of space.
say you commit 100mb file and svn becomes version 1 then if you add a new file of 200mb the version will be 2.
Your svn repository will be 300mb.
if you woule like your file in version 1 you would have to svn co -r 1 svnrepourl
I know this question is a little dated, but at my company we've been experimenting with something similar. We've been pulling xml-formatted backups (not from MySQL, but still simply text files) that are ~300 MB in size and committing them to an SVN repository, every night for a little over a week. The first commit put the repository at 41 MB, but each commit since has been smaller. We are now at revision 8, and the total size of the repository is a scant 57 MB. This is about 2.5% of the size of all of the history it contains!
I just tried out rdiff-backup using the same data; below is a comparison (all sizes in MB):
Looks like the deltas are about the same (sometimes svn is better, sometimes rdiff-backup is), so on overall size, SVN wins. An advantage to rdiff is that it is easy to remove old backups, where with SVN you would have to do an svnadmin dump and svnadmin load to get rid of old revisions. I guess it's a matter of preference but SVN is easy to use, and has a ton of tools around to support it.
Check out this script which automates the process, allowing for specific selection of databases and exclusion of tables [disclaimer I am the author] - http://mysql-svn-backup.redant.com.au/
Percona XtraBackup supports incremental hot backups of MySQL databases.