I started using a PostgreSQL database with GnuCash instead of a file, and set up a weekly cron job to dump the database to a file. Here’s the script:

#!/usr/bin/env bash

# Requires that ~/.pgpass exists, is chmod 600, and contains a line like:
#
# 127.0.0.1:5432:*:gnucash_user:my-secret-password

pg_dump -h 127.0.0.1 -U gnucash_user -d gnucash_db -Fc > ${HOME}/gnucash_$(date +%F).dump

I’m probably going to modify this script to check that ~/.pgpass exists.

Any other changes you think I need?