Chinaunix首页 | 论坛 | 博客
  • 博客访问: 892633
  • 博文数量: 179
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 1546
  • 用 户 组: 普通用户
  • 注册时间: 2015-01-27 11:05
个人简介

MySQL工程师 QQ:1815357042

文章分类

全部博文(179)

文章存档

2015年(179)

分类: LINUX

2015-02-26 14:35:29


  1. #!/bin/sh

  2. #function:mysql database backup
  3. #author:reed
  4. #date:2015-02-26

  5. . /etc/profile

  6. DB_NAME=cloudbridge
  7. DB_USER=cloud
  8. DB_PASSWD=cloud
  9. BAK_DIR=/root/BAK_DIR
  10. BAK_FILE=$DB_NAME-`date +%F`.sql

  11. #mkdir bakcup dir
  12. [ ! -d $BAK_DIR ] && mkdir -p $BAK_DIR

  13. FUNC()
  14. {
  15.         echo "[INFO][`date +%F_%T`]Begin to backup."
  16.         echo "[INFO][`date +%F_%T`]cd $BAK_DIR"
  17.         cd $BAK_DIR
  18.         echo "[INFO][`date +%F_%T`]mysqldump -u$DB_USER -p$DB_PASSWD $DB_NAME >> $BAK_FILE"
  19.         echo "[INFO][`date +%F_%T`]Please wait..."
  20.         mysqldump -u$DB_USER -p$DB_PASSWD $DB_NAME >> $BAK_FILE
  21.         if [ $? -eq 0 ];then
  22.                 echo "[INFO][`date +%F_%T`]tar -zcvf $BAK_FILE.tar.gz $BAK_FILE"
  23.                 tar -zcvf $BAK_FILE.tar.gz $BAK_FILE
  24.                 echo "[INFO][`date +%F_%T`]rm -rf $BAK_FILE"
  25.                 rm -rf $BAK_FILE
  26.                 echo "[INFO][`date +%F_%T`]Backup database $DB_NAME successfully."
  27.         else
  28.                 echo "[INFO][`date +%F_%T`]Backup database $DB_NAME falied.Please check it!"
  29.                 exit 111
  30.         fi

  31. }
  32. FUNC >> $BAK_DIR/baklog_$(date +%F_%T).log

阅读(1665) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~