Monday, July 19, 2010

Backup and Restore Asterisk, FreePBX, MySQL, HTTP

;Required:
1) Make sure you have the same version of source files used to
install Asterisk, FreePBX, MySQL and Apache
2) Modify the file path if needed


;;;;Backup Script
#!/bin/sh
NOW=$(date +"%m-%d-%Y-%H%M%S")
#mkdir /root/ast-backup-$NOW
tar -zcvf /root/ast-backup-$NOW/etc-amportal-$NOW.tar.gz /etc/amportal.conf ;
tar -zcvf /root/ast-backup-$NOW/etc-asterisk-$NOW.tar.gz /etc/asterisk ;
tar -zcvf /root/ast-backup-$NOW/var-lib-asterisk-$NOW.tar.gz /var/lib/asterisk ;
tar -zcvf /root/ast-backup-$NOW/var-lib-mysql-$NOW.tar.gz /var/lib/mysql ;
tar -zcvf /root/ast-backup-$NOW/var-spool-asterisk-$NOW.tar.gz /var/spool/asterisk ;
tar -zcvf /root/ast-backup-$NOW/var-www-html-$NOW.tar.gz /var/www/html ;


;;;;Restore Script
#!/bin/sh
NOW=$(date +"%m-%d-%Y-%H%M%S")
######## ------- Configuration / DB restore steps -------
######## BACKUP EXISTING and RESTORE /etc/asterisk
mv /etc/asterisk /etc/asterisk.$NOW
cd /usr/local/src/postinstall/config_files/etc
cp -R asterisk /etc
chown -R asterisk.asterisk /etc/asterisk
cp amportal.conf /etc

######## RESTORE Directories
mv /var/www/html/admin /var/www/html/admin.$NOW
mv /var/www/html/myqueue /var/www/html/myqueue.$NOW
mv /var/www/html/panel /var/www/html/panel.$NOW
mv /var/www/html/recordings /var/www/html/recordings.$NOW

cp -R /usr/local/src/postinstall/config_files/var/www/html/* /var/www/html
chown -R asterisk.asterisk /var/www/html

mv /var/lib/mysql /var/lib/mysql.$NOW
cp -R /usr/local/src/postinstall/config_files/var/lib/mysql /var/lib
chown -R mysql.mysql /var/lib/mysql

mv /etc/asterisk /etc/asterisk.$NOW
cp -R /usr/local/src/postinstall/config_files/etc/asterisk /etc
chown -R asterisk.asterisk /etc/asterisk

mv /var/lib/asterisk /var/lib/asterisk.$NOW
cp -R /usr/local/src/postinstall/config_files/var/lib/asterisk /var/lib
chown -R asterisk.asterisk /var/lib/asterisk

mv /var/spool/asterisk /var/spool/asterisk.$NOW
cp -R /usr/local/src/postinstall/config_files/var/spool/asterisk /var/spool
chown -R asterisk.asterisk /var/spool/asterisk

######## RESTART MYSQL and HTTPD Services
/etc/rc.d/init.d/httpd restart
/etc/rc.d/init.d/mysqld restart

No comments:

Post a Comment