Understanding the Backup And Restore Script

Status
Not open for further replies.

mc6650

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

1.) SSH into 192.168.2.10 or 192.168.2.109? 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 192.168.2.10. Can I not just upload / restore this to 192.168.2.109 and if so how?

#!/bin/sh
now=$(date +%Y-%m-%d)
ssh_server=192.168.2.10
database_host=127.0.0.1
database_port=5432
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";
 
Status
Not open for further replies.