MYSQL备份脚本
时间:2008-04-13 来源:huzi1986
#!/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
[email protected] 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
# 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
[email protected] 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
相关阅读 更多 +