How to backup AstDB with FreePBX15 Backup Module


First of all, great work to the redesigned FreePBX 15 backup/restore module!

I use fop2 and I would like to create a backup job which will backup just that and the AsteriskDB. I can add the fop2 directories no problem using the custom files/directories but how would one backup the AstDB ?

With the FreePBX 14 Backup job, I would simply add the AsteriskDB to the backup selection but I’m unsure how to achieve this with the new FreePBX 15 Backup Module.


Hi @Fraser Backup & Restore in FreePBX 15 has been completely redesigned where each module is responsible for its own data to backup and restore hence as of now no common way of backing up asteriskdb.

Ok thanks.

So how would one backup dynamic queue members, find me, extension state etc etc which are stored in AstDB?

Would backing up /var/lib/asterisk/astdb.sqlite3 be enough?


Related modules will take care of backup of there respective configuration (from asteriskdb) and also restoring the same for example queues module can take care of “dynamic queue members” configuration backup and restore.

Thanks @kgupta1. Understood.

Looking at the AstDB, fop2 stores information in here so my only option, I think, is to manually backup /var/lib/asterisk/astdb.sqlite3 by the use of a Custom File in the FreePBX Backup job.

I’ve just tested and I think it works ok. FreePBX required a restart in order to read the restored AstDB but I can live with that. I’ll test more later on when I have more time to play.


Hi @Fraser okay thanks and good to know custom file option is working well for you. thanks.

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:

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:

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


  • 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:

This is good stuff @Fraser. This would make a good addition to the community documentation project if you’re so inclined … FreePBX Community Documentation


I have a wee issue with the restoring on to the FreePBX 15 Spare machine so let me get that fixed first of all.

I haven’t looked into it yet but I have a hunch that it’s possibility a “path” issue - PBX1 saving the file on PBX2 at: /var/spool/asterisk/backup/backupfile.tar.gz but the API is telling PBX2 to restore from a backup file located at: /var/spool/asterisk/backup/mybackupjob/backupfile.tar.gz. Like I said, I havent looked into this yet and it’s only a hunch!

In the Backup log generated from PBX1 I do get an API “Success” message but I think that is just a “Success, we told PBX2 to start the restore process” however ultimately the outcome of that restore process job failed, which is not reported back over the API to PBX1… I could be wrong.

An update for the Backup Module was just released again this afternoon so maybe that will solve it (however I believe that update was the Pre/Post Back/Restore Scripts.)


1 Like

I woke up this morning and my warm spare box is an exact replica of my Primary box so this looks to be fixed!

Maybe this fixed it! :slight_smile:


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.