Moving FusionPBX to New Hardware

DigitalDaz

Administrator
Staff member
Sep 29, 2016
2,702
474
83

Directories to tar up:
Code:
/etc/freeswitch
/etc/fusionpbx
/var/www/fusionpbx
/var/lib/freeswitch/
/usr/share/freeswitch


Commands used:
Code:
tar -zcvf xxx.tgz xxx
tar -zxvf xxx.tgz -C /destination/path
su - postgres
pg_dump fusionpbx > /tmp/fusionpbx.sql
drop database fusionpbx
create database fusionpbx
alter user fusionpbx with password 'xxxxxxxxxxx'
psql fusionpbx < /tmp/fusionpbx.sql
 

AIC2000

Member
Feb 15, 2018
162
2
18
31
Also... you could script this up couldn't you, and create an rsync task so you'd have a redundant fusionpbx on a completely different network / service?

Then you could just switch the IP address and be good to go if there was a failure!
 

Andyd358

Member
Aug 23, 2018
215
8
18
52
UK
Also... you could script this up couldn't you, and create an rsync task so you'd have a redundant fusionpbx on a completely different network / service?

Then you could just switch the IP address and be good to go if there was a failure!
did you mange to do this?
 

PBXMePlz

Member
Mar 1, 2019
86
7
8
29
Directories to tar up:
Code:
/etc/freeswitch
/etc/fusionpbx
/var/www/fusionpbx
/var/lib/freeswitch/
/usr/share/freeswitch

Possibly resurrecting an old post here, but also kind of doing it on purpose as this did help me. What's the value to zipping up /etc/fusionpbx? If you restore it to a new install, ultimately seem to have problems with the database password and such. Does anyone really edit the files in /etc/fusionpbx? Easy enough to just let the new one be and restore everything else, yea?
 

PBXMePlz

Member
Mar 1, 2019
86
7
8
29
Here's a couple scripts that I'd say I got maybe 90% done and when tested were working. The goal was to have the backup on a cron, and the restore can be run on a separate machine. Likely going a slightly different direction so hopefully this helps someone. It requires rclone, which is rather easy to use.

backup.sh
Code:
#!/bin/sh

export PGPASSWORD=$(cat /etc/fusionpbx/config.php | grep db_password | awk {'print $3'} | tr -d /\'/\;)
db_host=127.0.0.1
db_port=5432

now=$(date +%Y-%m-%d)
bucket=wasabi:wasabibucket/pbxbackups/`hostname`

mkdir -p /var/backups/fusionpbx/postgresql

echo "Backup Started"

#delete postgres backups
find /var/backups/fusionpbx/postgresql/fusionpbx_pgsql* -mtime +4 -exec rm {} \;

#delete the main backup
find /var/backups/fusionpbx/*.tgz -mtime +2 -exec rm {} \;

#backup the database
pg_dump --verbose -Fc --host=$db_host --port=$db_port -U fusionpbx fusionpbx --schema=public -f /var/backups/fusionpbx/postgresql/fusionpbx_pgsql_$now.sql

#package
#tar --exclude='/var/lib/freeswitch/recordings/*/archive' -zvcf /var/backups/fusionpbx/backup_$now.tgz /var/backups/fusionpbx/postgresql/fusionpbx_pgsql_$now.sql /var/www/fusionpbx /usr/share/freeswitch/scripts /var/lib/freeswitch/storage /var/lib/freeswitch/recordings /etc/fusionpbx /etc/freeswitch /usr/share/freeswitch/sounds/music/

#source
#tar -zvcf /var/backups/fusionpbx/backup_$now.tgz /var/backups/fusionpbx/postgresql/fusionpbx_pgsql_$now.sql /var/www/fusionpbx /usr/local/freeswitch/scripts /usr/local/freeswitch/storage /usr/local/freeswitch/recordings /etc/fusionpbx /usr/local/freeswitch/conf /usr/local/freeswitch/sounds/music/

tar --exclude='/var/lib/freeswitch/recordings/*/archive' -zvcf /var/backups/fusionpbx_backup_$now.tgz /var/backups/fusionpbx /var/www/fusionpbx /etc/fusionpbx /etc/freeswitch /var/lib/freeswitch /usr/share/freeswitch

rclone copy /var/backups/fusionpbx_backup_$now.tgz $bucket/

#rclone sync /var/backups/fusionpbx $bucket/var/backups/fusionpbx
#rclone sync /var/www/fusionpbx $bucket/var/www/fusionpbx
#rclone sync /etc/fusionpbx $bucket/etc/fusionpbx

#rclone sync /etc/freeswitch $bucket/etc/freeswitch
#rclone sync /var/lib/freeswitch $bucket/var/lib/freeswitch
#rclone sync /usr/share/freeswitch $bucket/usr/share/freeswitch

echo "Backup Completed"

restore.sh
Code:
#!/bin/sh
export PGPASSWORD=$(cat /etc/fusionpbx/config.php | grep db_password | awk {'print $3'} | tr -d /\'/\;)

now=$(date +%Y-%m-%d)
bucket=wasabi:wasabibucket/pbxbackups/pbxdev

mkdir -p /var/backups/fusionpbx/postgresql

echo "Stopping Freeswitch"
systemctl stop freeswitch

echo "Restore Started"

rclone copy $bucket/fusionpbx_backup_$now.tgz /var/backups/full_backup_$now.tgz

tar -zvcf /var/backups/fusionpbx_backup_$now.tgz /var/backups/fusionpbx /var/www/fusionpbx /etc/freeswitch /var/lib/freeswitch /usr/share/freeswitch

#rclone sync $bucket/var/backups/fusionpbx /var/backups/fusionpbx
#rclone sync $bucket/var/backups/fusionpbx/postgresql /var/backups/fusionpbx/postgresql
#rclone sync $bucket/var/www/fusionpbx /var/www/fusionpbx

#rclone sync $bucket/etc/freeswitch /etc/freeswitch
#rclone sync $bucket/var/lib/freeswitch /var/lib/freeswitch
#rclone sync $bucket/usr/share/freeswitch /usr/share/freeswitch

echo "Dumping Existing Database"

psql --host=127.0.0.1 --port=5432 --username=fusionpbx -c 'drop schema public cascade;'
psql --host=127.0.0.1 --port=5432 --username=fusionpbx -c 'create schema public;'

echo "Restoring Database"

pg_restore -v -Fc --host=127.0.0.1 --port=5432 --dbname=fusionpbx --username=fusionpbx /var/backups/fusionpbx/postgresql/fusionpbx_pgsql_$now.sql

echo "Deleting Cache"

rm -r /var/cache/fusionpbx/*

echo "Starting Freeswitch"

systemctl start freeswitch

echo "Restore Complete"