DEV Community

Cover image for Copying your files isn't a backup: what a real one actually needs
Jasna Mishevska for CodeChem

Posted on Originally published at blog.codechem.com

Copying your files isn't a backup: what a real one actually needs

Written by: Aleksandar Filipovski. Originally published on the CodeChem blog.

There's a saying every sysadmin repeats in some form: there are two kinds of people, those who've lost data and those who will. I learned it early, when my dad reformatted the external drive holding all our family photos because a set-top box asked him to. We got them back, but the lesson stuck: never keep important things in one place.

A copy somewhere else is the start. Here's how fast "just back it up" turns into something much bigger.

A mirror isn't a backup

Ransomware, a wrong rm, a script that writes zeroes over everything. A mirrored drive (RAID 1) copies all of that instantly. You need to go back in time, which means snapshots.

How often, and for how long?

How much data can you afford to lose? That's your Recovery Point Objective (RPO). Banks aim for seconds; a small business might accept a day. For family photos, a weekly snapshot is probably fine.

But daily snapshots pile up: 365 a year. So you rotate them. Keeping only the last 14 days means corruption you don't notice for two weeks is gone for good. A better pattern is GFS (grandfather-father-son): dailies for 14 days, weeklies for 7 weeks, monthlies for a year. Frequent near today, sparse further back.

Don't store the same file twice

Most files never change between snapshots, and a small minority change all the time. So instead of copying everything, you deduplicate: store each file once and hard-link it into every snapshot that needs it. Deleting an old snapshot only removes directory entries. That's how rsnapshot works, and it saves bandwidth too, which matters a lot once a cloud bill is involved.

At this point you have an incremental, deduplicated, GFS-rotated, snapshot-based backup, built from rsync and cron. Not bad for an afternoon.

Then real systems get involved

Point it at a homelab with 10 Docker containers and backups start failing. Containers create root-owned files your cron user can't read. Databases keep data in memory and flush in batches, so a raw file copy can restore as corrupted data. Now you're dumping databases and handing your backup job full permissions on Docker volumes.

3-2-1 and the offsite copy

Some drive models fail in batches, and a fire or flood takes everything in the room. Hence the 3-2-1 rule: 3 copies, on 2 types of media, 1 offsite.

Offsite usually means object storage like S3, and that breaks your setup again. Uploads lose file metadata, and millions of small files get expensive. So you pack files into archives, which kills your hard-link deduplication, so you split archives into chunks, and now you need to prove the chunking is safe.

Where I'd stop and use a real tool

This is where rolling your own stops being worth it. Borg and Restic already handle encryption, chunk-level deduplication and checksums, and they've been tested by far more people and failures than your script ever will be.

And none of it counts until you test a restore. Put one in your calendar every six months.

One more: don't schedule backups between 2 and 3 AM. Daylight saving time will either skip that hour or run it twice.


The full version on our blog goes deeper on each step and adds what readers raised after it was published: ZFS snapshots, consistency across apps and databases, ACLs and sparse files.

What's the worst backup surprise you've hit? Tell us in the comments.

Top comments (1)

Collapse
 
mariosfong profile image
Mario Fang •

Good piece — the 2–3 AM line is the one I'd underline twice. I ran a nightly job at 2:30 for months before a restore test came up one snapshot short, and that's when the skipped hour finally clicked. Moved everything to 1:30 AM. The Docker part hit me the same way: root-owned files in volumes broke my first cron-based attempt, and that's what pushed me to restic. GFS rotation is exactly what I run now — dailies for two weeks, then it thins out.