forked from ISTI-ansible-roles/ansible-roles
42 lines
1.1 KiB
Bash
42 lines
1.1 KiB
Bash
|
#!/bin/sh
|
||
|
|
||
|
if [ ! -f /root/.my.cnf ] ; then
|
||
|
exit 1
|
||
|
fi
|
||
|
|
||
|
MY_BACKUP_DIR=/var/lib/mysql-backup
|
||
|
umask 0077
|
||
|
MY_DATA_DIR=/var/lib/mysql
|
||
|
LOCKFILE=$MY_DATA_DIR/.mysqldump.lock
|
||
|
|
||
|
|
||
|
if [ ! -d $MY_BACKUP_DIR ] ; then
|
||
|
mkdir -p $MY_BACKUP_DIR
|
||
|
fi
|
||
|
if [ ! -d $MY_BACKUP_DIR/log ] ; then
|
||
|
mkdir -p $MY_BACKUP_DIR/log
|
||
|
fi
|
||
|
if [ ! -d $MY_BACKUP_DIR/old ] ; then
|
||
|
mkdir -p $MY_BACKUP_DIR/old
|
||
|
fi
|
||
|
chmod -R 700 $MY_BACKUP_DIR
|
||
|
|
||
|
if [ ! -f $LOCKFILE ] ; then
|
||
|
touch $LOCKFILE
|
||
|
for db in $( /bin/ls -1 /var/lib/mysql/ ) ; do
|
||
|
if [ -d /var/lib/mysql/$db ] ; then
|
||
|
if [ -f $MY_BACKUP_DIR/$db.sql ] ; then
|
||
|
mv -f $MY_BACKUP_DIR/$db.sql $MY_BACKUP_DIR/old
|
||
|
fi
|
||
|
#mysqldump -uroot -f --opt -p$MYSQLPASS $db > $MY_BACKUP_DIR/$db.sql 2> $MY_BACKUP_DIR/log/$db.log
|
||
|
mysqldump -f --opt $db > $MY_BACKUP_DIR/$db.sql 2> $MY_BACKUP_DIR/log/$db.log
|
||
|
chmod 600 $MY_BACKUP_DIR/$db.sql
|
||
|
fi
|
||
|
done
|
||
|
# Do a "flush-hosts" after the backup
|
||
|
mysqladmin flush-hosts 2> $MY_BACKUP_DIR/log/flush-hosts.log
|
||
|
rm -f $LOCKFILE
|
||
|
fi
|
||
|
|
||
|
exit 0
|