• mysql 备份脚本


    2015-09-07

    #inno_backup.sh
    #mysql备份innodb引擎数据库
    #!/bin/bash ### AUTHOR: Kobezhu ### DATE: 2015/05/12 ### REV: V0.1 source /etc/profile source /root/.bash_profile MYSQL_LOG=/data/backup/log/mysql_bk.log TODAY=`date +%Y%m%d` target_full_dir=/data/backup/innobackup/full target_increment_dir=/data/backup/innobackup/increment mysql_conf=/etc/my.cnf user=root password=pro#pateo # send mail configuration DATE=`date '+%Y-%m-%d %H:%M:%S'` echo "-------------------------------------$TODAY-----------------------">$MYSQL_LOG WEEK_DAILY=`date +%a` case "$WEEK_DAILY" in "Mon") export BAK_LEVEL=Increment ;; "Tue") export BAK_LEVEL=Increment ;; "Wed") export BAK_LEVEL=Increment ;; "Thu") export BAK_LEVEL=Increment ;; "Fri") export BAK_LEVEL=Increment ;; "Sat") export BAK_LEVEL=Increment ;; "Sun") export BAK_LEVEL=Full ;; "*") export BAK_LEVEL=error esac echo "Today is : $WEEK_DAILY Backup level=$BAK_LEVEL">>$MYSQL_LOG case "$BAK_LEVEL" in "Increment") full_db_dir=`ls $target_full_dir` cd $target_increment_dir rm -rf * echo "Start incremental backup ........" sleep 5 /usr/bin/innobackupex --defaults-file=$mysql_conf --user=$user --password=$password --incremental-basedir=$target_full_dir/$full_db_dir --incremental $target_increment_dir RSTAT=$? echo "RSTAT=$RSTAT" echo "RSTAT=$RSTAT">>$MYSQL_LOG cd /data/backup/innobackup tar -zcvf ivi_"$TODAY"_Inc.tar.gz increment/ /usr/bin/rsync --log-file=/data/backup/log/rsync.log -a /data/backup/innobackup/ivi_"$TODAY"_Inc.tar.gz 10.105.29.161::backup/ivi/ >/dev/null 2>&1 if [ $? = 0 ];then echo "rsync completed!" rm -f /data/backup/innobackup/ivi_"$TODAY"_Inc.tar.gz else echo "rsync uncompleted!" RSYNCLOG="rsync error!" echo "=====================$RSYNCLOG on `date`====================">>$MYSQL_LOG fi ;; "Full") cd $target_full_dir rm -rf * echo "Start full backup .........." sleep 5 /usr/bin/innobackupex --defaults-file=$mysql_conf --user=$user --password=$password $target_full_dir RSTAT=$? echo "RSTAT=$RSTAT" echo "RSTAT=$RSTAT" >>$MYSQL_LOG cd /data/backup/innobackup tar -zcvf ivi_"$TODAY"_Full.tar.gz full/ /usr/bin/rsync --log-file=/data/backup/log/rsync.log -a /data/backup/innobackup/ivi_"$TODAY"_Full.tar.gz 10.105.29.161::backup/ivi/ >/dev/null 2>&1 if [ $? = 0 ];then echo "rsync completed!" rm -f /data/backup/innobackup/ivi_"$TODAY"_Full.tar.gz else echo "rsync uncompleted!" RSYNCLOG="rsync error!" echo "=====================$RSYNCLOG on `date`====================">>$MYSQL_LOG fi ;; "*") exit 99 ;; esac if [ $RSTAT = 0 ];then LOGMSG="backup end successfully!" echo $LOGMSG else LOGMSG="backup end in error." echo $LOGMSG # mailx -s "Mysql database backup was failured." -r arvinzhou@pateo.com.cn -c rich@pateo.com.cn kobezhu@pateo.com.cn,arvinzhou@pateo.com.cn < /data/backup/script/mail fi echo "=====================$LOGMSG on `date`====================">>$MYSQL_LOG
  • 相关阅读:
    centos下安装mycat
    centos下安装MySQL5.7
    centos下yum安装wget失败
    开心消消乐刷金币
    myBatis获取批量插入数据的主键id
    nginx: [emerg] bind() to 0.0.0.0:80 failed (13: Permission denied)
    Mac下安装JDK 6
    VI下删除所有内容
    Mac下lombok无法安装到eclipse mars
    WEB-INF目录下的文件访问权限
  • 原文地址:https://www.cnblogs.com/cenliang/p/4788823.html
Copyright © 2020-2023  润新知