What this is about
Everyone knows they should keep a backup. Fewer people have tried to use one. A backup is only a file until you restore it somewhere safe and see that your data comes back. This article shows the test we run: restore into a scratch copy, count, compare. It also tells what went wrong the first time we checked a copy of files, and why the fault was ours.
Why it matters
The worst time to learn that a backup is broken is the day you need it. Files can be empty. A copy can stop halfway. A database dump can leave out a table. A checksum can say the file is fine, and the file can still not restore. A small test, done before you need it, turns hope into knowledge.
How to do it, step by step
This is the order we follow for the database of a shop.
- Take the backup. A script on the server dumps the database and the uploaded files. It prints OK only after its own checksum passes. In our case it also writes a small file with the row count of every table.
- Copy it off the machine. A backup on the same box as the data dies with the box. We copy it to a second machine.
- Check the file is the same file. On the second machine, we run
sha256sum -c. A checksum proves the file is the one that was written. It does not prove the file restores. - Restore into a scratch database. We start a throwaway PostgreSQL container, load the dump, and nothing else touches it.
- Count and compare. For each table, we count the rows and compare the numbers to the rowcounts file from the source.
- Delete the scratch copy. It served its purpose.
What it showed us
For one of our shops, the backup held 20 tables, and the dump had data for all 20. The scratch restore ran on PostgreSQL 18.6. Some of the counts were booking 10 rows, customer 11, email_log 122, setting 29 and page_block 45. All 20 tables together came to 323 rows. The counts were equal to the source, so the backup earned the name.
We also wrote down what that test did not prove. The 10 bookings in the dump were all in the past, the newest from 2026-11-11. A restore proves that the data comes back. It does not prove that a new booking, made today with the code, will work against the restored data.
The mistake the check was about
Another site keeps its files on an FTPS server. We copied them: 2,882 files and 4,479,488 bytes, which matched the server listing in both count and total size. Then we ran the checksum, and it said all 2,882 had failed.
That looked terrible for about a minute. Then we saw the cause. The checksum file lists paths relative to the folder it was written in. We had run the command one folder up, so every path pointed at nothing. We ran it again from the right folder, and it came out clean. The copy was fine. The command was wrong.
We keep this story because it is the honest shape of backup work. A failed check can mean a bad backup, and it can also mean a bad check. Read the first error, not just the count of errors.
Three copies, three jobs
Our notes keep three copies apart, because each answers a different question.
- The nightly copy, made by a timer on the server at 03:30 UTC, is what we would restore after a bad night.
- The pull to the lab, a copy kept on our own machine, is where we test restores without touching the server. It was 17 hours old at the moment we decided to go ahead with a change, and we said so in the record.
- The change backup is taken as the first step of any switch. It is the closest to the change, and the switch depends on it.
What this does not prove
A matching row count does not mean every value is right. It means the same number of rows came back. A deeper check compares sums, such as the sum of all prices, and some of our switches do that. It also does not cover a disaster where the backup machine is gone too. For that you need a copy in a third place.
Words you may not know
- Backup: a copy of data kept so you can recover from loss.
- Restore: loading a backup back into a working system.
- Checksum: a short fingerprint of a file. Same file gives the same fingerprint.
- Dump: a file that holds a database's contents as commands.
- Scratch: a throwaway copy that you delete afterwards.
- Row count: the number of rows in a table.
- FTPS: a way to copy files over a network with a private line.
Try it
- Pick a folder of files that matter to you. Run
sha256sumon a few and save the result to a text file. - Copy the folder to another disk and run
sha256sum -cfrom inside the copied folder. - If you have a database, restore its dump into a throwaway container and count the rows of one table.
- See the sites we back up this way at amarbaro.com/web.
Read next
- A backup is a file until a scratch restore counts the same rows: the full account, with every number.

Commenti
Ancora nessun commento.
Accedi per commentare.