#!/bin/sh
# Name:mysqlbackup.sh
# PS:MySQL DataBase Backup,Use mysqlhotcopy script.
# Write by:i.Stone
# Last Modify:2007-11-15
#
# Define variables.
scriptsDir=`pwd`
dataDir=/var/lib/mysql/
tmpBackupDir=/tmp/tmpbackup/
backupDir=/home/mysql_back
mysqlUser=root
mysqlPWD=dayuweiwei
if [[ -e $tmpBackupDir ]]; then
rm -rf $tmpBackupDir/*
else
mkdir $tmpBackupDir
fi
if [[ ! -e $backupDir ]];then
mkdir $backupDir
fi
if [[ -s MySQLBackup.log ]]; then
cat /dev/null >MySQLBackup.log
fi
for databases in `find $dataDir -type d | \
sed -e "s/\/var\/lib\/mysql\///" | \
sed -e "s/test//"`; do
if [[ $databases == "" ]]; then
continue
else
/usr/bin/mysqlhotcopy --user=$mysqlUser --password=$mysqlPWD -q "$databases" $tmpBackupDir
dateTime=`date "+%Y.%m.%d %H:%M:%S"`
echo "$dateTime Database:$databases backup success!" >>MySQLBackup.log
fi
done
date=`date -I`
cd $tmpBackupDir
tar czf $backupDir/mysql-$date.tar.gz ./
if [[ -s MySQLBackup.log ]]; then
cat MySQLBackup.log | mail -s "MySQL Backup" $eMail
fi
阅读(1267) | 评论(0) | 转发(0) |