Constructing a Backup
Why RAID and the cloud are not a backup, what the 3-2-1 rule really means, and how I back up my own data – with restic on a NAS, a test restore and a few stories of people who were lucky (and some who were not).
Open in the interactive Digital Garden
| What You Need |
|---|
| The data you would cry about if it was gone – start by making a list |
| A second place to put it: an external disk, a NAS or an old PC – see Constructing a Cloud |
| restic for Example 1 (Windows, Linux or macOS) |
| All the tools in one place: my Backup & Recovery resources |
Jump to Examples
I have mentioned the 3-2-1 rule in almost every note so far, so it was about time to write the note itself. Backup is one of those things everybody agrees with and almost nobody does properly – me included, for many years. I had copies, sure. Copies on the same disk, copies on a USB stick in the same drawer as the laptop, and one very old copy on a DVD that I am not sure any of my computers can still read.
The honest test of a backup is simple: if this disk dies right now, or the laptop gets stolen, or a ransomware encrypts everything – what exactly do I lose, and how long does it take to get it back? If the answer is "I don't know", there is no backup yet.
From Tapes to Snapshots
Backup is as old as storing data. The first computers kept their data on punched cards and magnetic tape, and copying a tape to another tape was the backup. IBM's first tape drive for computers, the IBM 726, came out in 1952 – and tape is still here today. Big data centres keep huge libraries of LTO cartridges, because a tape on a shelf is cheap, lasts for decades and cannot be hacked while it is not in a drive.
At home it went from floppy disks to CDs and DVDs, then to external hard disks, and now to NAS boxes and the cloud. What really changed is not the media but the way of copying. Old backups copied everything, every time. Modern tools split files into small pieces, store every piece only once (deduplication) and keep many snapshots – the state of your files on a certain day – for almost no extra space. That is why I can keep a year of daily backups of my documents on a disk that would hold only two or three full copies.
My favourite backup story is from Pixar. In 1998, during the work on Toy Story 2, somebody ran a delete command on the server with the film's files, and most of the film disappeared. Then they found out that the backups had not been working for a while. The film was saved because technical director Galyn Susman had a copy on her computer at home, where she worked after her baby was born. A whole film saved by luck. Don't build your plan on luck.
What Is Not a Backup
- RAID. Two mirrored disks protect you from one dead disk. If you delete a file, or a virus encrypts it, the mirror deletes or encrypts it too – instantly and very reliably.
- Sync (OneDrive, Dropbox, Google Drive, Syncthing). Same as RAID, only over the network. A deleted file is deleted everywhere. Some services have a recycle bin or file versions for a few weeks – useful, but that is their rule, not yours.
- A copy on the same disk. Protects only against your own mistakes, never against the disk.
- A backup you never tried to restore. This is the Pixar case. Until you have restored a file from it, it is only a hope.
The 3-2-1 Rule
The rule is usually credited to photographer Peter Krogh, who wrote about managing digital photos in the 2000s, and it is still the best short answer:
- 3 copies of your data – the original and two backups,
- 2 different kinds of storage – for example the laptop's SSD and a NAS,
- 1 copy in another place – at a friend's, at work, or in the cloud (encrypted!).
Today people often add a 0 and another 1: one copy offline or immutable (ransomware can't touch a disk that is not connected) and 0 errors after a test restore. For me at home that means:
- Laptop and PC – the originals.
- Synology NAS at home – automatic backup every night (Example 1).
- An external USB disk that I connect once a month and then put away.
- An encrypted copy of the most important folders somewhere outside the house.
Examples
Example 1: Backup to a NAS with restic
restic is one program file with no installation. It encrypts everything, makes snapshots and deduplicates. The backup place is called a repository; it can be a folder on a disk, a NAS share over SFTP or a cloud service. On Linux the NAS share is mounted at /mnt/nas/backup in this example; on Windows the same works with a drive letter, for example Z:\restic.
# once: create the repository (restic asks for a password - write it down somewhere safe!)
restic init --repo /mnt/nas/backup/restic
# every day: back up the folders that matter
restic -r /mnt/nas/backup/restic backup ~/Documents ~/Pictures ~/Projects
# what do I have?
restic -r /mnt/nas/backup/restic snapshots
# keep 7 daily, 4 weekly and 12 monthly snapshots, delete the rest
restic -r /mnt/nas/backup/restic forget --keep-daily 7 --keep-weekly 4 --keep-monthly 12 --prune
# check that the repository is not damaged
restic -r /mnt/nas/backup/restic check
The password is the backup. Without it, the encrypted repository is just random bytes, also for you. Mine is in KeePassXC, and the KeePassXC file itself is part of the backup – and there is a printed copy of the master password in a place my family knows about.
To run it every night on Linux, the same systemd timer as in Constructing a Program works fine. The password can be given in a file with --password-file that only root can read.
Example 2: The Test Restore
This is the part everybody skips. Restore into a different folder, never over the originals:
# restore the last snapshot into a test folder
restic -r /mnt/nas/backup/restic restore latest --target /tmp/restore-test
# or only one folder from it
restic -r /mnt/nas/backup/restic restore latest --target /tmp/restore-test --include /home/jernej/Documents/Invoices
Then actually open a few files – a photo, a spreadsheet, something old. A file that is there but damaged is not restored. I put a reminder in the calendar to do this every three months.
Example 3: An Image of the Whole Disk
Coming soon. File backup is great for documents, but when a system disk dies, I don't want to reinstall Windows and fifty programs. I'll describe how I make an image of the whole disk with Clonezilla (or Rescuezilla if you prefer clicking) before I change anything big on a computer.
Example 4: A Copy Outside the House
Coming soon. Fire, flood or burglary take the computer and the NAS at the same time. Options I am testing: a second NAS at a family member's place, an encrypted restic repository in the cloud via Rclone, and the simplest one – a USB disk in a drawer at work.
A Few More Thoughts
The good thing about backup is that it is boring once it works. The tools are free and very good; the hard part is deciding what matters and then checking now and then that the copies are really there. Start small: one folder, one external disk, one test restore this week. That is already more than most people have.