Before I start digging into some scripting, I'm curious if anyone has designed anything to automatically switch which server BART is backing up if the master goes down and the standby becomes the master?
Using VIP In this case will be wise decision.
The VIP remains active on Master and moves on to the Slave in case of failover.
Hope this helps.
Maybe you can include a check on 'Database cluster state' of pg_controldata command in your backup script.
bash-4.4$ pg_controldata -D /var/lib/postgresql/data/ | grep 'Database cluster state'
Database cluster state: in production
If it is under recovery then do nothing, otherwise performs the BART backup.
Then setup the backup script to all DB servers, primary and standby(s) with cronjob.
Currently we setup BART on both primary/standby DBs, decide which database is the master and perform backup job with cronjob. And we mount a NFS directory on both of them for WAL archiving/restoring.