How to implement regular Postgres backups on PythonAnywhere

Your Postgres data on PythonAnywhere is fully protected against hardware failure. However, we do not automatically support rolling back to a point in time. If you want protection from accidental changes, you can set up a scheduled task to regularly back your data up to a file, which you can re-load into Postgres at a later date.

Here's an example of a command that can dump a particular database called "mydb":

pg_dump --host=HOSTNAME --port=PORT --username=super --format=c --file=pgbackup`date +%F-%H%M`.dump mydb

This command will perform so called "logical backup", not a "physical backup" or a "file-system-level backup" as PostgreSQL documentation calls it, which is not supported on PythonAnywhere.

You can find your HOSTNAME and PORT values on the Databases tab. The HOSTNAME will look something like myusername-667.postgres.pythonanywhere-services.com.
See this page if you need more information on Postgres setup and configuration.

You'll want to experiment with pg_dump and pg_restore until you have a backup command which you have confidence in -- remember, an untested backup procedure isn't a backup procedure at all!