al3x/sovereign — pull request #257 by T3hUb3rK1tten (2014-07-10 06:09:06+00:00)
Title: Backup postgres to .sql without needing restart of service

Changed tarsnap.sh to not shut down postgresql, instead use the pg_dumpall command to create a .sql backup file in /decrypted/. Much better than shutting down the entire db server, sometimes I had weird problems where it wouldn't come back after stopping, and monit had no clue what to do.

Before adding in the "cd /home/" I was getting errors (and hence emails) from pg_dumpall saying "could not change directory to "/root"". This was because the sudo -u postgres would stay in /root/ and pg_dumpall checked permission on the current directory even if it didn't need them. I couldn't find a way to suppress the error without suppressing other errors, so I added the cd in.
Postgres doesn't need write access to /decrypted/, since by the time bash gets to "> /decrypted/postgresql-backup.sql" it's back at root privileges.