This restic backup tutorial sets up an encrypted, deduplicated backup on Linux and then does the part most guides skip: restoring the data and proving that it is identical. restic is a modern backup program written in Go, shipped as a single binary. I tested everything with restic 0.20.0 (released 19 November 2026) on Debian Linux, with a local test repository and 20 MB of sample data. All results are from 2 December 2026. The tests are small on purpose, so they show how the commands behave, not how fast restic is on your terabytes.
Why restic instead of rsync or scp?
rsync and scp copy files. After a run, the target holds a copy of the current state, readable by anyone with access to it. If a file was damaged or deleted yesterday and you synchronized today, the good version is gone, unless you built your own versioning with extra rsync options. restic works differently: every run creates a snapshot, a complete view of the directory at that time. The data is stored encrypted in a repository, identical content is stored only once, and you can restore any snapshot. That also answers what happens to your files when the backup storage belongs to someone else: they only see encrypted blobs.
The usual advice for what to back up is the 3-2-1 rule: three copies of your data, on two different kinds of media, one of them off site. Everything in this tutorial sits in /tmp/demo on one disk, which is fine for learning and is not a backup. For real use, point the repository at another disk, another machine or a storage service that restic supports.
Install restic on Linux: the binary setup
The installation is a single binary, and there is nothing to configure afterwards. Most distributions package restic, but the version can be old. I downloaded the binary from the restic release page on GitHub, checked the SHA-256 sum against the published list and installed it. This is the setup I used; the release file is a bzip2 archive, which I unpacked with Python because the box had no bunzip2 (on most systems bunzip2 does the same):
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
sha256sum --ignore-missing -c SHA256SUMS
python3 -c "import bz2,shutil; shutil.copyfileobj(bz2.open('restic_0.20.0_linux_amd64.bz2'), open('restic','wb'))"
chmod +x restic && sudo mv restic /usr/local/bin/restic
restic version
restic_0.20.0_linux_amd64.bz2: OK
restic 0.20.0 compiled with go1.27.4 on linux/amd64
I only checked the checksum list that comes from the same release page. The release also contains a signed checksum file, which you can verify with GPG if you want a stronger guarantee. A matching checksum protects against a damaged download, not against a compromised release page. If you care about that, the same reasoning applies as in the tutorial Secure Python Dependencies with uv, where hashes pin exactly the files you reviewed.
Create a repository and protect the password
To use restic, you first need a repository: a directory (or a remote location) with the encrypted data. The encryption happens on your machine before anything is written. You create it once with restic init. Instead of typing the password every time, restic can read it from a file or an environment variable. To keep the commands short I set two variables in my shell; you can pass -r /path/to/repo and --password-file to every command instead, which I also tried and which behaves the same:
export RESTIC_REPOSITORY=/tmp/demo/repo
export RESTIC_PASSWORD_FILE=/tmp/demo/pw.txt
echo "correct-horse-battery-example" > /tmp/demo/pw.txt && chmod 600 /tmp/demo/pw.txt
restic init
created restic repository e5df49f9a3 at /tmp/demo/repo
Please note that knowledge of your password is required to access
the repository. Losing your password means that your data is
irrecoverably lost.
The warning is meant literally. restic encrypts everything with a key that is unlocked by this password, and there is no reset. A wrong password ends with a short error, and no data is shown:
Fatal: wrong password or no key found
Store the password in a password manager, not only on the machine you are backing up. If the machine dies, the password file dies with it.
Run your first backup
The test directory /tmp/demo/project has six files that I want, plus a node_modules folder and a cache folder that are not worth saving. An exclude file lists them:
node_modules
cache
*.tmp
restic backup --host demo --exclude-file excludes.txt project
Files: 6 new, 0 changed, 0 unmodified
Dirs: 3 new, 0 changed, 0 unmodified
Added to the repository: 19.140 MiB (19.104 MiB stored)
processed 6 files, 19.136 MiB in 0:00
snapshot fcf839d1 saved
The summary shows that restic read 6 files and added 19.140 MiB to the repository. The host name demo comes from the --host option; by default restic uses the machine’s host name. Now I added a small file and ran the same command again:
using parent snapshot fcf839d1
Files: 1 new, 0 changed, 6 unmodified
Dirs: 0 new, 2 changed, 1 unmodified
Added to the repository: 3.267 KiB (1.329 KiB stored)
processed 7 files, 19.136 MiB in 0:00
snapshot 6f4e7675 saved
This is the deduplication at work: restic saw that 6 of 7 files were unchanged and stored only 3.267 KiB new data, although the snapshot again covers 19.136 MiB. Each snapshot is still a full view of the directory. The command restic snapshots lists them:
ID Time Host Tags Paths Size
------------------------------------------------------------------------------------
fcf839d1 2026-12-02 15:43:11 demo /tmp/demo/project 19.136 MiB
6f4e7675 2026-12-02 15:43:12 demo /tmp/demo/project 19.136 MiB
------------------------------------------------------------------------------------
2 snapshots
If you want to know what a backup would do without writing anything, add --dry-run. In my test it reported the new files and the size it would add (about 4 KiB) without creating a snapshot. With --verbose in addition, it also printed the scan result (9 files, 19.136 MiB) and the number of new data and tree blobs. With restic ls latest you see the files in the newest snapshot, and restic diff compares two snapshots:
restic diff fcf839d1 6f4e7675
+ /project/docs/new.md
Files: 1 new, 0 removed, 0 changed
Restore the data and prove that it is identical
A backup you have never restored is a hope, not a backup. Restoring writes the files of a snapshot into a target directory. Then diff -r compares the restored tree with the original (without the excluded folders), and a list of SHA-256 hashes confirms it:
restic restore latest --target /tmp/demo/restore
diff -r -x node_modules -x cache project restore/project && echo IDENTICAL
Summary: Restored 10 files/dirs (19.136 MiB) in 0:00
IDENTICAL
I also compared the hashes of all 7 files with sha256sum in both trees, and the two lists were equal. To restore just one file, add --include with the path as it appears in the snapshot, which you can see with restic ls:
restic restore latest --target /tmp/demo/restore2 --include /project/docs/new.md
Summary: Restored 3 / 1 files/dirs (9 B / 9 B) in 0:00
Check the repository: why a plain restic check is not enough
The command restic check verifies the structure of the repository. It does not read the stored data by default. To test that, I flipped a single byte inside one pack file of the repository (the files are read-only, so I had to change the permission first) and ran the check:
check all packs
check snapshots, trees and blobs
[0:00] 100.00% 2 / 2 snapshots
no errors were found
restic reported no errors, and the exit code was 0. Only restic check --read-data, which reads and decrypts all packs, found the damage:
read all data
[0:00] 100.00% 5 / 5 packs
pack 4b907742e6c0... contains 2 errors: [blob 1950b912...: decrypting blob <data/1950b912> ... failed: ciphertext verification failed ...]
...
Fatal: repository contains errors
A restore showed the practical effect. The file in the damaged pack was not restored correctly, the other files were fine, and the exit code was 1:
ignoring error for /project/media/video.bin: decrypting blob <data/1950b912> from pack 4b907742e6c0... failed: ciphertext verification failed
Summary: Restored 9 / 10 files/dirs (17.011 MiB / 19.136 MiB) in 0:00
Fatal: There were 1 errors
So schedule restic check --read-data from time to time. On a large repository it reads everything and can take long. The option --read-data-subset=1/5 reads only a fifth of the packs per run (in my small repository, 2 of 5 packs), so you can cover everything over several runs. The error message points to restic repair packs and restic repair snapshots --forget. I did not run those; I restored the repository from a copy I had made before the test.
Delete old snapshots with forget and prune
Without a policy, the repository keeps every snapshot forever. The command restic forget with a keep policy removes the ones you no longer need, and --prune deletes the data that nothing uses anymore. To test a policy realistically, I created 45 snapshots with the option --time, one per day, so that they look like daily backups of the last weeks (this option is meant for importing old data, I used it only for the test). Always try the policy first with --dry-run:
restic forget --keep-daily 7 --keep-weekly 4 --keep-monthly 3 --dry-run
Applying Policy: keep 7 daily, 4 weekly, 3 monthly snapshots
keep 10 snapshots:
ID Time Host Tags Reasons Paths Size
------------------------------------------------------------------------------------------------------
2009a289 2026-10-31 03:00:00 demo monthly snapshot /tmp/demo/project 19.136 MiB
0362da6c 2026-11-15 03:00:00 demo weekly snapshot /tmp/demo/project 19.136 MiB
5e0289e8 2026-11-22 03:00:00 demo weekly snapshot /tmp/demo/project 19.136 MiB
c6192714 2026-11-26 03:00:00 demo daily snapshot /tmp/demo/project 19.136 MiB
...
2a6de834 2026-11-30 03:00:00 demo daily snapshot /tmp/demo/project 19.136 MiB
monthly snapshot
0c8ca8f3 2026-12-01 03:00:00 demo daily snapshot /tmp/demo/project 19.136 MiB
6f4e7675 2026-12-02 15:43:12 demo daily snapshot /tmp/demo/project 19.136 MiB
weekly snapshot
monthly snapshot
The “Reasons” column shows why a snapshot is kept. With --keep-daily 7 --keep-weekly 4 --keep-monthly 3 the 47 snapshots shrank to 10: the last seven days, the newest snapshot of each of the last four weeks and the newest of each of the last three months. A snapshot can have several reasons. Running the same command with --prune instead of --dry-run then removed the unused data. The repository stayed at 21 MB, because the 20 MB file was in every snapshot and is still needed:
to delete: 144 blobs / 44.374 KiB
total prune: 147 blobs / 45.403 KiB
remaining: 57 blobs / 19.114 MiB
unused size after prune: 0 B (0.00% of remaining size)
Two behaviours surprised me. First, forget treats snapshots with the same host name and paths as one group, so a snapshot from a different host name is never compared with the others. In my test, a snapshot made under another host name stayed outside of the policy of the group demo. If the host name of a machine changes, set --host explicitly. Second, I cut one of my own runs short by piping its output to head, which killed the script during a prune. The next command refused to run:
unable to create lock in backend: repository is already locked exclusively by PID 2178154 on ...
the `unlock` command can be used to remove stale locks
The exclusive lock of the killed process was still in the repository. restic unlock removed it, and a following restic check --read-data reported no errors. Only run unlock when you are sure that no other restic process is still working on the repository.
Schedule the backup with a script and a systemd timer
To run the backup every night, put the two commands into a small script. This is the script I used (with paths adapted to the test); I ran it by hand and it did a backup followed by forget --prune:
#!/bin/sh
set -eu
restic backup --exclude-file /etc/restic/excludes.txt /home/anna/project
restic forget --keep-daily 7 --keep-weekly 4 --keep-monthly 3 --prune
With systemd you can run it as a service that a timer starts. The following unit files are the usual way to schedule a restic backup on Linux. I could not test them through systemd, because the machine I tested on does not run it. I only checked the time expression with systemd-analyze calendar, which accepted *-*-* 03:00:00. So treat these files as a starting point and check the result with systemctl list-timers. The file /etc/restic/env holds the two variables from above, RESTIC_REPOSITORY and RESTIC_PASSWORD_FILE, in the simple NAME=value format:
[Unit]
Description=restic backup
[Service]
Type=oneshot
EnvironmentFile=/etc/restic/env
ExecStart=/usr/local/bin/restic-backup.sh
[Unit]
Description=Run the restic backup every night
[Timer]
OnCalendar=*-*-* 03:00:00
Persistent=true
RandomizedDelaySec=15min
[Install]
WantedBy=timers.target
sudo systemctl enable --now restic-backup.timer
Persistent=true runs a missed backup after the machine was off at 3 o’clock, and the random delay spreads the load if many machines share a target. If you prefer cron, the same script works there too; I did not test a crontab entry.
What I did not test
I tested only a local repository on one disk. restic can also store repositories on SFTP servers, S3-compatible storage and, through rclone, many cloud services. For SFTP, keep your SSH server patched, as the report on OpenSSH 10.6p2 shows. If you want a European encrypted cloud as a target, read about Internxt first; I did not test whether it works with restic. I also did not test mounting snapshots, large amounts of data, Windows or macOS. The restic documentation covers these. The measurements here are from one small test machine, so check the commands with your own data and do a real restore before you rely on any backup.




