最近有需求 重新修改了下 备份发出来 水平有限 高手莫见怪
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
#!/bin/bash # Name:mysqlbackup # PS:MySQL DataBase Backup,Use mysqlhotcopy script. # # Last Modify:2011-3-23 # # Define variables. scriptsDir=`pwd` datadir=/data/path/to/db tmpBackupDir=/home/path/temp/ backupDir=/home/path/mysql/ mysqlUser=root mysqlPWD=PASSWORD mysqlhost=127.0.0.1 dblist=`ls -p $datadir | grep / | tr -d /` #多个帐号半角逗号隔开 eMail=ihipop@gmail.com if [[ -e $tmpBackupDir ]]; then rm -rf $tmpBackupDir/* else mkdir $tmpBackupDir fi if [[ ! -e $backupDir ]];then mkdir $backupDir else rm -rf $backupDir/* fi if [[ -s mysqlbackup.log ]]; then cat /dev/null >mysqlbackup.log fi for databases in $dblist do if [[ $databases == "" ]]; then continue else result='Failed!(Warning!)' /usr/bin/mysqlhotcopy --user=$mysqlUser --password=$mysqlPWD -q "$databases" $tmpBackupDir [ $? == 0 ] && result='Success!' dateTime=`date "+%Y.%m.%d %H:%M:%S"` && echo "$dateTime Database:$databases backup $result !" >> $backupDir/mysqlbackup.log fi done cd $tmpBackupDir date=`date +%m-%d-%H` # Tar/gzip data tar czf $backupDir/mysql-$date.tar.gz ./ if [[ -s $backupDir/mysqlbackup.log ]]; then cat $backupDir/mysqlbackup.log | mail -s "MySQL Backup" $eMail fi chmod 700 -R /home/path |