linux/centos cacti备份及恢复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}
fi
if [ ! -e {xmlbackup}
fi
#create rra => xml
for file in `find /usr/local/share/cacti/rra/ -mtime -2 | awk -F\/ ‘{print $NF}̵7;`
do
{rrdpath}{xmldir}/${file}.xml
done
if [ `ls /tmp/mysqlbackup/rraxml/|wc -l` -ge 2 ];then
#tar backup
cd ${mysqlbackupDIR}
tar czvf {DATE}.tar.gz rraxml >/dev/null 2>&1
mv {DATE}.tar.gz ${xmlbackup}
#delete file&dir
if [ $? -eq 0 ];then
rm -fdr {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恢复
(3)恢复rra
restorerra.sh
#!/bin/sh
rrdrestore=”/usr/local/bin/rrdtool restore”
xmldir=/tmp/rraxml/
for file in `find NF}217; | sed s/.xml//g`
do
echo {rrdrestore} {file}.xml /usr/local/share/cacti/rra/${file}
done
chown -R cacti:cacti /usr/local/share/cacti/rra