restore.rst 2.5 KB

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