一直以来用cactiEZ进行服务器的监控
也没有管它备份的事儿,今日做一个备份的脚本 主要是备份cacti数据库,nagios的配置文件 以及cacti的rra文件。
cacti 的恢复的话 就是将所有的rra文件拷贝到现有的位置 然后将cacti库给导入~
##############################################################################
#!/bin/sh ###################### #### #### EDITED BY anpipi #### 2009-12-09 #### #####################
T_date=`date +%y%m%d` O_date=`date +%y%m%d --date='7 days ago'` LOG="/var/log/backup.log"
echo "#### - `date +%F`--------------BACK UP IS starting---------------" >> $LOG
function cactidb_bak () { extra=50000 Dbname="cacti" Dbuser="root" Dbpasswd="apipi" Bakfile=/bak/"$Dbname"_"$T_date".sql gzfile=$Bakfile.gz size=$( ls -l $gzfile | awk '{print $5}')
if [ ! -e $gzfile ] || [ $size -le $extra ];then /usr/bin/mysqldump -u$Dbuser -p$Dbpasswd --databases $Dbname > $Bakfile /usr/bin/gzip $Bakfile fi echo "`date +%T`---------$Dbname--------backup is success----------" >> $LOG rm -rf /bak/"$Dbname"_"$O_date".sql* }
function tardata () { ########### tar all rra data file ##################
file1=/bak/"cacti_rra_"$T_date".tar.gz" extra=1000000 size=$( ls -l $file1 | awk '{print $5}') if [ ! -e $file1 ] || [ $size -le $extra ];then dir="/var/www/html" cd $dir /bin/tar -zcvf /bak/cacti_rra_"$T_date".tar.gz rra echo "`date +%T`--------rra-----------backup is success----------" >> $LOG fi rm -rf /bak/cacti_rra_"$O_date".tar.gz
########### tar nagios data file #################
file2=/bak/"nagios_"$T_date".tar.gz" extra=100000 size=$( ls -l $file2 | awk '{print $5}') if [ ! -e $file2 ] || [ $size -le $extra ];then dir_nagios="/etc" cd $dir_nagios /bin/tar -zcvf /bak/nagios_"$T_date".tar.gz nagios echo "`date +%T`------------all-----------backup is success----------">> $LOG echo "####">> $LOG echo "####">> $LOG fi rm -rf /bak/nagios_"$O_date".tar.gz }
cactidb_bak
tardata
|