restore.rst 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. *********
  2. Restore
  3. *********
  4. |
  5. It's always good to have a restore method of a backup in place. Here are the steps to a basic restore method with FusionPBX.
  6. .. Note:: It is important to know if your installation is from package or source as the paths are different for FreeSWITCH. Always test the backups and restore methods on test machines first.
  7. * To create the script use an editor such as vi or nano.
  8. * Copy/Paste from the code block below and save the file as fusionpbx-restore.sh
  9. * Replace zzz with your database password
  10. * chmod + x fusionpbx-restore.sh and then run the script ./fusionpbx-restore.sh
  11. * edit the script as needed and run this script from the server you are restoring on.
  12. ::
  13. #!/bin/sh
  14. now=$(date +%Y-%m-%d)
  15. ssh_server=x.x.x.x
  16. database_host=127.0.0.1
  17. database_port=5432
  18. export PGPASSWORD="zzz"
  19. #run the remote backup
  20. ssh -p 22 root@$ssh_server "nice -n -20 /etc/cron.daily/./fusionpbx-backup.sh"
  21. #delete freeswitch logs older 7 days
  22. find /var/log/freeswitch/freeswitch.log.* -mtime +7 -exec rm {} \;
  23. #synchronize the backup directory
  24. #rsync -avz -e 'ssh -p 22' root@$ssh_server:/var/backups/fusionpbx /var/backups
  25. rsync -avz -e 'ssh -p 22' root@$ssh_server:/var/backups/fusionpbx/postgresql /var/backups/fusionpbx
  26. rsync -avz -e 'ssh -p 22' root@$ssh_server:/var/www/fusionpbx /var/www
  27. rsync -avz -e 'ssh -p 22' root@$ssh_server:/etc/fusionpbx /etc
  28. find /var/backups/fusionpbx/postgresql -mtime +2 -exec rm {} \;
  29. rsync -avz -e 'ssh -p 22' root@$ssh_server:/etc/freeswitch/ /etc
  30. rsync -avz -e 'ssh -p 22' root@$ssh_server:/var/lib/freeswitch/storage /var/lib/freeswitch
  31. rsync -avz -e 'ssh -p 22' root@$ssh_server:/var/lib/freeswitch/recordings /var/lib/freeswitch
  32. rsync -avz -e 'ssh -p 22' root@$ssh_server:/usr/share/freeswitch/scripts /usr/share/freeswitch
  33. rsync -avz -e 'ssh -p 22' root@$ssh_server:/usr/share/freeswitch/sounds /usr/share/freeswitch
  34. echo "Restoring the Backup"
  35. #extract the backup from the tgz file
  36. #tar -xvpzf /var/backups/fusionpbx/backup_$now.tgz -C /
  37. #remove the old database
  38. psql --host=$database_host --port=$database_port --username=fusionpbx -c 'drop schema public cascade;'
  39. psql --host=$database_host --port=$database_port --username=fusionpbx -c 'create schema public;'
  40. #restore the database
  41. pg_restore -v -Fc --host=$database_host --port=$database_port --dbname=fusionpbx --username=fusionpbx /var/backups/fusionpbx/postgresql/fusionpbx_pgsql_$now.sql
  42. #restart freeswitch
  43. service freeswitch restart
  44. echo "Restore Complete";