Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- FusionPBX Backup: (https://docs.fusionpbx.com/en/latest/getting_started/backup.html)
- - 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)
- - in /etc/cron.daily create a file by the name of "fusionpbx-backup.sh"
- - in that file add the following code:
- #!/bin/sh
- now=$(date +%Y-%m-%d)
- echo "Server Backup"
- #password for this machine is ChEXt6hPitTFyksIjy1SUP3Q1oQ
- export PGPASSWORD="zzzzzzzz"
- db_host=127.0.0.1
- db_port=5432
- mkdir -p /var/backups/fusionpbx/postgresql
- #delete postgres logs older than 7 days
- find /var/log/postgresql/postgresql-11-main* -mtime +7 -exec rm {} \;
- #delete freeswitch logs older 3 days
- find /usr/local/freeswitch/log/freeswitch.log.* -mtime +2 -exec rm {} \;
- pg_dump --verbose -Fc --host=$db_host --port=$db_port -U fusionpbx fusionpbx --schema=public -f /var/backups/fusionpbx/postgresql/fusionpbx_pgsql_$now.sql
- echo "Backup Complete";
- - chmod +x fusionpbx-backup.sh
- - to set up automatic backups
- crontab -e
- Choose 1 for nano
- Goto the last blank line and paste in the next line.
- 0 0 * * * /bin/sh /etc/cron.daily/fusionpbx-backup.sh
- press enter then save and exit.
- - run the file: /etc/cron.daily/fusionpbx-backup.sh
- --------------------------------------------------------------------------------------------------
- *********************
- --------------------------------------------------------------------------------------------------
- FusionPBX Restore: (https://docs.fusionpbx.com/en/latest/getting_started/restore.html)
- - create a file: fusionpbx-restore.sh
- - make sure to enable ssh on both computers (by typng the following into the terminal:
- sudo apt update
- sudo apt install openssh-server)
- - make sure that the Linux with the origin db has ssh as root enabled (
- in superuser mode open /etc/ssh/sshd_config, then find the line /maybe commented/ PermitRootLogin without-password and change it to PermitRootLogin yes
- then in the terminal run
- sudo service ssh restart
- )
- - 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
- sudo passwd root
- - 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 = ...
- - get your db passrowrd from /etc/fusionpbx/config.php under "$db_password" (and use in in place of the zzz in the code bellow)
- - 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):
- #!/bin/sh
- now=$(date +%Y-%m-%d)
- ssh_server=x.x.x.x
- database_host=127.0.0.1
- database_port=5432
- export PGPASSWORD="zzz"
- #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
- #systemctl stop freeswitch
- #systemctl start freeswitch
- service freeswitch restart
- echo "Restore Complete";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement