I have developed my strategy for putting drupal database dumps into subversion every day. This was slightly more complicated than I though it would be. In principle I could just use mysqldump to dump the sql and put that in subversion but the problem is that mysqldump by default will output the insert statements to reconstruct a table in a single line in the file, even of that line grows to 600k long. If subversion does a line-by-line diff on the files it stores it will end up writing all 600k to it's transaction log.
To minimise the sizes of each diff I dump the mysql in two parts, the data and the structure. For the data dump I do the following:
- use --skip-opt to ensure that each row is inserted on a seperate line: this limits the line length. The --opt option is the default for my version of mysql (4.1.13) so I have to turn it off.
- remove comments
- strip out data for the 'accesslog', 'cache', 'search_index' and 'sessions' tables. I don't think these need backing up.
- sort the remaining lines into alphabetical order as I am not sure the sql dump is guaranteed to always dump the rows in the same order
The structure is dumped straight, I certainly don't sort the lines in the file!
This creates sql data files that should diff pretty optimally.
Here is the bash script that does this for me:
1 #!/bin/bash 2 3 function SqlDumpData { 4 mysqldump -u secret -psecret --no-create-info --skip-opt --comments=0 $1 | \ 5 egrep -v "INSERT INTO \`(accesslog|cache|search_index|sessions)\`" | sort >$2 6 } 7 8 function SqlDumpStructure { 9 mysqldump -u secret -psecret --no-data $1 >$2 10 } 11 12 cd /home/peterc/DatabaseDumps 13 14 SqlDumpData petersblog petersblog_data.sql 15 16 SqlDumpStructure petersblog petersblog_structure.sql 17 18 svn commit -m "daily backup"
This is all done on the server. Following this I can use my standard strategy to backup the subversion repository.
I have tested that the sql dumps can be reimported into mysql and give a functioning website.


Hi Peter,
thanks for this post, it's very helpful! I do regular backups of my Drupal sites in svn, too, but was a bit reluctant to include the DB dumps because of the size... I'll try your method tomorrow, that should save lots of disk space.
P.S. I _knew_ it was a good idea to set up Planet Drupal ;)
Uwe.