Skip to content

Instantly share code, notes, and snippets.

@jlecour
Created May 15, 2016 08:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jlecour/316a9308526b8ecd71ef9f1de9f2cae7 to your computer and use it in GitHub Desktop.
Save jlecour/316a9308526b8ecd71ef9f1de9f2cae7 to your computer and use it in GitHub Desktop.
#!/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