Created
February 4, 2010 13:48
-
-
Save jlecour/294627 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
set -e | |
if [ ! "`id -u`" -eq 0 ]; then | |
echo "Must be root !" | |
exit 0 | |
fi | |
MYSQLUSER=root | |
MYSQLPASSWORD=password | |
DATABASE=dbadmin_staging | |
BASEDIR=/tmp/mysql-git-backup | |
DUMPDIR=$BASEDIR/$DATABASE | |
GITDIR=/var/backups/mysql | |
if [ ! -d $GITDIR ]; then | |
mkdir -p $GITDIR | |
chgrp -R wheel $GITDIR | |
cd $GITDIR | |
git init . | |
git config core.compression 9 | |
git config repack.usedeltabaseoffset true | |
git config pack.windowMemory 100m | |
git config pack.window 15 | |
git config gc.auto 1000 | |
git config gc.autopacklimit 10 | |
fi | |
if [ -d $DUMPDIR ]; then | |
rm -rf $DUMPDIR/* | |
else | |
mkdir -p $DUMPDIR | |
fi | |
chown -R mysql:wheel $BASEDIR | |
chmod -R 775 $BASEDIR | |
mysqldump -u $MYSQLUSER -p$MYSQLPASSWORD -Q --tab=$DUMPDIR $DATABASE | |
chown -R mysql:wheel $DUMPDIR | |
cp -pRP $BASEDIR/$DATABASE $GITDIR | |
rm -rf $BASEDIR/$DATABASE | |
cd $GITDIR | |
git add $DATABASE | |
git commit -m "Backup automatique" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment