How to backup AstDB with FreePBX15 Backup Module

Hi @kgupta1. I just want to say thanks for all the hard work you and the FreePBX team have done.

Using the FreePBX 15 Backup module with a couple of scripts, I have now been able to achieve taking and restoring a backup of fop2. I am using this as part of a FreePBX 15 Warm Spare Setup that I am building.

For anyone searching the forums and are looking to backup fop2 then this is how to do it:

Within your Backup job, add the following custom files/directories:
Directory: /usr/local/fop2
Directory: /var/www/html/fop2
File: /var/lib/asterisk/astdb.sqlite3

Now create the following Pre-Backup Hook script:

#!/bin/bash
DBUSER=cat /etc/freepbx.conf | sed 's/ //g' | grep AMPDBUSER | tail -n 1 | cut -d\" -f4
DBPASS=cat /etc/freepbx.conf | sed 's/ //g' | grep AMPDBPASS | tail -n 1 | cut -d\" -f4
mysqldump --add-drop-table -u $DBUSER -p$DBPASS asterisk $(mysql -u $DBUSER -p$DBPASS -D asterisk -Bse “SHOW TABLES LIKE ‘fop2%’”) > /usr/local/fop2/fop2_backup.sql

Now create the following Post Restore Hook script:

#!/bin/bash
DBUSER=cat /etc/freepbx.conf | sed 's/ //g' | grep AMPDBUSER | tail -n 1 | cut -d\" -f4
DBPASS=cat /etc/freepbx.conf | sed 's/ //g' | grep AMPDBPASS | tail -n 1 | cut -d\" -f4
mysql -u $DBUSER -p$DBPASS asterisk < /usr/local/fop2/fop2_backup.sql
fwconsole restart
sleep 30
systemctl restart fop2

Notes:

  • The Pre-backup and Post-restore scripts need to be owned by the Asterisk user and must be executable.
  • My advice would be to place these scripts inside /usr/local/fop2 as they will be included in the backup and therefore move over automatically.
  • If you a backing up and restoring to a Warm Spare Server (which I am), then you want to exclude fop2.lic and fop2_server from the /usr/local/fop2 directory. (Each server should have it’s own fop2_server and licence (plus a licence for any plugins you use)
  • Restoring will restart FreePBX on the destination server and therefore active calls on that server will be dropped. Since I am doing this as part of a Warm Spare Setup, there will be no calls so that’s OK :wink:
3 Likes