empty.sh 749 B

123456789101112131415161718192021222324252627282930
  1. #!/bin/sh
  2. #database settings
  3. db_host=127.0.0.1
  4. db_port=5432
  5. #move to script directory so all relative paths work
  6. cd "$(dirname "$0")"
  7. #includes
  8. . ../config.sh
  9. #set the database password
  10. export PGPASSWORD=$database_password
  11. #set the date
  12. now=$(date +%Y-%m-%d)
  13. #make sure the backup directory exists
  14. mkdir -p /var/backups/fusionpbx/postgresql
  15. #backup the database
  16. pg_dump --verbose -Fc --host=$db_host --port=$db_port -U fusionpbx fusionpbx --schema=public -f /var/backups/fusionpbx/postgresql/fusionpbx_auto_$now.sql
  17. #empty the fusionpbx database
  18. sudo -u postgres psql -d fusionpbx -c "drop schema public cascade;";
  19. sudo -u postgres psql -d fusionpbx -c "create schema public;";
  20. # pgpassword security and conflict avoidance
  21. unset PGPASSWORD