Backups and Recovery: Archives, Checksums, Restore Tests, RPO and RTO
Make backups that actually work: archive a site with tar, record checksums, restore to another place and compare, detect a corrupted backup, and work out how much data a backup schedule can lose and how long a restore takes.
In this lesson you will
- Create and restore an archive
- Verify a backup with checksums
- Detect a corrupted backup
- Calculate RPO and RTO
About 28 minutes
The backup that was never tested
Femi’s client lost a database to a mistaken command and went to the backup, which turned out to be an empty file: the backup job had been failing silently for four months. A backup you have not restored is a hope and not a backup. A sound routine has four parts. Make the archive, for a site usually a tar file compressed with gzip, plus a dump of the database. Record a checksum of every file, so that damage and changes can be detected. Copy the archive to another place, since a backup on the same disk or the same machine dies with it. And restore it, regularly, into a scratch location, and compare, which is the only real proof.
Two numbers describe what a backup plan gives you. The recovery point objective, RPO, is how much recent data you can afford to lose, and a daily backup means that in the worst case you lose almost 24 hours. The recovery time objective, RTO, is how long you can be down while restoring: it is the time to find the backup, copy it back and start the services, and it grows with the size of the data and the speed of the link. A common rule of thumb, 3-2-1, says: keep three copies, on two different kinds of storage, with one copy off site. Retention matters too: if you keep only last night’s backup, a problem that began last week is already in it. Keep daily copies for a week, weekly copies for a month and monthly copies for a year, as a start, and balance it with the cost of storage and with privacy rules about how long personal data may be kept.
| Term | Meaning | Example |
|---|---|---|
| RPO | Data you can afford to lose | Daily backup: up to 24 hours |
| RTO | Time you can be down | 4 hours to restore |
| 3-2-1 | Copies, media, off-site copies | 3 copies, 2 media, 1 off site |
| Checksum | Fingerprint of a file | sha256 of each file |
| Restore test | Restore into a scratch place and compare | Monthly at least |
set -e
d=$(mktemp -d); cd "$d"; mkdir -p site/images site/data
printf '<h1>Pine and Honey</h1>\n' > site/index.html
head -c 40000 /dev/zero | tr '\0' 'x' > site/images/photo.raw
for i in 1 2 3 4 5; do echo "order $i,paid" >> site/data/orders.csv; done
( cd site && find . -type f | sort | xargs sha256sum ) > manifest.txt
tar -czf backup.tar.gz site
echo "files in the archive: $(tar -tzf backup.tar.gz | grep -vc '/$') | archive size: $(stat -c %s backup.tar.gz) bytes"
mkdir restore && tar -xzf backup.tar.gz -C restore
( cd restore/site && sha256sum -c ../../manifest.txt --quiet ) && echo "restore test: every checksum matches"
cp backup.tar.gz damaged.tar.gz
printf 'X' | dd of=damaged.tar.gz bs=1 seek=100 conv=notrunc 2>/dev/null
tar -tzf damaged.tar.gz > /dev/null 2> err.txt && echo "damaged archive listed without error" || echo "damaged archive: tar reports an error ($(head -c 40 err.txt | tr '\n' ' ')...)"
echo "sha256 of the good backup: $(sha256sum backup.tar.gz | cut -c1-16)"
echo "sha256 of the damaged backup: $(sha256sum damaged.tar.gz | cut -c1-16)"
echo "the manifest has $(wc -l < manifest.txt) lines"
files in the archive: 3 | archive size: 399 bytes
restore test: every checksum matches
damaged archive: tar reports an error (tar: This does not look like a tar archi...)
sha256 of the good backup: 10ac74199f39b295
sha256 of the damaged backup: aab2921479e9fa61
the manifest has 3 lines
daily worst-case data loss 24 hours | copies kept 23 | storage for 80 GB each: 1840 GB
every 6 hours worst-case data loss 6 hours | copies kept 44 | storage for 80 GB each: 3520 GB
hourly worst-case data loss 1 hours | copies kept 184 | storage for 80 GB each: 14720 GB
restore time for 80 GB over 200 Mbit/s: 53 minutes of copying + 25 minutes of fixed work = 78 minutes
The shell session built a tiny site, recorded a sha256 checksum of each of its three files in a manifest, packed the folder into a compressed tar archive, and then did what makes the difference: it restored the archive into a different folder and checked every checksum against the manifest, which succeeded (“restore test: every checksum matches”). Then it damaged one byte of a copy of the archive and tried to read it, and tar reported an error, while the checksum of the whole file differs from the good one, in the first characters. Both a failed read and a different checksum are signs of damage, and a nightly job should check one or the other and alert, instead of reporting success because it ran.
The arithmetic of a plan uses invented numbers: 80 gigabytes of data and a link of 200 megabit per second. Copying the data back takes about 53 minutes, and with 25 minutes of fixed work for finding the backup, restoring the database and starting services, the RTO is about 78 minutes, nearly 1.3 hours, before any surprises. A daily backup schedule loses up to 24 hours of data, an hourly one up to 1 hour, at the price of a much larger number of copies: keeping hourly backups for a week alone is 168 copies, 13,440 gigabytes at 80 gigabytes each, unless the backup tool stores only the differences. The right balance depends on what an hour of lost orders costs, and the business, not the technician, must say what the RPO and RTO are.
Independent check: the same procedure was repeated in Python with its own tar and hashing libraries: the three files were archived, their checksums recorded, the archive extracted elsewhere and every checksum compared, with a match for all three, and a single flipped byte at the same position made the archive unreadable. The restore time is arithmetic on the sizes: 80 gigabytes is 640,000 megabits, divided by 200 megabit per second is 3,200 seconds, 53 minutes, and the lesson’s program computes the same.
Check by hand: 80 gigabytes x 8 bits x 1,000 = 640,000 megabits, over 200 megabits per second is 3,200 seconds, which is 53.3 minutes, and plus 25 minutes is 78.3 minutes. Daily backups kept for seven days, four weeks and twelve months are 7 + 4 + 12 = 23 copies.
A failed disk, a mistaken command, a break-in with ransomware or a deleted account can destroy both. Keep a copy elsewhere, with credentials that the server cannot use to delete it.
Put a monthly restore test in the calendar, and automate the checksum comparison. The first real restore should never be an emergency.
Providers, plans and prices change often, so the lessons use invented prices and generic names, and you must check each provider’s current website. The server behaviour in this lesson was run for real on a Linux machine with Python 3.13, Node.js 22, OpenSSL and standard Unix tools, and every result was checked a second way. Backup tools, database dumps and cloud snapshots differ. The principles of copies, checksums, restore tests, RPO and RTO apply to all of them.
Practice
Add a database dump to the archive and check its size. Write the commands that keep the last seven daily archives and delete older ones. Compute the restore time for 500 GB over a 1 Gbit/s link.
Check what you learned
Five quick questions. Pick an answer and you will see straight away whether it is right and why.
What is a backup that has never been restored?
- A good backup
- A checksum
- An unproven hope
- A log
Test restores.
What is RPO?
- How long you can be down
- How much recent data you can afford to lose
- The size of the backup
- The price
A daily backup gives up to 24 hours.
What is RTO?
- The number of copies
- How long you can be down while restoring
- The age of a backup
- The size of a disk
Time to restore.
What does the 3-2-1 rule say?
- 3 copies, 2 kinds of storage, 1 off site
- 1 copy, 2 disks, 3 sites
- 3 backups a day
- 2 passwords
A classic rule of thumb.
How can you detect a damaged archive?
- Read it with tar and compare checksums
- Rename it
- Look at its date
- Copy it twice
Check on a schedule.
Summary
- Archive, checksum, copy elsewhere, and restore into a scratch place to prove it.
- RPO is the data you can lose; RTO is the time you can be down.
- Use the 3-2-1 rule and sensible retention.
- Detect damage with checksums and test restores on a schedule.
Questions
Should I back up the whole server or just the data?
The data and the configuration are essential, and the operating system can usually be rebuilt. Keep a written procedure and the configuration files so that a rebuild is quick.
How do I back up a running database?
With the database's own dump or snapshot tool, which gives a consistent copy. Copying the live files can produce a broken backup.
Should backups be encrypted?
If they contain personal or secret data, yes, and keep the key separately and safely. A lost key makes the backup useless, so test that too.
