Tech Blog :: Incremental database backups with Git
Incremental database backups with Git
I'm trying a new method for database (MySql) backups: incremental tracking every 10 minutes with Git. Basically I have a Git repository cloned to a directory on the server, every 10 minutes on cron the database is dumped to the directory, and all changes are committed. I added a changed-line counter to make the logs more interesting.
I'm not sure how this will work in production, or what strain mysqldump puts on the database (I should run this off a slave when it goes live, I'm thinking), but the ability to revert the database to any 10-minute increment in the past and view changes to each table line by line seems pretty cool. This is the script:
#! /bin/bash cd /var/backups/db-git DRUSH=/usr/bin/drush $DRUSH --root=/path/to/webroot sql-dump > /var/backups/db-git/site-db.sql syncDT=`date "+%Y-%m-%d_%H-%M"` ## count # of lines changed NUMLINES=$(git diff | grep -e "^[+-]" | wc -l) ## don't count 2 header lines NUMLINES=$(( $NUMLINES - 2 )) git ci -a -m"DB backup DEV: $syncDT ($NUMLINES lines changed)" git push origin
Any thoughts?
Google: TheBuckSt0p
Facebook: BenBuckman
LinkedIn
Github: newleafdigital
@thebuckst0p
Delicious: thebuckst0p
Drupal.org: thebuckst0p
Post new comment
Don't bother putting in spam links. They'll be set to
rel=nofollowand will be removed and reported as spam shortly after submitting.