[Insights](/insights/) / [Core Engineering Intelligence](/insights/core_engineering_intelligence/)

# 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](https://static.devforth.io/adminusers/avatars/2026/48db9847-d461-40cd-b344-f2bd7b0d98ca-avatar_ivan@devforth.io_f4ce9df9-8363-4314-9345-28753c76a386.jpeg)

Ivan Borshchov

CEO & System Architect @ DevForth

Dec 3, 2026

![How to back up a SQL database so it actually works](https://static.devforth.io/posts/logo-svg/2026/f7a30c3e-5083-4833-9a05-3373d5de76b1-logo-preview-new.svg)

![How to back up a SQL database so it actually works](https://static.devforth.io/posts/logo-svg/2026/f7a30c3e-5083-4833-9a05-3373d5de76b1-logo-preview-new.svg)

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)**

```bash
# 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:

```bash
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:

```bash
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](https://github.com/devforth/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

[

Get a quote

](/estimation-request/)[

Talk to our engineers

](https://talk.devforth.io/book/30-minute-meeting)

[

Back to insights

](/insights/)

[](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fdevforth.io%2Finsights%2Fhow-to-back-up-a-sql-database-so-it-actually-works%2F)[](https://bsky.app/intent/compose?text=How%20to%20back%20up%20a%20SQL%20database%20so%20it%20actually%20works%0A%0Ahttps%3A%2F%2Fdevforth.io%2Finsights%2Fhow-to-back-up-a-sql-database-so-it-actually-works%2F)[](https://x.com/intent/tweet?text=How%20to%20back%20up%20a%20SQL%20database%20so%20it%20actually%20works%20by%20%40ivanborshchov%0A%0Ahttps%3A%2F%2Fdevforth.io%2Finsights%2Fhow-to-back-up-a-sql-database-so-it-actually-works%2F)

## Related insights

[

![Forward a remote port to your computer with SSH](https://static.devforth.io/posts/logo-svg/2026/62b2a6d3-714d-471d-864e-c48d51d84d77-logo-preview-new.svg)

Core Engineering Intelligence Dec 3, 2026

## Forward a remote port to your computer with SSH

Use ssh -L to open a database, admin panel or debug server that runs on a remote server on your own localhost, without opening it to the internet.

](/insights/forward-a-remote-port-to-your-computer-with-ssh/)[

![Blocking vs asynchronous code, explained simply](https://static.devforth.io/posts/logo-svg/2026/1c717208-1a6c-497e-8676-3f879a925104-logo-preview-new.svg)

Core Engineering Intelligence Dec 3, 2026

## Blocking vs asynchronous code, explained simply

Blocking code stands and waits, async code works on something else in the meantime. Why that matters, and why neither one fixes a slow query.

](/insights/blocking-vs-asynchronous-code-explained-simply/)[

![Install PostgreSQL and create a database and user from the command line](https://static.devforth.io/posts/logo-svg/2026/4289b5ee-f719-4e22-8f1d-519f5fa1fa11-logo-preview-new.svg)

Core Engineering Intelligence Dec 3, 2026

## Install PostgreSQL and create a database and user from the command line

Install PostgreSQL on Ubuntu or WSL, then create a database owned by its own user in two SQL commands, and connect with one URL.

](/insights/install-postgresql-and-create-a-database-and-user-from-the-command-line/)
