Backing up your data in 2026: 3-2-1, ransomware, cloud accounts and a tested restic script
What to back up, why a synced folder is not a backup, how to get your data out of Google, Apple, Microsoft and GitHub, and one complete restic setup in a single script: an encrypted repository on an external disk, a copy off-site, pruning, integrity checks and a restore test on every run.
A backup is a copy you can still get back after whatever destroyed the original. That rules out a second folder on the same disk, a sync service, and a USB drive that was plugged in when ransomware ran. Here is what to copy, where to keep it, how to get your data out of the big cloud accounts, and one complete, tested restic setup for a Linux machine at home or on the bench.
3-2-1, and the 1-0 on the end
US-CERT’s 2012 paper Data Backup Options states the rule everyone quotes: keep 3 copies of any important file (one primary, two backups), on 2 different types of media, with 1 copy off-site. The paper credits it to Peter Krogh’s The DAM Book, a book for photographers.
Veeam, a backup vendor, extends it to 3-2-1-1-0: one more copy that is immutable or air-gapped, and zero errors when backups are checked and test-restored. The name is marketing; the advice is the same as CISA’s #StopRansomware Guide: “Maintain offline, encrypted backups of critical data, and regularly test the availability and integrity of backups”.
The setup below, mapped onto it:
| Copy | Where | What it survives |
|---|---|---|
| 1 | your files on the computer | nothing: this is the original |
| 2 | an encrypted restic repository on an external USB disk | a dead drive, a deleted folder, a bad edit (old versions are kept) |
| 3 | a copy of that repository in a cloud bucket, or on a rest-server elsewhere | fire, theft, anything that takes the house |
| the extra 1 | the USB disk, unplugged between runs, or an append-only off-site copy | ransomware, or anyone, running with your login |
| the 0 | restic check and a restore test on every run |
a backup that quietly stopped working |
What ransomware and locked accounts changed
Ransomware goes looking for backups. CISA: “many ransomware variants attempt to find and subsequently delete or encrypt accessible backups”. The UK’s NCSC has seen it encrypt “the connected USB and network storage drives” along with the originals. Its answer is a copy that is offline most of the time: an unplugged disk, storage that refuses connections except during a backup, or storage where the backup client can add data but not change or delete it.
The other change is how much lives only in accounts. Microsoft’s Services Agreement (in force since 30 September 2026) closes an account that has not signed in for two years, then deletes its content and “won’t be able to retrieve” it; it also recommends that you “regularly backup Your Content and Data”. Google may delete an account unused for two years. A closed, suspended or hijacked account takes its content with it, so your backups must not depend on signing in.
Sync is not backup
Sync services such as Google Drive and OneDrive keep one set of files the same on every device. When something goes wrong that is exactly the wrong behaviour: delete a folder and it goes everywhere; ransomware encrypts your files and the encrypted versions sync as fresh edits. Google’s help: with Drive for desktop, “any files you put in the trash are put in the trash everywhere”, and “Files you move to the Trash are deleted forever after 30 days.”
There is an undo. “Restore your OneDrive” rolls a whole OneDrive back to any point in the last 30 days after files were “deleted, overwritten, corrupted, or affected by malware”, with an active Microsoft 365 subscription. Use it if you have it, but it is still one company, one account and 30 days: your original in two places, not a second copy.
What to back up
Everything you made, and everything you could not download again:
- Photos and videos. Get them off the phone and out of the photo cloud onto a computer the backup covers.
- Documents: scans, tax papers, manuals for things you own.
- Project files: firmware, KiCad and CAD files, 3D models, notes. A repository on GitHub is one more copy, not the backup; mirror it (below).
- Home Assistant. Its backups contain the
configfolder, where the ESPHome Device Builder keeps its device files (inesphome/), so one backup covers both. They are encrypted by default and you “need the encryption key in the emergency kit to restore”: download the kit and keep it outside Home Assistant. Home Assistant recommends a copy “on another system (outside of Home Assistant) and ideally also one off-site”, so add a network share as a backup location and put that folder in the restic list. - Your password manager. If the vault is a file, back up the file. With Bitwarden, choose the password protected encrypted export: an account restricted one can only be imported back into the account that made it, and becomes unreadable if you rotate that account’s encryption key. No export includes the trash or Sends; only the
.zip (with attachments)format includes attachments. - The backup’s own password. restic says it when you create a repository: “Losing your password means that your data is irrecoverably lost.” Keep it in your password manager and on paper, away from the computer.
Leave out what can be rebuilt: caches, node_modules, Python virtual environments, and build output such as PlatformIO’s .pio folder, which holds “compiled objects, static libraries, firmwares, and external library dependencies”.
Getting your data out of cloud accounts
Each export is a snapshot that you then back up like any other file. Checked on 27 November 2026:
| Account | Export | What to know |
|---|---|---|
| Google Takeout | One archive, or one “every 2 months for one year”; .zip or .tgz in parts of up to 50 GB; a link by e-mail, or delivery to Drive, Dropbox, OneDrive or Box. Archives expire after about 7 days and can be downloaded 5 times. Can take days. | |
| Apple (iCloud) | “Request a copy of your data” at privacy.apple.com | Contacts, calendars, notes, bookmarks, reminders, email, photos, videos and documents in iCloud. 14 days to download. Health data is exported from the Health app. |
| Microsoft | Product by product | OneDrive on the web downloads a selection as .zip (10 GB per zip, 20 GB overall); for more, sync it to a PC and back up that folder. Outlook.com mail exports to .pst with Outlook for Windows, or .olm with legacy Outlook for Mac. |
| GitHub | Settings, Account, “Export account data” | A tar.gz of “repository and profile metadata”; the link expires after seven days. Mirror the code with git. |
A Takeout archive delivered to Drive is still inside the account you are guarding against: use the e-mailed link.
To mirror your GitHub repositories, install the GitHub CLI, run gh auth login, then gh auth setup-git so git can use that login for private repositories:
mkdir -p ~/github-mirror && cd ~/github-mirror
gh repo list YOUR_NAME --source --limit 1000 --json name,url --jq '.[] | .name + " " + .url' |
while read -r name url; do
if [ -d "$name.git" ]; then git -C "$name.git" remote update --prune
else git clone --mirror "$url" "$name.git"; fi
done
--mirror copies every branch and tag, and a second run updates them; --source skips forks.
The setup: restic
restic is a free, open-source backup program: one binary for Linux, macOS, Windows and the BSDs. Each run is a snapshot, unchanged data is stored once, the repository is encrypted with AES-256 and authenticated with Poly1305-AES, and the same commands work on a local disk, an S3-compatible bucket or restic’s own rest-server.
Install it
The current release is restic 0.20.0 (19 November 2026); Ubuntu 24.04’s package is 0.16.4. Take the official binary and check it against the key fingerprint in restic’s installation docs:
curl -LO https://github.com/restic/restic/releases/download/v0.20.0/restic_0.20.0_linux_amd64.bz2
curl -LO https://github.com/restic/restic/releases/download/v0.20.0/SHA256SUMS
curl -LO https://github.com/restic/restic/releases/download/v0.20.0/SHA256SUMS.asc
curl -fsSL https://restic.net/gpg-key-alex.asc | gpg --import
gpg --verify SHA256SUMS.asc SHA256SUMS # look for: Good signature, CF8F 18F2 8445 7597 3F79 D4E1 91A6 868B D3F7 A907
sha256sum -c --ignore-missing SHA256SUMS # restic_0.20.0_linux_amd64.bz2: OK
bunzip2 restic_0.20.0_linux_amd64.bz2
sudo install -m 755 restic_0.20.0_linux_amd64 /usr/local/bin/restic
On a 64-bit ARM board, take the linux_arm64 file. Later, sudo restic self-update fetches new releases and checks their signature itself.
The off-site bucket
Backblaze B2 as the example; other S3-compatible storage works the same way.
- Create a private bucket and copy its Endpoint value,
s3.REGION.backblazeb2.com. - Under Application Keys, add a key for that bucket only, Read and Write. The applicationKey is shown once.
- In the bucket’s lifecycle settings, choose “Keep only the last version of the file”. B2 keeps old versions forever by default, and restic’s manual recommends this rule so pruning really frees space. (The alternative, “Keep prior versions for this number of days”, costs more and keeps deleted data downloadable for those days.)
B2 costs $6.95 per TB per month, the first 10 GB free, downloads free up to three times your average monthly storage, then $0.01 per GB (published U.S. West rates, read 27 November 2026). No real bucket was used for this article; the commands are the ones restic documents for S3-compatible storage. A rest-server on a small computer at a friend’s place does the same job, and can be append-only (below).
The config, the list and the exclusions
~/.config/backup/config holds the settings and the bucket key: chmod 600 it.
RESTIC_PASSWORD_FILE=/home/you/.config/backup/restic-password
LOCAL_REPO=/media/you/backup1/restic
SOURCES_FILE=/home/you/.config/backup/sources.txt
EXCLUDES_FILE=/home/you/.config/backup/excludes.txt
CANARY=/home/you/Documents/backup-canary.txt
OFFSITE_REPO=s3:https://s3.REGION.backblazeb2.com/BUCKET
AWS_ACCESS_KEY_ID=the-keyID
AWS_SECRET_ACCESS_KEY=the-applicationKey
sources.txt, one path per line (or just /home/you):
/home/you/Documents
/home/you/Pictures
/home/you/projects
/home/you/github-mirror
/mnt/nas/home-assistant-backups
excludes.txt: a pattern without a slash, like node_modules, matches that name anywhere; $HOME works here, ~ does not.
$HOME/.cache
$HOME/.local/share/Trash
node_modules
.venv
__pycache__
.pio
*.tmp
The canary is a file that never changes; the script restores and compares it on every run: echo "backup canary: do not edit" > ~/Documents/backup-canary.txt.
Then create the password and both repositories, once. The off-site one shares the local one’s chunker parameters, so copied snapshots deduplicate:
cd ~/.config/backup
(umask 077; head -c 32 /dev/urandom | base64 > restic-password)
set -a; . ./config; set +a
restic -r "$LOCAL_REPO" init
restic -r "$OFFSITE_REPO" init --from-repo "$LOCAL_REPO" --from-password-file "$RESTIC_PASSWORD_FILE" --copy-chunker-params
Now copy that password onto paper.
The script
backup.sh
#!/usr/bin/env bash
# backup.sh: restic backup to an external disk, copied off-site; then prune, check and restore-test both copies.
# Settings come from the environment or from $BACKUP_CONFIG (default ~/.config/backup/config, chmod 600).
# No password or key ever goes in this file. geekcowboy.net, 2026. MIT licence.
set -euo pipefail
config=${BACKUP_CONFIG:-$HOME/.config/backup/config}
# shellcheck source=/dev/null
if [[ -f $config ]]; then set -a; source "$config"; set +a; fi # set -a: restic sees the variables
LOG_FILE=${LOG_FILE:-$HOME/.local/state/backup/backup.log}
mkdir -p "$(dirname "$LOG_FILE")"
exec > >(tee -a "$LOG_FILE") 2>&1 # everything below goes to the screen and to the log
: "${RESTIC_PASSWORD_FILE:?set RESTIC_PASSWORD_FILE to the file that holds the repository password}"
: "${LOCAL_REPO:?set LOCAL_REPO to the repository on the external disk}"
: "${SOURCES_FILE:?set SOURCES_FILE to a file listing what to back up, one path per line}"
EXCLUDES_FILE=${EXCLUDES_FILE:-/dev/null}
OFFSITE_REPO=${OFFSITE_REPO:-} # empty: no off-site copy
OFFSITE_PRUNE=${OFFSITE_PRUNE:-yes} # no: the off-site is append-only and is pruned from another machine
CANARY=${CANARY:-} # absolute path of a file that never changes; restored and compared every run
KEEP=(--keep-daily 7 --keep-weekly 5 --keep-monthly 12 --keep-yearly 3)
export RESTIC_PASSWORD_FILE
tmp=$(mktemp -d)
trap 'rm -rf "$tmp"' EXIT
status=0
log() { printf '%s %s\n' "$(date '+%F %T')" "$*"; }
fail() { log "FAILED: $1"; exit "$2"; }
run() { # restic, logged; any failure stops the script, except 3 (some source files could not be read)
local rc=0
log "restic $*"
restic "$@" || rc=$?
case $rc in
0) ;;
3) log "WARNING: restic exit code 3, some files were not read (see above)"; status=3 ;;
10) fail "no repository there; is the disk plugged in? (restic exit code 10)" 10 ;;
12) fail "wrong password (restic exit code 12)" 12 ;;
*) fail "restic exit code $rc" "$rc" ;;
esac
}
restore_test() { # restore the canary from the latest snapshot in repository $1 and compare it with the original
[[ -n $CANARY ]] || return 0
local dir="$tmp/restore-$2"
run -r "$1" restore latest --target "$dir" --include "$CANARY"
cmp -- "$CANARY" "$dir$CANARY" || fail "restore test: $CANARY from $1 is missing or differs" 1
log "restore test passed: $CANARY from $1"
}
run version
run -r "$LOCAL_REPO" backup --files-from "$SOURCES_FILE" --exclude-file "$EXCLUDES_FILE" --exclude-caches
if [[ -n $OFFSITE_REPO ]]; then
run -r "$OFFSITE_REPO" copy --from-repo "$LOCAL_REPO" --from-password-file "$RESTIC_PASSWORD_FILE"
fi
run -r "$LOCAL_REPO" forget --prune "${KEEP[@]}"
run -r "$LOCAL_REPO" check --read-data-subset 5%
restore_test "$LOCAL_REPO" local
if [[ -n $OFFSITE_REPO ]]; then
if [[ $OFFSITE_PRUNE == yes ]]; then run -r "$OFFSITE_REPO" forget --prune "${KEEP[@]}"; fi
run -r "$OFFSITE_REPO" check
restore_test "$OFFSITE_REPO" offsite
fi
log "finished with exit code $status"
exit "$status"
Save it as ~/bin/backup.sh, chmod +x it, and run it once by hand.
What it does
In order: a backup to the disk; restic copy sends new snapshots off-site; forget --prune applies the retention policy to the disk; check verifies the repository and reads a random 5% of its data; the canary is restored from the newest snapshot and compared byte for byte; then the same for the off-site copy.
The policy keeps the newest snapshot of each of the last 7 days, 5 weeks, 12 months and 3 years that have one; prune deletes data that no remaining snapshot uses. Until there are enough snapshots, restic also keeps the oldest one, marked oldest.
The off-site check reads only the structure, to save downloads. Once a month, read everything with restic -r "$OFFSITE_REPO" check --read-data; on B2 that fits inside the free download allowance.
The script stops at the first failure, and the exit code says why:
| Exit code | Meaning | What to do |
|---|---|---|
| 0 | everything ran, both restore tests passed | nothing |
| 3 | backup made, but some files could not be read; the log lists them | fix their permissions or exclude them |
| 10 | no repository at that path | plug in and mount the disk |
| 12 | wrong password | check the password file |
| 1 or other | a restic command or a restore test failed; nothing after it ran | read the log |
The log is ~/.local/state/backup/backup.log; each run ends with finished with exit code 0 or FAILED: and the reason.
Every night, and a real restore once a month
crontab -e, with PATH set so cron finds restic in /usr/local/bin:
PATH=/usr/local/bin:/usr/bin:/bin
30 2 * * * $HOME/bin/backup.sh >/dev/null 2>&1
Read the log’s last line every week. A backup that has been failing for three months looks just like one that works.
The canary proves the chain works; a bigger restore proves your data is in it. Restore a folder elsewhere and compare (files changed since the last run, and excluded ones like *.tmp, will differ):
restic -r /media/you/backup1/restic restore latest --target /tmp/restore-test --include /home/you/Documents
diff -r /home/you/Documents /tmp/restore-test/home/you/Documents && echo identical
Once a year, restore from the off-site copy on another computer, with only the password from paper and the bucket key. That is the disaster you are preparing for.
The offline or immutable copy
Two ways to get the extra “1” with this script:
- Unplug the disk between runs. It is then offline in the NCSC’s sense. The cost: while it is unplugged the nightly run stops with exit code 10, and nothing goes off-site either, because the off-site copy is made from the disk. Plug it in and run the script by hand a couple of times a week.
- Make the off-site append-only. restic’s rest-server has an
--append-onlymode that “allows creation of new backups but prevents deletion and modification of existing backups”. SetOFFSITE_PRUNE=noand prune that repository now and then from another, well-secured machine, using the--keep-withinoptions: restic’s manual explains that an attacker who can add fake snapshots could otherwise make a--keep-dailystyle policy delete the real ones.
B2 also offers Object Lock, which stops files being changed or deleted until a set date; restic’s manual does not describe using it, so it is not covered here.
On a Mac or a Windows PC
- macOS: Time Machine backs up to an external drive, another Mac, or a NAS that supports Time Machine over SMB. It keeps hourly backups for 24 hours, daily ones for a month and weekly ones before that, deleting the oldest when the disk is full. That is copy 2; add an off-site one.
- Windows 11: File History (Control Panel, System and Security) copies your libraries to an external drive or network location and keeps earlier versions. The newer Windows Backup app stores your folders in OneDrive (5 GB free), which is the sync case above.
- restic has macOS and Windows builds, but
backup.shhas only been run on Linux.
How this was tested
Everything above was copied from this page and run on Linux with restic 0.20.0, against a scratch home folder (documents, photos, projects full of build folders, an ESPHome file, a Home Assistant backup, mirrored repositories, one unreadable file) and two local repositories standing in for the disk and the bucket. No cloud account was used. The first run exited with 3 for the unreadable file, the second with 0, and restores matched the source apart from the excluded files. A missing disk gave 10, a wrong password 12, a missing canary 1. A truncated pack off-site stopped the run; a flipped byte inside a pack passed the plain check and was caught by check --read-data, hence the monthly full read. The cron lines were not tested.
Sources
- restic: release 0.20.0 and its changelog; license (BSD 2-clause); the manual as of v0.20.0: installation (signing key, self-update), preparing a repository (password files, rest-server, S3-compatible storage, Backblaze B2 and its lifecycle advice), backing up (exclude patterns, files-from, exit codes), working with repositories (copy, chunker parameters, check), restoring, removing snapshots (policies, the oldest snapshot, append-only security), scripting (exit codes) and the design document (encryption)
- restic rest-server README (append-only mode), release 0.15.0
- Ubuntu 24.04 archive,
apt-cache policy restic: 0.16.4, read on 27 November 2026 - US-CERT, Data Backup Options (Paul Ruggiero and Matthew A. Heckathorn, 2012): the 3-2-1 rule and its credit to Peter Krogh
- Veeam, What is the 3-2-1 Backup Rule? (3-2-1-1-0)
- CISA, #StopRansomware Guide
- NCSC, Offline backups in an online world (2019)
- Microsoft: Services Agreement (effective 30 September 2026), Restore your OneDrive, Download files and folders from OneDrive or SharePoint, Export your Outlook.com mailbox, Back up and restore with Windows Backup, Backup and restore with File History
- Google: How to download your Google data (Takeout), Inactive Google Account Policy, Delete files in Google Drive
- Apple: Get a copy of the data associated with your Apple Account, Back up your Mac with Time Machine, Backup disks you can use with Time Machine
- GitHub: Requesting an archive of your personal account’s data;
gh repo list --help(GitHub CLI) andgit clone --mirrorin the git manual - Home Assistant, Backups; ESPHome, Getting started with the ESPHome Device Builder in Home Assistant (where device files live)
- Bitwarden, Export vault data and Encrypted exports
- PlatformIO, workspace_dir (the
.piofolder) - Backblaze: B2 pricing, read on 27 November 2026; create and manage buckets, application keys, the S3-compatible API (endpoint format), lifecycle rules, Object Lock and restic with B2