当前位置:首页 > 开发 > 系统架构 > 架构 > 正文

备份MYSQL脚本

发表于: 2013-02-25   作者:dcj3sjt126com   来源:转载   浏览:
摘要: #!/bin/sh # this shell to backup mysql #1413161683@qq.com (QQ:1413161683 DuChengJiu) _dbDir=/var/lib/mysql/ _today=`date +%w` _bakDir=/usr/backup/$_today [ ! -d $_bakDir ] && mkdir -p
#!/bin/sh
# this shell to backup mysql
#1413161683@qq.com (QQ:1413161683 DuChengJiu)

_dbDir=/var/lib/mysql/
_today=`date +%w`
_bakDir=/usr/backup/$_today
[ ! -d $_bakDir ] && mkdir -p $_bakDir
#Create db tar archive
#/usr/local/mysql/share/mysql/mysql.server stop
service mysqld stop
for db in `find $_dbDir -type d|tail -n +2`
do
        echo "Do $db ...."
        realDb=`echo $db|awk -F / '{print $NF}'`
        echo "Backup $realDb ......"
        tar cvf $_bakDir/${realDb}.tar $db || echo "$realDb   :  1" >>$_bakDir/backup-error
done

#/usr/local/mysql/share/mysql/mysql.server start
service mysqld start

#gzip backup
for zip in $_bakDir/*.tar
do
        echo "Compress $zip ........"
        gzip -f $zip
done
find $_bakDir -name "*tar" -exec rm -f {} \;

 

备份MYSQL脚本

  • 0

    开心

    开心

  • 0

    板砖

    板砖

  • 0

    感动

    感动

  • 0

    有用

    有用

  • 0

    疑问

    疑问

  • 0

    难过

    难过

  • 0

    无聊

    无聊

  • 0

    震惊

    震惊

版权所有 IT知识库 CopyRight © 2009-2015 IT知识库 IT610.com , All Rights Reserved. 京ICP备09083238号