Java教程

Zabbix数据库的备份脚本

本文主要是介绍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

转载!

这篇关于Zabbix数据库的备份脚本的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!