Zabbix数据库的备份脚本


脚本不错,记下来备用

#/bin/sh
:<< Statement
| Function : TO BACK ZABBIX DB EXCEPT HISTORY* TREND*
| version  : DEV
| mail        : 714810243@qq.com
| date        : 2016-07-19
Statement
MysqlCMDPath='/usr/bin/mysql'
DumpCMDPath='/usr/bin/mysqldump'
DumpDBUser='zabbix'
DumpDBPasswd='xxxx'
DataBaseName=zabbix
BackFileDirPath='/home/zabbix/DBBACK'
BackFileDirName=`date +%Y%m%d`
function MysqlDump()
{
        [ -d ${BackFileDirPath}/${BackFileDirName} ] || mkdir -p ${BackFileDirPath}/${BackFileDirName} 
        Table_Name_All=`${MysqlCMDPath} -u${DumpDBUser} -p${DumpDBPasswd} ${DataBaseName} -e"show tables;" | egrep -v "Tables_in_zabbix|history*|trends*|events*"`
    
    for Table_Name in ${Table_Name_All}
    do
        ${DumpCMDPath} -q --skip-opt -u${DumpDBUser} -p${DumpDBPasswd} ${DataBaseName} ${Table_Name} > ${BackFileDirPath}/${BackFileDirName}/${Table_Name}.sql
    done    
    
    if [    "$?" == 0 ] ; then
        echo "${BackFileDirName} : BackUp zabbix successed" >> ${BackFileDirPath}/zabbixback.log
    else
        echo "${BackFileDirName} : BackUp zabbix not successed" >> ${BackFileDirPath}/zabbixback.log
    fi
    
    rm -rf ${BackFileDirPath}/`date +%Y%m%d --date='7 days ago'`
}
MysqlDump

转载!

原创文章,作者:dweifng,如若转载,请注明出处:https://blog.ytso.com/273657.html

(0)
上一篇 2022年7月11日
下一篇 2022年7月11日

相关推荐

发表回复

登录后才能评论