Asterisk Backup Script

 

This script is designed to backup all of the Asterisk files in case of a complete system blowout. The locations are setup around the Asterisk CentOS release using the voicemail system. There are two more databases included (astvm and astlogger) which I have created for my own purposes. These were left here to show you how to create a functional array of databases to backup.

#!/bin/bash

# 0 3 * * * /backup/bin/ast_backup.sh > /dev/null 2>&1

STAMP=`date +"%F"`;
EPOCH=`date +"%s"`;

TMPBKDIR=/backup/.tmp/
BKDIR=/backup/

BACKUPFOLDERS=(/etc/asterisk /etc/firewall /etc/init.d /var/spool/asterisk \
    /var/log/asterisk /var/www/html /var/lib/asterisk /usr/lib/asterisk)
DBNAMES=(mysql astvm astlogger asterisk)

DBUSER=root
DBPASS=password

[ -d $BKDIR ] || mkdir $BKDIR
[ -d $TMPBKDIR ] || mkdir $TMPBKDIR

for folders in ${BACKUPFOLDERS[@]}
 do
  mkdir -p ${TMPBKDIR}${STAMP}${folders}
  cp -r $folders ${TMPBKDIR}${STAMP}${folders}
 done

for i in ${DBNAMES[@]}
 do
   mkdir ${TMPBKDIR}${STAMP}/var/lib/mysql/
   mysqldump -u${DBUSER} -p${DBPASS} ${i} > ${TMPBKDIR}${STAMP}/var/lib/mysql/${i}.sql
 done

rm -rf ${BKDIR}${STAMP}-${EPOCH}-asterisk.tar.gz
cd ${TMPBKDIR}
tar -czf ${STAMP}-${EPOCH}-asterisk.tar.gz ${STAMP}
mv ${STAMP}-${EPOCH}-asterisk.tar.gz ${BKDIR}
rm -rf ${TMPBKDIR}${STAMP}








































 

If we wait for threats to fully materialize, we will have waited too
long.... [T]he war on terror will not be won on the defensive. We must
take the battle to the enemy, disrupt his plans, and confront the worst
threats before they emerge.
-- George W. Bush