Chinaunix首页 | 论坛 | 博客
  • 博客访问: 668050
  • 博文数量: 467
  • 博客积分: 8050
  • 博客等级: 中将
  • 技术积分: 14825
  • 用 户 组: 普通用户
  • 注册时间: 2006-09-18 11:00
文章分类

全部博文(467)

文章存档

2009年(8)

2008年(459)

分类: LINUX

2008-04-14 12:04:05

#!/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
阅读(1236) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~