Backup & Restore

marc8lange

New Member
Oct 29, 2018
6
0
1
Does anyone have a workflow for a backup and restore in FS PBX?

So far I have backup figured out.

1) SSH in server
2) then cd /var/www/fspbx
3) then simply type "php artisan fspbx:backup" without quotes and it runs a backup.
4) Download the folder /var/backups/fspbx - it now contains the files and database you can use to restore

However i can't find an artisan restore command...and running my own script has led me down an exploratory 6 hours rabbit hole of trying to match database passwords and usernames in order to bring a GUI back up and synchronize everything...I can work on a restore script ...

but checking to see if anyone has a workflow out there.
 
Hi @marc8lange, we don't have an official restore script. The backup archive is best used for disaster recovery or off-site backups. A more straightforward way to restore your server is to install a new version of FS PBX and then restore the database from the backup folder. Our latest version of the backup script grabs your faxes, recordings and voicemail folder too. Those can be copied manually into the respective folders.

The backup script can also be enabled to run daily. Go to Default Settings -> Scheduled Jobs and enable it.

FS PBX supports full database replication and file sync between two or more servers in a cluster. It's a master to master replication, which allows you to have one server on standby. Most of our clients set up their infrastructures this way to eliminate any possible downtime. You can think of this as a backup, also in case one server becomes unoperational. Synchonizeion is real-time, so your data is always present on all nodes.
 
Hi @pbxgeek thank you for the response.

I'm approaching this in 2 steps, as I kick the tires, first can backup and restore be done without error, and second explore master-master replication as an operational model.

But restoring an offsite back is essential and can't be replaced by replication.

I did discover the Default Settings -> Scheduled Jobs ---> backup setting to true, thank you.

However the restoring has been frustrating trying to match old and new database passwords in both fusionpbx and artisan and the .env file, running into php errors, missing migration, incomplete seeding, etc

I'll give it one more go at restoring.

script I'll try next (thx / nothx to AI)
----

#!/bin/bash
set -e # stop on first error
now=$(date +%Y-%m-%d)

CONFIG_FILE="/etc/fusionpbx/config.conf"

if [ ! -f "$CONFIG_FILE" ]; then
echo "❌ Could not find $CONFIG_FILE"
exit 1
fi

# Parse database settings
database_host=$(grep '^database.0.host' $CONFIG_FILE | cut -d '=' -f2 | xargs)
database_port=$(grep '^database.0.port' $CONFIG_FILE | cut -d '=' -f2 | xargs)
database_name=$(grep '^database.0.name' $CONFIG_FILE | cut -d '=' -f2 | xargs)
database_user=$(grep '^database.0.username' $CONFIG_FILE | cut -d '=' -f2 | xargs)
export PGPASSWORD=$(grep '^database.0.password' $CONFIG_FILE | cut -d '=' -f2 | xargs)

echo "Using DB connection: $database_user@$database_host:$database_port/$database_name"

BACKUP_FILE="/var/backups/fspbx/postgresql/fusionpbx_pgsql_$now.sql"
TARBALL="/var/backups/fspbx/backup_$now.tgz"

# Extract files (optional)
if [ -f "$TARBALL" ]; then
echo "Extracting backup archive..."
tar -xvpzf "$TARBALL" -C /
else
echo "⚠️ No tarball found for $now, skipping filesystem restore"
fi

# Confirm before dropping DB
read -p "⚠️ This will ERASE the current database. Continue? (yes/no): " yn
if [ "$yn" != "yes" ]; then
echo "Aborted."
exit 1
fi

# Drop and recreate schema
psql --host=$database_host --port=$database_port --username=$database_user -d $database_name -c 'drop schema public cascade;'
psql --host=$database_host --port=$database_port --username=$database_user -d $database_name -c 'create schema public;'

# Restore DB
if [ ! -f "$BACKUP_FILE" ]; then
echo "❌ Backup file $BACKUP_FILE not found."
exit 1
fi

echo "Restoring database from $BACKUP_FILE..."
psql --host=$database_host --port=$database_port --username=$database_user -d $database_name < "$BACKUP_FILE"

# Restart FreeSWITCH
systemctl restart freeswitch || service freeswitch restart

echo "✅ Restore Complete"
 
If you end up with a final result at some point, send me a pull request to add the script to the repository. Others may find it very useful. Thank you for sharing.