Title: FreePBX Backup and Restore

Your PBX includes a number of pre-defined backup templates that backup selected components of a PBX installation.

  • "CDR's" template backup
    • Includes the local call detail record database (MySQL Database named "asteriskcdrdb"),
  • "Config Backup" template backup
    • Includes the local configuration database (MySQL Database named "asterisk"),
    • It does not include configuration customizations that may have been made in /etc/asterisk/*.conf files (e.g. *_custom.conf files) – the "Full Backup" template (below) includes those
  • "Full Backup" template backup
    • includes the "CDR's" backup template items (Above)
    • includes the "Config Backup" backup template items (Above)
    • includes the directory referenced by the variable __ASTETCDIR__, by default "/etc/asterisk", and all subdirectories and files

    • Includes the directory referenced by the variable __AMPWEBROOT__, by default "/var/www/html", and all subdirectories and files (PBX web administration console modules are in this directory tree)
    • Includes the directory referenced by the variable __AMPSBIN__, by default "/usr/sbin", and all subdirectories and files
    • Includes the directory "/etc/dahdi"
    • it does not include user voicemails, voice mailbox greetings or system audio greeting recordings
  • "Safe Remote Restore" template backup
    • this is the same as "Config Backup" but excluding settings relating to the backup module itself
  • "System Audio" template backup
    • Includes the directory referenced by the variable __ASTVARLIBDIR__/moh, by default "/var/lib/asterisk/moh", and all subdirectories and files (this is for music on hold files)
    • Includes the directory referenced by the variable __ASTVARLIBDIR__/sounds/custom, by default "/var/lib/asterisk/sounds/custom", and all subdirectories and files (this is for custom system recordings such as IVR menu recordings)
  • "Voice Mail" template backup
    • Includes the directory referenced by the variable __ASTSPOOLDIR__/voicemail, by default "/var/spool/asterisk/voicemail", and all subdirectories and files (this is for extension voice mail greetings and messages)
Icon

The file "amportal.conf" does not need to be backed up – it is generated from the configuration database automatically

About backup storage locations

 

Backup storage destinations can be viewed and edited by clicking "Servers" on the right.

There are two default disk storage locations for backup files.

  • "Local Storage (local)" (this is the usual option)
    • The backup tarball file is stored in "/var/spool/asterisk/backup/(backupjobname)/*.tgz" on the local machine
  • "Legacy Backup (local)"
    • This is only used for backups made by FreePBX earlier than ver. 2.10

Additional locations can be created to send backups to an e-mail account, a remote FTP server, a remote server using SFTP, or a remote MySQL server. These options are used for sending backups to a different server or site, or for setting up a warm standby FreePBX system.

About the default "Default backup" backup

  • This is a monthly backup done the first of every month using the "Config Backup" backup template

Access the Backup and Restore module

FreePBX 2.10

  • Admin > Backup & Restore

Backup and Restore module initial configuration

Set the From e-mail address

This is the e-mail address the the backup module will send e-mail from if configured to send backups to an e-mail address. By default, the backup module is not configured to do this, and this from e-mail address is left blank.

FreePBX 2.10

  • Settings > Advanced Settings
    • Backup Module
      • Email "From:" Address: enter the From e-mail address, e.g. "pbxbackups@domain.org"
      • click the green "Save" check mark next to the field
        • Apply Config

Creating a backup job

Example: Configure a full backup

This is a full backup of all PBX configuration and user audio data, done once a day at midnight.

  • Backups (on the right-hand menu)
    • click "New Backup"
  • Backup
    • Backup Name: "fullbackup"
    • Description?: "full backup of all FreePBX configuration settings, system audio files and voicemail run at midnight each day"
  • Items
    • drag-and-drop the following template items onto the "Type Path/DB Exclude Delete" line
      • "Full Backup"
      • "System Audio"
      • "Voice Mail"
  • Backup Server
    • select "This server" (the default – this assumes the CDR database is not on a remote server)
  • Storage Locations
    • drag-and-drop "Local Storage (local)" from the "Available Servers" box to the "Storage Servers" box
  • Backup Schedule
    • Run: select "Daily" (the time is automatically set to be at midnight)
    • Randomize: leave disabled (the default) unless backups should have their times randomly adjusted to avoid generating network or system load at always the same time of day
  • Maintenance
    • "Delete after": 21 days (thus keeping three weeks of backup history)
    • "Delete after": 0 runs (don't purge backup history on the basis of number of runs)
  • Save

The backup will appear on the small menu on the right.

Test the backup using the manual backup process, below.

Example: Configure a voicemail-only backup

This is a second scheduled job that backs up only the voicemail at noon each day. This backup augments the backup above by providing some protection from users mistakenly deleting a voicemail they received the same day, which will not be in the nightly full daily backup yet.

  • Backups (on the right-hand menu)
    • click "New Backup"
  • Backup
    • Backup Name: "voicemailonlybackup"
    • Description?: "backup of just voicemail run at noon each day"
  • Items
    • drag-and-drop the following template items onto the "Type Path/DB Exclude Delete" line
      • "Voice Mail"
  • Storage Locations
    • drag-and-drop "Local Storage (local)" from the "Available Servers" box to the "Storage Servers" box
  • Backup Schedule
    • Run: select "Custom"
    • Minutes: select "00"
    • Hour: select "12"
    • Day of Week: leave no items selected (this means every day of the week)
    • Month leave no items selected (this means every month)
    • Day of Month: leave no items selected (this means every day of the month)
  • Maintenance
    • select "Delete after": 21 days (keeping three weeks of backup history)
  • Save

The backup will appear on the small menu on the right.

Test the backup using the manual backup process, below.

Manual backup test

  • Click Backups (on the right-hand menu)
    • click on the desired backup job on the right-hand menu (e.g. "fullbackup")
  • click "and Run" at the bottom of the web page
    • a backup status window will display showing backup progress
    • the last line should be "Backup successfully completed!"
  • close the backup status window (there is no OK or Close button, just click the top-right window close control)

Backup verification

  • Verify that a new backup file has been created in /var/spool/asterisk/backup/fullbackup/*.tgz where the filename will reflect the backup date and time
  • Verify the file size looks reasonable
    • For example, a backup including "Full Backup", "System Audio" and "Voice Mail" on a mostly empty new FreePBX Distro installation is about 120MB in size
  • Verify the file listing of the tar file looks reasonable
tar --list --file /var/spool/asterisk/backup/fullbackup/20130503-164647-1367614007-1697135908.tgz
    • Sample output
./
./etc/
./etc/asterisk/
./etc/asterisk/queues_general_additional.conf
./etc/asterisk/sip_notify_custom.conf
./etc/asterisk/chan_dahdi.conf.template
...
./etc/dahdi/
./etc/dahdi/system.conf
./etc/dahdi/genconf_parameters
./etc/dahdi/init.conf
./etc/dahdi/modules
./etc/freepbx.conf
./mysql-4.sql
./mysql-3.sql
./.lock
./manifest
./var/
./var/lib/
./var/lib/asterisk/
./var/lib/asterisk/sounds/
./var/lib/asterisk/sounds/custom/
...
./var/www/
./var/www/html/
./var/www/html/robots.txt
./var/www/html/index.html
./var/www/html/admin/
./var/www/html/admin/images/
...
./usr/sbin/warnquota
./usr/sbin/pvscan
./astdb
  • Extract one sample file
cd /tmp
tar xvf /var/spool/asterisk/backup/fullbackup/20130503-164647-1367614007-1697135908.tgz ./astdb
vi /tmp/astdb
# the contents will be a solid block of text containing strings like AMPUSER and EXTENSION
rm /tmp/astdb

Restore a backup

Icon

Ensure the exact same version of FreePBX Distro and same version of the Backup & Restore module is installed on the target restore system as used on the backed-up system if at all possible.

  • Restore (on the right-hand menu)
    • if the backup to restore was made on the same server, click "Local Storage (local)" on the right menu to see a list of previous local backups and select the desired one
    • if the backup to restore is a separate file, click "Browse..." and select the backup .tgz file
    • click "Go!"
      • The backup file will be scanned and a list of contents displayed
    • Select files and databases to restore
      • check the item(s) to restore
    • click "Restore" to do the restore

Monitoring of backups

Configuring e-mail notifications

The user asterisk will, by default, get an e-mail containing cron job output from each backup, indicating if the backup succeeded or failed. To get these, edit /etc/aliases and ensure that the user asterisk has e-mail directed to a monitored e-mail address.

Configure e-mail redirection to a monitored e-mail account

vi /etc/aliases
  • add the redirection of the asterisk local user to the root local user, and direct all e-mail to the root local user to a monitored e-mail address
...
# Customization: all of the "asterisk" user's mail should be directed to the local root user
asterisk: root
# Customization: all of the "root" user's mail should be directed to a monitored e-mail address (note: redirection ordering matters; the root user redirection should be last in the file)
root: myemailaddress@domain.org
Icon

It also works just to redirect e-mail to the asterisk user directly to an external e-mail address. However, it is a recommended best practice to direct all other users' e-mail first to the root user, and then ensure e-mail to the root user is sent to a human being. This will ensure that e-mails sent by other programs on a FreePBX server which send to root by default (such as mdadm RAID monitoring) will also be seen.

  • reload the aliases file
newaliases
  • verify delivery
echo "This is a test e-mail to the local asterisk account. It should go to the actual monitored e-mail address through the /etc/aliases file." | mail -s "E-mail test to local asterisk account" asterisk; tail -f /var/log/maillog | grep "status="
 
# expected result (two successful sends, one to the local account and one to the external e-mail address)
May  3 17:38:16 ... postfix/local[8423]: BB4CB1D61804: to=, orig_to=, relay=local, delay=0.08, delays=0.06/0.01/0/0.01, dsn=2.0.0, status=sent (forwarded as C43981D6176C)
May  3 17:38:16 ... postfix/smtp[8424]: C43981D6176C: to=, orig_to=, relay=..., delay=0.07, delays=0.01/0.01/0.01/0.04, dsn=2.0.0, status=sent (250 Message accepted for delivery)
  • Confirm the test e-mail was received
  • Confirm the next normally scheduled backup sends a backup status e-mail

Troubleshooting

Verify asterisk user backup cron jobs

The web user interface creates cron jobs for the user asterisk that perform the actual backups. It is helpful when troubleshooting to confirm these cron jobs are present.

  • Display cron jobs for the user asterisk
crontab -u asterisk -l
  • The line "@monthly /var/lib/asterisk/bin/backup.php --id=1" is the cron job for the default once-a-month backup job called "Default backup"
  • If other backup jobs have been defined, additional jobs calling backup.php with other ID numbers (e.g. 2, 3, ...) should display
...
@monthly /var/lib/asterisk/bin/backup.php --id=1
Authored by: Guru Corner on Thu, Sep 19th, 2013 at 6:00 PM
This question has been viewed 23824 times so far.
Online URL: http://kb.guru-corner.com/question.php?ID=320

Powered by Guru Corner