1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/bin/bash

#SETTINGS
MYSQLUSER=<insert mysql user>
MYSQLPASSWORD=<insert mysql user password>
DBNAMES=("database_1" "database_2" "database_3")
BACKUPDIR=/path/to/dbbackups

#DUMP THE DATABASES
for name in ${DBNAMES[@]}
do
/usr/bin/mysqldump --skip-opt -u$MYSQLUSER -p$MYSQLPASSWORD --quote-names --complete-insert --create-options --quick --lock-tables=false --skip-add-locks $name -r $BACKUPDIR/$name.sql

cd $BACKUPDIR
/usr/local/bin/git add $name.sql
/usr/local/bin/git commit -m "mysql database backup $name `date`"
echo "--- mysql database backup $name `date` completed"

done
/usr/local/bin/git push
echo "--- mysql database backups pushed to remote repository"