FreePBX Backup: Creation and Restoration, Part 4

FreePBX installation

The importance of a backup is only truly understood by those who have had to recover files from damaged data storage. Server administrators fall into two categories: those who perform backups, and those who will start performing backups. In this article, we will learn how to create backups locally, on an FTP server, on Dropbox and Amazon S3, and how to send them to an email address and via SSH.

Settings -> Filestore

First, let’s navigate to Settings -> Filestore. In this window, there are several tabs, depending on where we want to store our backup files.

image 73

Settings -> Filestore -> Local

We will start by creating a backup locally on the hard drive where your FreePBX system is installed. A local copy is useful when you want to test various FreePBX settings and are concerned that changing them might cause your telephone exchange to stop working correctly. However, remember that in addition to local copies, you should also create backups that are sent remotely to an FTP server, Dropbox, etc. A local backup will be useless if the hard drive on which FreePBX is installed fails.

image 74

Go to the Local tab and click the Add local path button. A new window will appear where you need to enter:

  • Path name: A name for your Filestore settings. It can be anything, for example, Local Copy.
  • Description: Any description, for example, Local copy on the hard drive.
  • Path: The path on the hard drive where the backups will be stored. We can use variables suggested by FreePBX. For example, the variable __ASTSPOOLDIR__ (remember the double underscores before and after) represents the /var/spool/asterisk/ folder. We can add backup at the end, so we know the files in this folder are backups. Therefore, entering __ASTSPOOLDIR__/backup is exactly the same as /var/spool/asterisk/backup.

Finally, confirm the changes with the Submit button.

image 75

Settings -> Filestore -> FTP

If you have access to an FTP server, you should definitely use the option to send backups to it. This significantly increases the security of your FreePBX telephone exchange. If you only make local backups, in the event of a hard drive failure, all local backups will also be lost. If you don’t know how to set up an FTP server at home, you can purchase affordable server space in the cloud, for instance at Zetohosting, where you will also get FTP server access as part of the hosting package.

First, in the Filestore window under the FTP tab, we will enter the settings that will allow us to log in to the server. Click the Add FTP Instance button and fill in the required fields in the new window:

image 76
  • Enabled: This button enables or disables the data store.
  • Server Name: Any name for your data store.
  • Description: Any description.
  • Hostname: The IP address of your FTP server, or the domain name.
  • Port: The port on which your FTP server operates.
  • Use TLS: If your FTP server requires SSL/TLS encryption, enable this option.
  • Username: The username for the FTP server.
  • Password: The password.
  • Filesystem type: If you know the operating system of your FTP server, select the appropriate option. If you are unsure, select Auto.
  • Path: The access path where backups will be saved. Note: provide the full path (starting with /), otherwise your Filestore will not work.
  • Transfer Mode: Choose Active or Passive mode for your FTP server.
  • Timeout: The inactivity time in seconds after which the connection to the FTP server will be terminated.

You should receive all the necessary data to configure the FTP connection from your FTP server provider.

Admin -> Backup & Restore

Once we have created a location to save the files, we can go to the Admin -> Backup & Restore window. In the Backup tab, click Add Backup to configure a new backup. For my needs with FreePBX, I usually set up monthly and weekly backups, keeping the last three weekly copies and one from each of the last three months. Of course, there is nothing stopping you from creating daily or quarterly backups. It all depends on how much hard drive space you can allocate for backups. Let’s start by setting up monthly backups.

Basic Information

  • Backup name: Any name, for example, Monthly Copies. (It’s worth avoiding special characters in the name. I’ll explain why shortly.)
  • Backup Description: Any description, for example, Keep copies from the last 3 months.
  • Backup Items: Here you choose which FreePBX modules should be included in the backup. A good starting point is to back up all modules, so don’t change anything here.
  • Custom Files: If you have manually copied any files to your FreePBX (for example, via FTP) and they are stored outside the FreePBX/Asterisk folders, and you want them to be included in the backup, you must tell FreePBX where they are located. If you haven’t copied any additional files, you don’t need to worry about this.

