Call us Today +49 7543 609337-0
Log In

Cacti Backup Guide

This guide describes a short how-to for backing up all essential cacti files.

[the_ad_placement id=”default-manual”]

Generic Information

This section provides an overview on what should be backed up as well as the script and cron jobs being used

What to Backup:

The goal of the backup is to have a full working Cacti installation restored as fast as possible. Therefore the following configuration files and directories should be included:

  • Apache configuration
  • PHP configuration
  • Cacti Cronjob
  • Full Cacti directory
  • Backup script
  • If installed: Spine

In addition to these files, the following database needs to be saved:

  • cacti

Backup Script:

The passwords have been changed to “xxx”.

#!/bin/bash
# Urban-Software.de
# Database Backup Script

# Set the backup filename and directory
DATE=`date +%Y%m%d` # e.g 20130721
FILENAME="cacti_database_$DATE.sql";
TGZFILENAME="cacti_files_$DATE.tgz";
BACKUPDIR="/backup/";

# Database Credentials
DBUSER="cactiuser";
DBPWD="xxx";
DBNAME="cacti";

# FTP Backup Server credentials
FTPHOST="127.0.0.1";
FTPUSER="cacti";
FTPPWD="xxx";

echo "Creating Cacti backup for [$DATE]"

# Where is our gzip tool for compression ?
# The -f parameter will make sure that gzip will
# overwrite existing files
GZIP="/bin/gzip -f";

# What files do we want to include ?
# Change the directories accordingly !
TARINCLUDE="./var/www/html
./etc/cron.d/cacti
./etc/php.ini
./etc/php.d
./etc/httpd/conf
./etc/httpd/conf.d
./usr/local/spine/etc/spine.conf
./usr/local/spine"

# Which files/directories do we want to EXCLUDE ?
TAREXCLUDE="./var/www/html/log"

# Delete old database backups older than 3 days
find /backup/cacti_database*.sql.gz* -mtime +3 -exec rm {} \;
find /backup/cacti_files*.tgz* -mtime +3 -exec rm {} \;

# Change to the root directory
cd /

# execute the database dump
mysqldump --user=$DBUSER --password=$DBPWD --add-drop-table --databases $DBNAME > $BACKUPDIR$FILENAME

# compress the database backup
$GZIP $BACKUPDIR$FILENAME

# Create the Cacti files backup
tar -czpf $BACKUPDIR$TGZFILENAME $TARINCLUDE

# Generate MD5 crc
md5sum $BACKUPDIR$TGZFILENAME > $BACKUPDIR$TGZFILENAME.md5
md5sum $BACKUPDIR$FILENAME.gz > $BACKUPDIR$FILENAME.gz.md5

# Uncomment the following to enable FTP upload
exit

# Upload to FTP server (on a SCP server, the transfer could be verified
# By a md5sum execution on the remote system with a comparison of the 2 files afterwards
ftp -inv $FTPHOST << EOF
user $FTPUSER $FTPPWD
bin
put $BACKUPDIR$TGZFILENAME.md5 $TGZFILENAME.md5
put $BACKUPDIR$FILENAME.gz.md5 $FILENAME.gz.md5
put $BACKUPDIR$TGZFILENAME $TGZFILENAME
put $BACKUPDIR$FILENAME.gz $FILENAME.gz
bye
EOF

Backup Cronjob:

The following lines have been added to /etc/cron.d/cacti:

# Cacti Backup Schedule
0 2 * * * root /bin/bash /backup/cacti_backup.sh &>/backup/backup.log

Restore Procedures

Follow these steps in order to restore your Cacti system:

  1. Create a new System with all pre-requirements satisfied ( php, mysql, apache installed, basic Cacti )
  2. Fetch your latest backup files ( files + database ) and put it into the tmp directory
  3. Drop and Re-Create a the cacti database and add the cacti user with your DB credentials ( change xxx to match your current database user/password):
    mysql –p
    > CREATE DATABASE cacti;
    > GRANT ALL PRIVILEGES ON cacti.* TO cacti@localhost IDENTIFIED BY “xxx”;
    > FLUSH PRIVILEGES;
  4. Execute the following commands:
    cd /
    tar –xzvf /tmp/cacti_files_yyyymmdd.tgz
    cd /tmp/
    gunzip /tmp/cacti_database_yyyymmdd.sql.gz
    mysql –u cacti –p cacti < /tmp/cacti_database_yyyymmdd.sql