Report this

What is the reason for this report?

How do I automatically back up a DigitalOcean Managed PostgreSQL database to Spaces?

Posted on June 26, 2025

I’m using a DigitalOcean Managed PostgreSQL database for my production app and I’d like to set up automatic backups to a DigitalOcean Space (similar to how you’d use S3).

Is there a way to schedule regular dumps of the database (e.g., daily pg_dump) and upload them to a Space automatically? Ideally, I’d like to run this as a lightweight job, maybe using a Droplet or some App Platform automation.

Has anyone implemented something like this? Looking for best practices or sample scripts!



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
0

Hi there,

DigitalOcean Managed Databases come with daily automated backups by default, which you can use to restore your database to any point within the backup window:

https://docs.digitalocean.com/products/databases/

If you still want to maintain your own backup copies (for extra redundancy, long-term archiving, or exporting to Spaces), you can set up a simple automation like this:

  1. Create a Space and generate access keys.

  2. Use a lightweight Droplet that has access to your database.

  3. Install pg_dump and s3cmd (or rclone).

  4. Here is a very simple script that you could use:

#!/bin/bash
TIMESTAMP=$(date +%F-%H-%M)
pg_dump "$DATABASE_URL" > backup-$TIMESTAMP.sql
s3cmd put backup-$TIMESTAMP.sql s3://your-space-name/backups/
rm backup-$TIMESTAMP.sql
  1. Add a cron job to schedule it:
0 2 * * * /home/youruser/backup.sh

If you want a fully managed option without maintaining a script or server, check out SnapShooter for PostgreSQL on DigitalOcean, it’s built specifically for this use case.

- Bobby

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.