Automate PostgreSQL Database Snapshots with Periodic Jobs

This use case will show you how to create a snapshot of PostgreSQL database using periodic jobs. For this example we will use DSLR tool to create snapshot but there are other options you can use. Check installation guide in their readme. Let create a new block and create periodic task called snapshot and add the following script.

# DATABASE_URL should be saved as credential or environment variable in RapidForge
# I am placing it here to make example shorter
export DATABASE_URL="postgresql://myuser:mypassword@localhost:5432/mydatabase"
snapshot_name="snapshot-$(date +%Y%m%d%H%M%S)"
dslr snapshot $snapshot_name

We can connect to any remote database, depending on the database you might need to create user and grant access. You can upload the snapshot to S3 or any other storage service by extending the script. By going to event tabs you can see the logs of the task. That should provide you enough information for auditing and troubleshooting.