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!
Accepted Answer
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:
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:
Create a Space and generate access keys.
Use a lightweight Droplet that has access to your database.
Install pg_dump
and s3cmd
(or rclone
).
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
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
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.