cacti备份及恢复shell

Standard

在网上找到下面两个shell,先收着.
备份Cacti
(1)cacti的文件目录的备份(rra目录除外)
(2)mysql备份
mysqldump -p cacti >/tmp/cacti.sql
(3)备份rra
dumprrd.sh

#!/bin/sh
rrddump="/usr/local/bin/rrdtool dump"
xmldir="/tmp/mysqlbackup/rraxml"
xmlbackup="/tmp/mysqlbackup/rrabak"
mysqlbackupDIR="/tmp/mysqlbackup"
rrdpath="/usr/local/share/cacti/rra/"
DATE=`date +"%y-%m-%d"`
 
if [ ! -e ${xmldir} ];then
   mkdir ${xmldir}
fi
 
if [ ! -e ${xmlbackup} ];then
  mkdir ${xmlbackup}
fi
 
#create rra => xml
for file in `find /usr/local/share/cacti/rra/ -mtime -2 | awk -F\/ '{print $NF}'`
  do
    ${rrddump} ${rrdpath}${file} > ${xmldir}/${file}.xml
  done
 
if [  `ls /tmp/mysqlbackup/rraxml/|wc -l`  -ge 2 ];then
   #tar backup
   cd ${mysqlbackupDIR}
   tar czvf ${xmldir}.${DATE}.tar.gz rraxml >/dev/null 2>&1
   mv ${xmldir}.${DATE}.tar.gz ${xmlbackup}
 
#delete file&dir
  if [ $? -eq 0 ];then
    rm -fdr ${xmldir}
    mkdir ${xmldir}
    /usr/bin/find ${mysqlbackupDIR}/rrabak -type f -ctime +2 | /usr/bin/xargs /bin/rm >/dev/null 2>&1
    echo "Rra Backup is ok!"
  fi
else
   echo "Rra Backup is fail!"
fi

恢复Cacti
(1)cacti的文件目录的备份(rra目录除外)
(2)mysql恢复
mysql cacti

#!/bin/sh
rrdrestore="/usr/local/bin/rrdtool restore"
xmldir=/tmp/rraxml/
for file in `find ${xmldir} | awk -F\/ '{print $NF}' | sed s/.xml//g`
  do
     echo $file
    ${rrdrestore} ${xmldir}${file}.xml /usr/local/share/cacti/rra/${file}
  done
chown -R cacti:cacti /usr/local/share/cacti/rra