Skip to content
Tutorials Center
My learning

Topics

Lesson 31 of 35 ยท Operations and Cost

Backups, Snapshots and Recovery on DigitalOcean

Plan recovery on DigitalOcean: automatic Droplet backups, manual snapshots, volume snapshots, managed database backups, off-site copies, RPO, RTO and restore drills.

Disks fail, people run rm -rf in the wrong directory, and a bad deploy corrupts data. A backup you have never restored is only a hope. This lesson covers what DigitalOcean offers, how the options differ, and how to decide how much protection you need using two numbers: RPO (how much data you can afford to lose) and RTO (how long you can afford to be down).

DigitalOcean is not available on this site, so procedures are text only and the Python blocks are stand-ins that simulate retention and recovery math with sample numbers. Prices mentioned are examples: read the current pricing page.

The tools

  • Droplet backups are automatic. Enable them per Droplet; the system takes a full image weekly and keeps the last four. A daily option exists as well. Backups cost a percentage of the Droplet's price. They are for "go back a few days or weeks", not for "undo what happened ten minutes ago".
  • Snapshots are manual, on-demand images of a Droplet or a volume. You decide when to take them and how long to keep them, and they are billed per GiB per month. Good before risky changes (an upgrade, a migration) and for building a reusable image.
  • Volume snapshots capture a Block Storage volume, which is useful for data disks.
  • Managed database backups are automatic, daily, and include point-in-time recovery for a window of several days on supported engines (check the docs for your engine), so you can restore a new cluster to a moment just before a mistake.
  • Spaces (object storage) is the natural place for off-site copies such as database dumps and file archives, and supports lifecycle rules for expiry and versioning.
  • Kubernetes: volumes are snapshotted through the CSI driver (VolumeSnapshots), and your manifests should live in Git.
Terminal
doctl compute droplet-action snapshot DROPLET_ID --snapshot-name web-1-before-upgrade --wait
doctl compute snapshot list
doctl compute droplet create web-restore --image SNAPSHOT_ID --region nyc1 --size s-1vcpu-1gb
doctl compute droplet-action enable-backups DROPLET_ID
doctl compute volume snapshot list
doctl compute snapshot delete SNAPSHOT_ID --force

For consistent snapshots of a busy database, stop writes or flush first: a snapshot of a running disk is "crash consistent" (like pulling the plug), which databases usually survive but cannot guarantee. Safer still is a logical dump (pg_dump, mysqldump) taken at the application level.

flowchart LR
  A["Droplet disk"] -->|"weekly, keep 4"| B["Automatic backups"]
  A -->|"manual, before changes"| C["Snapshots"]
  D["Managed database"] -->|"daily + PITR"| E["Built-in backups"]
  A -->|"cron: dump + upload"| F["Spaces bucket<br/>(off-site copy)"]

Layer the tools: automatic backups for convenience, snapshots for control, an off-site copy for disaster.

The 3-2-1 idea

Keep 3 copies of important data, on 2 different kinds of storage, with 1 off-site. Backups stored on the same account and region protect you from mistakes but not from an account lockout or a regional outage, so copy the critical dumps elsewhere (another region's Space, or another provider) and encrypt them. Also protect backups from deletion by a leaked token: use separate credentials with write-only access for the upload job.

Retention in practice

Automatic backups keep four weekly copies. This stand-in shows which dates remain on a given day, and how far back you can go.

Python Stand-in: weekly backups, keep 4

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.

Note the last line: with weekly backups, up to six days of changes may be lost. That is the RPO the setup really provides.

RPO and RTO

Decide the numbers first, then pick the tools:

  • RPO (recovery point objective): the maximum acceptable data loss, measured in time. An RPO of 1 hour needs hourly backups or point-in-time recovery.
  • RTO (recovery time objective): the maximum acceptable downtime. Restoring a 200 GiB snapshot, rebuilding DNS and checking the app takes time; measure it in a drill.
Python Stand-in: does my plan meet the targets?

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.

The numbers in the plans are invented for the exercise; the habit that counts is writing your own targets and your own measured restore times.

A restore drill

  1. Create a new Droplet from the latest snapshot or backup (never overwrite the original while you are testing).
  2. Start the application and run a smoke test (login, a read, a write).
  3. Check data freshness: what is the newest record?
  4. Time everything and write down the steps, including DNS changes and secrets.
  5. Delete the test Droplet so it does not keep costing money.

Repeat after significant changes, and at least every few months. Also keep infrastructure in code (Terraform and cloud-init) so rebuilding the server is a command, and only the data needs restoring.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. How often do automatic Droplet backups run, and how many are kept?

    The default is a weekly full image with four retained; check the docs for the daily option.
  2. 2. When is a manual snapshot most useful?

    You choose the moment, so a snapshot gives a precise rollback point.
  3. 3. What does RPO measure?

    Recovery point objective is the tolerated data loss; recovery time objective is the tolerated downtime.
  4. 4. What does the 1 in 3-2-1 stand for?

    At least one copy should be stored away from the primary location.

Summary

  • DigitalOcean offers automatic weekly backups, manual snapshots, volume snapshots, managed database backups with point-in-time recovery and Spaces for off-site copies.
  • Choose protection from your RPO and RTO, not from habit; weekly backups mean days of possible loss.
  • Follow 3-2-1, encrypt, and protect backup credentials.
  • Practise restores on a fresh Droplet and keep infrastructure as code.

Next: Pricing and Cost Control