Error
  • The template for this display is not available. Please contact a Site administrator.

A simple Trixbox "Asterisk" backup script

Below are my instructions for a simple manual failover solution for Trixbox.

We use two servers at our company.  


Overall notes:  for this script to work well you should follow THESE instructions to set up SSH with no password.

You may find that some commands are wrapped on the screen, it should be easy to find these lines, just make sure you coorect them if you copy paste.


 

Primary Server - IP - 10.20.0.5 -  2 NICs one is public facing allowing for remote connections.

Backup Server - IP - 10.20.0.4 - Duplicate of main server, Same model of server

 

First the Primary Server.

Every Hour the server will run the following backup script.  the script will backup the following.

  • ETC and VAR folders - These are straight copied to the backup server with the exception of the /etc/sysconfig folder.  We do not directly back this up because if we did the backup server would assume the same IP addresses, thus breaking the Primary Server
  • MySQL tables - These are backed up to the backup server under the /tmp/mysqlbackups folder,  you will need to create this folder.
  • It will then invoke a script sitting on the backup server which will restore the MySQL databases on the backup server that were just copied over.
  • It will then copy the /etc/sysconfig folder contents to the backup server under the /network-repair-info/ folder



#!/bin/sh

#it is designed to keep two Trixbox servers synced for a soft failover

#Backup /etc folder
rsync -avz --delete --exclude 'sysconfig' /etc/ This email address is being protected from spambots. You need JavaScript enabled to view it..0.4:/etc/
echo etc done
sleep 1

#Backup /var folder
rsync -avz --delete --exclude 'log' /var/ This email address is being protected from spambots. You need JavaScript enabled to view it..0.4:/var/
echo var done
sleep 1

#backup mysql tables
mysqldump -u root -ppassw0rd information_schema > /tmp/mysqlbackups/information_schema.sql
mysqldump -u root -ppassw0rd asterisk > /tmp/mysqlbackups/asterisk.sql
mysqldump -u root -ppassw0rd asteriskcdrdb > /tmp/mysqlbackups/asteriskcdrdb.sql
mysqldump -u root -ppassw0rd asteriskrealtime > /tmp/mysqlbackups/asteriskrealtime.sql
mysqldump -u root -ppassw0rd endpoints > /tmp/mysqlbackups/endpoints.sql
mysqldump -u root -ppassw0rd meetme > /tmp/mysqlbackups/meetme.sql
mysqldump -u root -ppassw0rd mysql > /tmp/mysqlbackups/mysql.sql
echo all databases extracted
sleep 1

#Backup /tmp/mysqlbackups/ folder
rsync -avz --delete /tmp/mysqlbackups/ This email address is being protected from spambots. You need JavaScript enabled to view it..0.4:/tmp/mysqlbackups/

echo databases synced
sleep 1

#delete /tmp/mysqlbackups/ files
rm -rvf /tmp/mysqlbackups/*
echo old databases deleted
sleep 1

#run mysql restore command on slave server
ssh This email address is being protected from spambots. You need JavaScript enabled to view it..0.4 '/restoremysql'
echo restore of mysql is complete.
echo all done

#backup sysconfig folder
ssh This email address is being protected from spambots. You need JavaScript enabled to view it..0.4 'rm -rvf /network-repair-info/*'
rsync -avz --delete /etc/sysconfig/ This email address is being protected from spambots. You need JavaScript enabled to view it..0.4:/network-repair-info/


Now the Backup Server

The backup server has two scripts on it.

  • Restoremysql - this script is run every hour as part of the primary backup script it will restore the MySQL databases that were copied from the primary server.
  • Restore_Server - This script is run only in the event that you need to bring the backup server up as the main.

Restoremysql Script

 




#!/bin/sh

#this script will restore the mysql databases backed up from the main server

mysql -u root -ppassw0rd asterisk < /tmp/mysqlbackups/asterisk.sql
mysql -u root -ppassw0rd information_schema < /tmp/mysqlbackups/information_schema.sql
mysql -u root -ppassw0rd asteriskcdrdb < /tmp/mysqlbackups/asteriskcdrdb.sql
mysql -u root -ppassw0rd asteriskrealtime < /tmp/mysqlbackups/asteriskrealtime.sql
mysql -u root -ppassw0rd endpoints < /tmp/mysqlbackups/endpoints.sql
mysql -u root -ppassw0rd meetme < /tmp/mysqlbackups/meetme.sql
mysql -u root -ppassw0rd mysql < /tmp/mysqlbackups/mysql.sql

Restore_Server

This script is still under construction.  It's goal is to promote the backup server in the case that the primary fails.

 




#!/bin/sh

#This script will bring this server up as the main server
#Amportal is not set to start on boot so replace the rc.local file so that it will start on boot
mv /etc/rc.d/rc.local.backup /etc/rc.d/rc.local

#A iptables line has been added to restrict access to the SIP provider to block registration
#this command blocks all traffic help with registration when /sbin/iptables -A OUTPUT -s 64.197.13.6 -j DROP
#The below command will unblock the SIP Provider IP
/sbin/iptables -D OUTPUT -s 64.197.13.6 -j DROP

#now make a backup of the current sysconfig settings
tar -cvf /sysconfigbeforebackup.tar /etc/sysconfig/*

#now remove all old sysconf info
rm -rvf /etc/sysconfig/*

#copy current sysconfig info
cp -r /network-repair-info/* /etc/sysconfig/
#restart server
reboot

And that is it for now.  if you see any problems or better ways to do it please leave a comment for all to see!