Advertisement
Guest User

Untitled

a guest
Nov 18th, 2019
762
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.73 KB | None | 0 0
  1. FusionPBX Backup: (https://docs.fusionpbx.com/en/latest/getting_started/backup.html)
  2.  
  3. - find the db passowrd of postgresql - it's in /etc/fusionpbx/config.php under "$db_password" (and use in in place of the zzzzz in the code bellow)
  4. - in /etc/cron.daily create a file by the name of "fusionpbx-backup.sh"
  5. - in that file add the following code:
  6. #!/bin/sh
  7. now=$(date +%Y-%m-%d)
  8. echo "Server Backup"
  9. #password for this machine is ChEXt6hPitTFyksIjy1SUP3Q1oQ
  10. export PGPASSWORD="zzzzzzzz"
  11. db_host=127.0.0.1
  12. db_port=5432
  13. mkdir -p /var/backups/fusionpbx/postgresql
  14. #delete postgres logs older than 7 days
  15. find /var/log/postgresql/postgresql-11-main* -mtime +7 -exec rm {} \;
  16. #delete freeswitch logs older 3 days
  17. find /usr/local/freeswitch/log/freeswitch.log.* -mtime +2 -exec rm {} \;
  18. pg_dump --verbose -Fc --host=$db_host --port=$db_port -U fusionpbx fusionpbx --schema=public -f /var/backups/fusionpbx/postgresql/fusionpbx_pgsql_$now.sql
  19. echo "Backup Complete";
  20. - chmod +x fusionpbx-backup.sh
  21. - to set up automatic backups
  22. crontab -e
  23. Choose 1 for nano
  24. Goto the last blank line and paste in the next line.
  25. 0 0 * * * /bin/sh /etc/cron.daily/fusionpbx-backup.sh
  26. press enter then save and exit.
  27. - run the file: /etc/cron.daily/fusionpbx-backup.sh
  28. --------------------------------------------------------------------------------------------------
  29. *********************
  30. --------------------------------------------------------------------------------------------------
  31. FusionPBX Restore: (https://docs.fusionpbx.com/en/latest/getting_started/restore.html)
  32.  
  33. - create a file: fusionpbx-restore.sh
  34. - make sure to enable ssh on both computers (by typng the following into the terminal:
  35. sudo apt update
  36. sudo apt install openssh-server)
  37. - make sure that the Linux with the origin db has ssh as root enabled (
  38. in superuser mode open /etc/ssh/sshd_config, then find the line /maybe commented/ PermitRootLogin without-password and change it to PermitRootLogin yes
  39. then in the terminal run
  40. sudo service ssh restart
  41. )
  42. - note that the root password may differ from the password used to log into superuser mode on the origin machine - in case you don't know the root passowrd, you can change it with
  43. sudo passwd root
  44. - in case of forbidden ssh connection (also causing not to be able to ping the origin), it's likely caused by Fail2Ban - to fix that, open /etc/fail2ban/jail.conf and add the IP address /or range of addresses/ to the ignoreip = ...
  45. - get your db passrowrd from /etc/fusionpbx/config.php under "$db_password" (and use in in place of the zzz in the code bellow)
  46. - into the ./fusionpbx-restore.sh file add the following code (note that "Systemctl freeswitch status" is the way to restart the service in Debian; "service freeswitch restart" is for Ubuntu - in case of another operating system, do check the appropriate command):
  47. #!/bin/sh
  48. now=$(date +%Y-%m-%d)
  49. ssh_server=x.x.x.x
  50. database_host=127.0.0.1
  51. database_port=5432
  52. export PGPASSWORD="zzz"
  53.  
  54. #run the remote backup
  55. ssh -p 22 root@$ssh_server "nice -n -20 /etc/cron.daily/./fusionpbx-backup.sh"
  56.  
  57. #delete freeswitch logs older 7 days
  58. find /var/log/freeswitch/freeswitch.log.* -mtime +7 -exec rm {} \;
  59.  
  60. #synchronize the backup directory
  61. #rsync -avz -e 'ssh -p 22' root@$ssh_server:/var/backups/fusionpbx /var/backups
  62. rsync -avz -e 'ssh -p 22' root@$ssh_server:/var/backups/fusionpbx/postgresql /var/backups/fusionpbx
  63. rsync -avz -e 'ssh -p 22' root@$ssh_server:/var/www/fusionpbx /var/www
  64. rsync -avz -e 'ssh -p 22' root@$ssh_server:/etc/fusionpbx /etc
  65. find /var/backups/fusionpbx/postgresql -mtime +2 -exec rm {} \;
  66.  
  67. rsync -avz -e 'ssh -p 22' root@$ssh_server:/etc/freeswitch/ /etc
  68. rsync -avz -e 'ssh -p 22' root@$ssh_server:/var/lib/freeswitch/storage /var/lib/freeswitch
  69. rsync -avz -e 'ssh -p 22' root@$ssh_server:/var/lib/freeswitch/recordings /var/lib/freeswitch
  70. rsync -avz -e 'ssh -p 22' root@$ssh_server:/usr/share/freeswitch/scripts /usr/share/freeswitch
  71. rsync -avz -e 'ssh -p 22' root@$ssh_server:/usr/share/freeswitch/sounds /usr/share/freeswitch
  72.  
  73. echo "Restoring the Backup"
  74. #extract the backup from the tgz file
  75. #tar -xvpzf /var/backups/fusionpbx/backup_$now.tgz -C /
  76.  
  77. #remove the old database
  78. psql --host=$database_host --port=$database_port --username=fusionpbx -c 'drop schema public cascade;'
  79. psql --host=$database_host --port=$database_port --username=fusionpbx -c 'create schema public;'
  80. #restore the database
  81. pg_restore -v -Fc --host=$database_host --port=$database_port --dbname=fusionpbx --username=fusionpbx /var/backups/fusionpbx/postgresql/fusionpbx_pgsql_$now.sql
  82.  
  83. #restart freeswitch
  84. #systemctl stop freeswitch
  85. #systemctl start freeswitch
  86. service freeswitch restart
  87. echo "Restore Complete";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement