Skip to content
Tutorials Center
My learning

Topics

Lesson 13 of 35 ยท Storage and Databases

Snapshots and Backups on DigitalOcean: Restore Points That Work

Compare Droplet backups, snapshots, Volume snapshots and database backups, plan retention and the 3-2-1 rule, restore safely, and test recovery before you need it.

Everything fails eventually: disks, deployments, and people (the most common cause is a command typed on the wrong server). A backup strategy means you can get your data and service back within a time you can accept. DigitalOcean offers several mechanisms that sound similar but serve different goals. This lesson sorts them out and shows how to build a plan that you have actually tested.

Two numbers define a plan

  • RPO (recovery point objective): how much data you can afford to lose, measured in time. "We can lose at most 24 hours of orders" means you need a backup at least daily.
  • RTO (recovery time objective): how long you can be down. "Back within 2 hours" decides whether a manual rebuild is acceptable or whether you need standby servers.

Write both numbers down before choosing tools. A personal blog and a payment system have very different answers.

The tools

Mechanism What it copies Taken Good for Not good for
Droplet backups Whole Droplet disk image Automatically, on a schedule (weekly, with a daily option available), a limited number kept Cheap routine protection Frequent restore points, databases needing consistency
Droplet snapshots Whole Droplet disk image Manually or through automation Before upgrades, golden images for cloning Hourly protection
Volume snapshots One Volume Manually or through automation Restore points for attached data Cross-region needs, unless you copy them
Managed database backups Database contents Automatic daily with point-in-time recovery for supported engines Database recovery Protecting against someone deleting the whole cluster
Spaces versioning and copies Objects Per upload Undoing overwrites and deletes Cluster-level disasters, unless replicated
Your own file-level backups Files and dumps you choose Any schedule Offsite copies, fine-grained restore Needing no effort

Prices change; backups are typically charged as a percentage of the Droplet's price, snapshots by gigabytes stored per month.

Droplet backups

Turn backups on in the panel (Backups tab) or at creation with --enable-backups. DigitalOcean takes images automatically and keeps a handful of recent ones. To restore, you pick a backup and either restore the Droplet in place (which overwrites its disk) or create a new Droplet from it. The second option is safer for investigations.

Backups happen at the disk level while the Droplet runs, so they are crash-consistent: like pulling the plug and later restarting. Journaling filesystems cope, but a busy database may need recovery on boot. For databases, add proper dumps.

Snapshots

A snapshot is a point-in-time image you create on demand:

Terminal
doctl compute droplet-action snapshot 314159 --snapshot-name web-1-before-upgrade --wait
doctl compute snapshot list --format ID,Name,Regions,MinDiskSize,Size
doctl compute droplet create web-1b --image <snapshot-id> --region fra1 --size s-1vcpu-1gb --wait

Use them before risky changes (kernel upgrade, database migration, major app update) and to create golden images: set up a server once, snapshot it, and launch copies. Snapshots can be transferred to other regions, which makes them a simple disaster recovery tool.

For the cleanest snapshot of a Droplet, shut it down first (doctl compute droplet-action power-off) or at least stop the database; a snapshot of a running machine is crash-consistent only. Snapshots are billed while they exist, so delete old ones; automated scripts should keep a fixed number (for example the last 7 daily and 4 weekly).

Database dumps and the 3-2-1 rule

The 3-2-1 rule is a classic: keep 3 copies of important data, on 2 different kinds of storage, with 1 off-site. On DigitalOcean that might be: the live data, the provider's automatic backups (copy 2), and a nightly dump uploaded to a Spaces bucket in another region or even another provider (copy 3, off-site).

Terminal
# nightly logical dump of a managed PostgreSQL database
pg_dump "$DATABASE_URL" --format=custom --file=shop-$(date +%F).dump
rclone copy shop-$(date +%F).dump do-spaces-ams3:shop-backups/postgres/

Run that from a cron job or a scheduled job in App Platform, and monitor it. Backups fail silently more often than you would think.

flowchart LR
  APP["App + database<br/>(copy 1)"] --> AUTO["Provider backups<br/>(copy 2)"]
  APP --> DUMP["Nightly dump"] --> SP["Spaces bucket<br/>another region<br/>(copy 3, off-site)"]
  APP --> SNAP["Snapshot before<br/>risky changes"]

Several independent copies, at least one in a different place.

Test your restores

A backup you have never restored is a hope, not a backup. Schedule a restore drill (monthly or quarterly): create a new Droplet from the latest backup, or a new database from a dump, and check that the application starts and the data looks right. Time the drill; that is your real RTO. Write the steps in a runbook so anyone can follow them at 3 a.m.

Stand-in: pick a restore point and prune old ones

These programs model retention and recovery with in-memory data. They teach the arithmetic behind RPO and pruning; they do not call the API.

Python Stand-in: retention policy (keep 7 daily, 4 weekly)

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Python Stand-in: how much data would a restore lose?

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Checklist

  • RPO and RTO written down and agreed.
  • Automatic backups on for production Droplets; managed database backups verified.
  • Snapshot before every risky change; prune old ones.
  • At least one off-site copy; secrets and keys backed up separately and securely.
  • A tested, written restore procedure.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What does RPO measure?

    RPO is the maximum acceptable data loss, expressed as time since the last good copy.
  2. 2. A snapshot of a running busy database Droplet is...?

    The disk is copied while in use, so databases might need recovery. Use dumps or a quiet moment for consistency.
  3. 3. Which satisfies the 'off-site' part of the 3-2-1 rule best?

    Off-site means a failure at the original location cannot take the copy with it.
  4. 4. How do you know your backups actually work?

    Only a restore test proves that the data is complete and usable and tells you your real RTO.

Summary

  • Define RPO and RTO first; pick mechanisms to meet them.
  • Droplet backups are automatic and cheap, snapshots are on-demand golden images and safety nets, databases have their own backups.
  • Follow 3-2-1, keep a nightly dump in another region, prune old snapshots, and monitor your jobs.
  • Test restores on a schedule and write a runbook.

Next: Managed Databases