MySQL HotCopy的备份脚本一枚

最近有需求 重新修改了下 备份发出来 水平有限 高手莫见怪

[bash]#!/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 protected]

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
[/bash]

Author Info :
  • From:MySQL HotCopy的备份脚本一枚
  • URL:https://blog.ihipop.com/2011/03/2182.html
  • Please Reserve This Link,Thanks!
  • 发表回复

    您的电子邮箱地址不会被公开。 必填项已用 * 标注