Understanding the Backup And Restore Script

Not open for further replies.


Apr 8, 2019
Can someone please give me some guidance as to the backup and restore procedure. I have and existing instance of FusionPBX on and would like to back it up and restore it to What is the idea of this script; is it to ssh into (the new server), run the script that creates a backup of and then it will be uploaded to the new server?

1.) SSH into or Which one?
2.) Run the backup and restore script with some of the values change.
3.) I'm not sure what IP address is suppose to go into the "ssh_server
4.) Is "export PGPASSWORD="xxxxxxx" supposed to be the superuse passwords of one of the servers? Which one?
5.) I have access to the daily backup from Can I not just upload / restore this to and if so how?

now=$(date +%Y-%m-%d)
export PGPASSWORD="xxxxxxx"

#run the remote backup
ssh -p 22 root@$ssh_server "nice -n -20 /etc/cron.daily/./fusionpbx-backup.sh"

#delete freeswitch logs older 7 days
find /var/log/freeswitch/freeswitch.log.* -mtime +7 -exec rm {} \;

#synchronize the backup directory
#rsync -avz -e 'ssh -p 22' root@$ssh_server:/var/backups/fusionpbx /var/backups
rsync -avz -e 'ssh -p 22' root@$ssh_server:/var/backups/fusionpbx/postgresql /var/backups/fusionpbx
rsync -avz -e 'ssh -p 22' root@$ssh_server:/var/www/fusionpbx /var/www
rsync -avz -e 'ssh -p 22' root@$ssh_server:/etc/fusionpbx /etc
find /var/backups/fusionpbx/postgresql -mtime +2 -exec rm {} \;

rsync -avz -e 'ssh -p 22' root@$ssh_server:/etc/freeswitch/ /etc
rsync -avz -e 'ssh -p 22' root@$ssh_server:/var/lib/freeswitch/storage /var/lib/freeswitch
rsync -avz -e 'ssh -p 22' root@$ssh_server:/var/lib/freeswitch/recordings /var/lib/freeswitch
rsync -avz -e 'ssh -p 22' root@$ssh_server:/usr/share/freeswitch/scripts /usr/share/freeswitch
rsync -avz -e 'ssh -p 22' root@$ssh_server:/usr/share/freeswitch/sounds /usr/share/freeswitch

echo "Restoring the Backup"
#extract the backup from the tgz file
#tar -xvpzf /var/backups/fusionpbx/backup_$now.tgz -C /

#remove the old database
psql --host=$database_host --port=$database_port --username=fusionpbx -c 'drop schema public cascade;'
psql --host=$database_host --port=$database_port --username=fusionpbx -c 'create schema public;'
#restore the database
pg_restore -v -Fc --host=$database_host --port=$database_port --dbname=fusionpbx --username=fusionpbx /var/backups/fusionpbx/postgresql/fusionpbx_pgsql_$now.sql

#restart freeswitch
service freeswitch restart
echo "Restore Complete";
Not open for further replies.