Notifications

  • Notification Email: Your email address to which notifications about completed backups or errors during backup creation will be sent.
  • Inline Logs: Includes logs from the backup process in the email message.
  • Email Type: Sends an email notification only if the backup was successful (Success), ended in an error (Failure), or in both cases (Both).

Storage

  • Storage location: Here we select the location—which we created earlier in the Filestore window—where our backups will be stored. In our case, it will be Local Copy.
  • Append Backup Name as a directory to the Storage path: If you enable this option, an additional directory with the name of our backup will be created in the directory where our backups are saved (in our case /var/spool/asterisk/backup/). In this instance, it would be Monthly Copies. This helps to keep the backups organised and makes it easier to find the one you need in case of a failure. This is why I mentioned earlier to avoid diacritical characters in the name, to prevent character encoding issues.

Schedule and Maintenance

Here we set whether we want backups to be performed automatically at scheduled intervals.

  • Enabled: Enables the backup schedule.
  • Scheduling: Sets the frequency of the backups. We can set it to run hourly, daily, weekly, monthly, or yearly.

Maintenance

In this section, we set how many copies we want to keep on the disk and when unnecessary copies should be deleted.

  • Delete After Runs: Here we set the number of recent copies we want to keep. In our case, we want to keep the last 3 copies. All copies over three will be deleted. If we set it to 0, copies will not be deleted at all.
  • Delete After Days: We can also set a time after which copies will be deleted, regardless of how many copies we have. I suggest setting this to Unlimited.

Note: If we set the first option to 0 and the second to Unlimited, the copies will never be deleted. As backups can be large, you might find that you quickly fill up your disk space.

Hooks

Here you can set what the computer should do before or after performing or restoring a backup. For example, after a backup, you can compress the files or transfer them to a remote server. You can also copy the backups to a connected USB stick—for this, you can mount it in this window before the backup is made. If you haven’t written scripts in Linux before, you don’t need to worry about this.

Warm Spare

If our FreePBX telephone exchange serves a large company and you cannot afford any downtime, you can install a second FreePBX server that will be synchronised with the main exchange. In the event of a failure, you can quickly switch your telephony to the backup FreePBX server. If you do not have two FreePBX servers, you can skip these options.

Save

Finally, we save our settings with the Save button.

Manual Backup Execution

After saving the settings, you can check if the backup is performed correctly by running it manually. To do this, press the arrow button as shown in the image below.

image 77

If all settings are correct, you should see the message “Finished created backup file” in the program logs.

To be extra sure that the backup was created, you can log in to the FreePBX console via SSH and check the backup save path, which in our case will be /var/spool/asterisk/backup/.

Navigate to the backup directory with the command cd /var/spool/asterisk/backup/ and list the contents of the directory with ls. As you can see in the attached illustration, an additional subfolder Monthly-Copies has been created. Open this folder with the command cd Monthly-Copies and list its contents with ls. As you can see, the backup file has been created correctly inside this directory.

[root@creativeart ~]# cd /var/spool/asterisk/backup/
[root@creativeart backup]# ls
Monthly-Copies
[root@creativeart backup]# cd Monthly-Copies/
[root@creativeart Monthly-Copies]# ls
20230218-085312-1676710392-16.0.33-1234817093.tar.gz
[root@creativeart Monthly-Copies]#

Admin -> Backup & Restore -> Restore

After creating our first backup, we should be able to see it in the Restore tab. Next to each backup, there is an Actions window where we can restore the backup, download it to our computer’s hard drive, or delete it. After downloading the copy to your computer, you can re-upload it to the server in the Upload your restore files window by clicking the Click to upload a backup file button.

To use the Restore from the cloud option, we must first configure Filestore to have access to cloud file storage services.

image 78

Summary

You now know how to automatically create and restore backups both on a local disk and on a remote FTP server. Now, in the event of any failure, you can easily restore your FreePBX telephone exchange to working order.

Komentarze

Leave a Reply

Your email address will not be published. Required fields are marked *