DevForth

How to back up a SQL database so it actually works

A simple backup routine for PostgreSQL and MySQL. Dump the data, copy it off the server, run it on a schedule and check that you can restore.

Ivan Borshchov
Ivan Borshchov
CEO & System Architect @ DevForth
How to back up a SQL database so it actually works
How to back up a SQL database so it actually works

A backup is a photo of your data. If the server dies, or someone runs the wrong DELETE, you put the photo back. A good backup comes in four steps.

1. Take the photo (dump)

# PostgreSQL
pg_dump -Fc -d myapp -f myapp-$(date +%F).dump
# MySQL / MariaDB
mysqldump --single-transaction myapp | gzip > myapp-$(date +%F).sql.gz

2. Keep the photo somewhere else

A backup on the same server dies along with the server. Copy it to object storage somewhere else, for example an S3 bucket:

aws s3 cp myapp-2026-12-03.dump s3://my-backups/myapp/ --storage-class GLACIER_IR

Archive storage classes are very cheap for files you rarely read. Older guides use standalone Glacier "vaults", but AWS no longer offers those to new customers, so use S3 storage classes instead. Give the backup job credentials that can upload to this one bucket and nothing else.

3. Run it on a schedule

Put the commands in a script and run it from cron, for example every night at 04:00:

0 4 * * * /opt/backup/backup.sh

Add a lifecycle rule to the bucket that deletes old copies, so the bill doesn't grow forever.

4. Practise the restore

A backup you have never restored is a hope, not a backup. Now and then, load the latest copy into an empty database:

createdb myapp_check
pg_restore -d myapp_check myapp-2026-12-03.dump

Look at a few tables, then ask two questions: how long did the restore take, and how much data would we lose since the last backup?

If you'd rather use a ready-made container than a script, our open-source docker-database-glacierizer dumps the database on a cron schedule and uploads it to an S3 Glacier storage class.

In short: dump, copy it off the server, schedule it, and test the restore.

Get your project quote

Free result within 48-72 hours

Related insights