Great script, thank you! It worked so there must be a problem in my backup script.
Sorted.
This was the script as copied from documentation:
https://docs.fusionpbx.com/en/latest/getting_started/backup.html
#!/bin/sh
now=$(date +%Y-%m-%d)
echo "Server Backup"
export PGPASSWORD="zzzzzzzz"
mkdir -p /var/backups/fusionpbx/postgresql
#delete postgres logs older than 7 days
find /var/log/postgresql/postgresql-9.4-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=$database_host --port=$database_port -U fusionpbx fusionpbx --schema=public -f /var/backups/fusionpbx/postgresql/fusionpbx_pgsql_$now.sql
echo "Backup Complete";
This is my new script with edits in bold.
#!/bin/sh
now=$(date +%Y-%m-%d)
echo "Server Backup"
export PGPASSWORD='XXXXXXXXXXXXXXXXXX'
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-9.4-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";
For some reason because they weren't declared, I thought $database_host and $database_port must be environment variables that were already set. Thats not the case, and using the db test script pointed me in the right direction.