A restic backup is quick to set up: create a repository, pick a password, run restic backup, done. restic encrypts everything, stores every data block only once and creates a complete snapshot on every run, from which you can restore any single file. That makes it one of the best tools for Linux server backups. The real work, though, isn’t in the first command. It’s in the cases where restic reports success even though something is missing.
Those are exactly what we measured on 3 December 2026 on our development server (Ubuntu 24.04.5, restic 0.16.4 from the Ubuntu package repository). We backed up a throwaway copy of this blog’s source code and images: 1,269 files, 57.7 MiB, all in /tmp. On top of that, a test repository ran on a Hetzner Storage Box via SFTP, which we deleted afterwards. Three results up front:
1. A typo in the backup path doesn’t abort anything. restic prints
/gibtsnicht does not exist, skipping, saves the snapshot without that directory and exits with exit code 0. If you only check the exit code, you won’t notice for months that a directory is missing.2. A half-finished database dump from a pipe ends up in the backup without complaint. Our simulated
pg_dump, which aborts with error 2 after the first line, produced a saved snapshot and exit code 0 from restic. Onlyset -o pipefailmakes the failure visible.3. A killed backup run (
kill -9) afterwards blocksrestic checkandrestic prunewith a stale lock. New backups still ran fine, but maintenance didn’t, until we ranrestic unlock.
If you’re still deciding what to back up and where, start with our 3-2-1 backup strategy. This article is the tool guide to go with it: restic from installation to a verified restore.
“Backups Done Right! A Beginner’s Guide To Restic” by DeAndre Wilson (January 2024). Walks through the basic commands calmly on screen, good for following along.
restic Backup in 60 Seconds
If you just need the commands:
# Install (Debian/Ubuntu)
sudo apt install restic
# Password in a file only root can read
sudo install -m 600 /dev/null /root/.restic-pass
openssl rand -base64 32 | sudo tee /root/.restic-pass > /dev/null
export RESTIC_PASSWORD_FILE=/root/.restic-pass
# Create a repository and back up
restic init -r /srv/backup/restic
restic -r /srv/backup/restic backup /etc /srv /home
# List snapshots and restore
restic -r /srv/backup/restic snapshots
restic -r /srv/backup/restic restore latest --target /tmp/restore-test
# Clean up old snapshots
restic -r /srv/backup/restic forget --keep-daily 7 --keep-weekly 4 --keep-monthly 6 --prune
The rest of this article explains why these lines look the way they do and what else you need so the restic backup is actually there when you need it.
What Is restic?
restic is an open-source backup program written in Go that runs as a single binary with no dependencies. It’s available for Linux, macOS, Windows and the BSDs. Data goes into a repository, which can live locally, on another server via SFTP, in S3-compatible object storage, on Backblaze B2, Azure, Google Cloud or on your own rest-server. Via rclone, dozens more targets are available.
Three properties set it apart from simply copying with cp or rsync:
- Snapshots instead of a mirror. Every run creates its own complete state. Older states stay until you deliberately delete them. If a file gets overwritten by accident or encrypted by ransomware, you just restore yesterday’s state.
- Deduplication. restic splits files into variable-length chunks and stores each chunk only once, across all snapshots and even across different paths. That’s why a daily backup costs almost no extra space.
- Encryption is always on. There is no unencrypted mode. The repository is encrypted with AES-256 and protected against tampering with Poly1305. Anyone who gets hold of the backup target sees only noise.
Since version 0.14, restic also compresses by default, as long as the repository uses format v2 (which restic init has created automatically ever since).
Installation: Package or Official Binary?
On Debian and Ubuntu, sudo apt install restic is enough. For us that installed restic 0.16.4. It works, but it isn’t the latest version. Two things stood out:
- The
restic self-updatecommand doesn’t exist in the Ubuntu package:unknown command "self-update" for "restic". The package maintainers removed it; updates come throughapt. - Newer features are missing.
--stdin-from-command, where restic starts a database dump itself and checks its exit code, only exists from 0.17. In 0.16.4 restic replies withunknown flag: --stdin-from-command. Why that feature matters is shown in the database section below.
If you want the current version, download the official binary from the GitHub releases page and put it in /usr/local/bin/. Then restic self-update works too. On a server where you manage updates centrally through the package manager, the packaged version is still a reasonable choice, as long as you know what’s missing.
restic version
# restic 0.16.4 compiled with go1.22.2 on linux/amd64
Step 1: Set the Password Before Anything Else
The password is the most important part of a restic backup. Without the password, the repository is lost. There is no recovery, no support, no back door. restic says so explicitly when you create a repository:
Please note that knowledge of your password is required to access
the repository. Losing your password means that your data is
irrecoverably lost.
With a wrong password we got exactly one line and exit code 1:
Fatal: wrong password or no key found
So put the password in a file with mode 600 and keep a copy off the server, for example in a password manager like Vaultwarden. The classic backup disaster is an offsite backup whose password only lived on the server that just died.
restic reads the password from three sources, in this order of preference:
| Variable | Purpose |
|---|---|
RESTIC_PASSWORD_FILE | path to a file containing the password, ideal for scripts |
RESTIC_PASSWORD_COMMAND | a command that prints the password, e.g. from a password manager |
RESTIC_PASSWORD | the password itself, but it easily ends up in shell history and process lists |
A repository can have several keys. restic key add creates a second password, for example one for the emergency envelope in the safe. restic key list shows all active keys; right after creation, ours had exactly one.
Step 2: Create the Repository
export RESTIC_PASSWORD_FILE=/root/.restic-pass
restic init -r /srv/backup/restic
Locally this took 2.8 seconds for us. Most of that is the deliberately slow key derivation (scrypt), which protects the password against brute force. The repository itself is a directory with a fixed structure:
config data index keys locks snapshots
Never touch these files by hand. Everything you need goes through restic commands. To avoid typing -r every time, you can set the repository as a variable:
export RESTIC_REPOSITORY=/srv/backup/restic
restic snapshots
A local repository on the same disk as the original data only protects against accidental deletion and application-level mistakes, not against disk failure. A separate volume is better, and a second copy offsite is a must (step 7).
Step 3: The First restic Backup
restic -r /srv/backup/restic backup /etc /srv /home
restic prints a summary at the end. Our measurements with the throwaway copy of the blog:
| Operation | Duration | Result |
|---|---|---|
| First backup, local | 0.82 s | 1,269 new files, 57.8 MiB, 52.2 MiB stored |
| Second backup, nothing changed | 0.72 s | 0 bytes added |
| One line appended to one file | under 1 s | 1 file changed, 85.8 KiB added, 23.5 KiB stored |
| Whole directory copied under a new name and backed up | under 1 s | 1,269 “new” files, but only 460.9 KiB added |
| 1,000 MiB of random data | 2.6 s | 1,000 MiB stored, no compression possible |
The fourth row is the heart of restic: to restic these were 1,269 new files in a path it had never seen. Yet it stored barely half a megabyte, because the data chunks were already in the repository. That’s why you can back up daily without the repository exploding.
Compression only saved 10.5 % on our data (ratio 1.12), because more than half of it was already-compressed WebP and JPG images. With text files, logs and database dumps the gain is much larger: in our earlier test for the 3-2-1 strategy, mostly source code, it was 29 %. Random data and encrypted files don’t compress at all, as the last row shows.

Excludes: What Doesn’t Belong in the Backup
Caches, temporary files and node_modules bloat every backup and are useless in an emergency. restic offers several ways to exclude them:
restic -r REPO backup /srv \
--exclude '/srv/*/node_modules' \
--exclude '*.tmp' \
--exclude-caches \
--exclude-file /etc/restic/excludes.txt \
--one-file-system
--exclude-caches skips every directory containing a CACHEDIR.TAG file (many programs put one in their cache directories). --one-file-system stops restic from wandering into mounted network shares or /proc when you back up /. Test new excludes with --dry-run -vv, which lists what would be backed up without writing anything.
Tags and Hostnames
With --tag daily or --tag before-update you label snapshots, and forget can later filter by tag. restic also records the hostname. If several servers back up into the same repository, they get separate retention groups, while deduplication still works across all of them.
Trap 1: A Wrong Path Isn’t an Error for restic
This surprised us most in testing. We deliberately passed a path that doesn’t exist:
restic -r REPO backup data /gibtsnicht
echo $?
/gibtsnicht does not exist, skipping
...
snapshot 56be5286 saved
0
restic saves the snapshot without the missing path and returns exit code 0. That’s intentional (a laptop doesn’t always have every third-party drive attached), but dangerous on servers: a typo in the backup script, a renamed directory or an unmounted volume, and the backup runs “green” for years without your most important data.
The fix: check the paths in the script yourself before restic starts, and regularly verify what’s actually in the snapshot:
for P in /etc /srv /home; do
[ -d "$P" ] || { echo "MISSING: $P" >&2; exit 1; }
done
restic -r REPO ls latest /srv | head
Trap 2: Unreadable Files Give Exit Code 3
As root, restic can read practically every file. So we ran a second test as an unprivileged user and placed a file owned by someone else with mode 600 into the backup directory:
error: open /tmp/rtest/nb/src/geheim: permission denied
Warning: at least one source file could not be read
snapshot c51f8966 saved
Exit code: 3. restic still saved the snapshot, just without that file. So code 3 doesn’t mean “backup failed”, it means “backup incomplete”. For a monitoring script, those are two different alerts. The exit codes of restic backup at a glance:
| Exit code | Meaning | What we measured |
|---|---|---|
| 0 | snapshot saved | even with a missing source path |
| 1 | fatal error, no snapshot | wrong password |
| 3 | snapshot saved, but at least one file unreadable | foreign file with 600, empty stdin pipe |
Newer restic versions add more codes, such as 10 for “repository does not exist” and 11 for “failed to lock repository”. If you rely on exit codes, check the documentation for your exact version.
Step 4: Backing Up Databases Properly
Never back up a running database as plain files, or you’ll capture a half-written state. First create a consistent dump, then put the dump in the repository. How to do that cleanly for MySQL and MariaDB is covered in detail in our MySQL backup guide, and for PostgreSQL in the PostgreSQL backup guide.
restic can read the dump straight from a pipe, so it never sits unencrypted on disk:
mysqldump --all-databases --single-transaction \
| restic -r REPO backup --stdin --stdin-filename mysql.sql
Trap 3: The Half Dump With Exit Code 0
This is the most dangerous trap in the whole article. We simulated a dump that writes one line and then aborts with error 2, like a mysqldump whose connection drops mid-run:
(echo "-- half dump"; exit 2) | restic -r REPO backup --stdin --stdin-filename half.sql
echo "${PIPESTATUS[@]}"
# 2 0
restic saved the snapshot and exited with 0. The backup contains the half dump:
restic -r REPO dump latest /half.sql
# -- half dump
Without extra settings, the shell returns the exit code of the last command in a pipe, which is restic’s. The dump’s failure disappears. Two remedies:
# 1. At the top of every backup script
set -euo pipefail
With pipefail, the whole pipe fails as soon as any part fails. Your script aborts and monitoring fires. The half snapshot is still in the repository, but you know about it and can remove it with restic forget <ID>.
# 2. From restic 0.17: restic starts the dump itself and checks its exit code
restic -r REPO backup --stdin-from-command --stdin-filename mysql.sql -- \
mysqldump --all-databases --single-transaction
With --stdin-from-command, restic discards the snapshot if the command fails. The 0.16.4 from Ubuntu’s packages doesn’t support it yet, so pipefail remains your safeguard there.
Interesting detail: when nothing at all came through the pipe, i.e. a dump that fails immediately, restic reported no data read and exit code 3. So the dangerous case is precisely the one where part of the dump had already been written.
Step 5: Restoring
A restic backup is only worth something once you know the restore works. The key commands:
# All snapshots
restic -r REPO snapshots
# What's in a snapshot?
restic -r REPO ls latest
# Everything back into a test directory
restic -r REPO restore latest --target /tmp/restore-test
# Just one file or directory
restic -r REPO restore latest --target /tmp/r --include /srv/app/config.yml
# A single file straight to stdout
restic -r REPO dump latest /etc/nginx/nginx.conf > nginx.conf
Our measurement: the full local restore of the 1,269 files took 0.9 seconds, and diff -r between original and restore found no differences. A single file was back in 0.7 seconds.

Trap 4: Paths in the Snapshot Aren’t Always What You Expect
During restore we tripped over two details worth knowing:
- restic stores the path exactly as you passed it at backup time. Back up with a relative path (
restic backup data) and the snapshot contains/data. Back up with an absolute path (restic backup /tmp/rtest/data) and it contains/tmp/rtest/data, sorestore --target /tmp/rproduces/tmp/r/tmp/rtest/data. In scripts, always use absolute paths so your snapshots are consistent. - An
--includethat matches nothing isn’t an error. With a misspelled path, restic restored0 files/dirsand exited with code 0. Look up the exact path first withrestic ls latest | grep name.
Restoring via FUSE: Browse Your Snapshots
If you’re looking for a file but don’t know in which snapshot it was still intact, restic mount is more convenient:
mkdir /mnt/restic
restic -r REPO mount /mnt/restic
# in a second terminal:
ls /mnt/restic/snapshots/
For us, the directories hosts, ids, snapshots and tags appeared, with every snapshot as a regular directory named by its timestamp. You can use cp, diff or a file manager inside. It requires FUSE (fusermount), which is installed on most servers. Stop with Ctrl+C or fusermount -u /mnt/restic.
Which Snapshot Changed What?
restic -r REPO diff 42372d32 aad5925b
After our appended line, diff showed exactly one changed data blob: Added: 85.800 KiB, Removed: 85.788 KiB. Handy when you want to find out when a config broke.
Step 6: Checking the Repository
restic has its own two-stage check command:
# Check structure and index (fast)
restic -r REPO check
# Additionally read all data and verify checksums (thorough)
restic -r REPO check --read-data
# For large repositories, read only a part per run
restic -r REPO check --read-data-subset=1/10
Locally, check took 0.74 seconds and check --read-data 0.82 seconds, both with no errors were found. With hundreds of gigabytes, reading all data takes hours, which is where --read-data-subset helps: one tenth every night, and after ten nights everything has been read once.
But check is not a real restore test. It proves the data in the repository is intact. It doesn’t prove the right data is in there, that your password exists off the server, or that your application starts with the restored files. More on that below.
Step 7: Offsite restic Backup (SFTP, Storage Box, S3)
A backup on the same server isn’t an offsite copy. restic can back up directly via SFTP to another machine, such as a Hetzner Storage Box or a second VPS:
restic init -r sftp:backup@backup.example.com:/restic/myserver
restic -r sftp:backup@backup.example.com:/restic/myserver backup /etc /srv /home
restic uses your regular SSH for this. The cleanest setup is a dedicated SSH key just for backups and an entry in ~/.ssh/config. Hetzner Storage Boxes listen for SSH on port 23:
# ~/.ssh/config
Host storagebox
HostName uXXXXXX.your-storagebox.de
User uXXXXXX
Port 23
IdentityFile /root/.ssh/backup_ed25519
restic -r sftp:storagebox:restic/myserver init
Our measurements from our server to a Storage Box, with the same 57.7 MiB:
| Operation | Duration |
|---|---|
| Create repository | 3.4 s |
| First backup | 2.9 s |
| Second backup, nothing changed | 1.2 s |
| Full restore | 1.4 s, diff -r with no differences |
check --read-data | 4.2 s, no errors |
We deleted the test repository afterwards.

Other targets look similar:
# S3-compatible storage
export AWS_ACCESS_KEY_ID=...
export AWS_SECRET_ACCESS_KEY=...
restic -r s3:https://s3.example.com/my-bucket/restic init
# Backblaze B2
restic -r b2:my-bucket:restic init
# your own rest-server
restic -r rest:https://backup.example.com:8000/myserver init
Keeping Two Repositories in Sync with restic copy
Instead of backing up twice, you can copy a local repository to a second one. The second repository can have its own password:
restic -r /srv/backup/second init
restic -r /srv/backup/second copy --from-repo /srv/backup/restic --from-password-file /root/.restic-pass
For us, the first run copied all five existing snapshots in under a second. A second run right after took 1.4 seconds and copied nothing twice; the target size stayed the same. Important: copy transfers snapshots but not deletions. You have to run forget in each repository separately. That’s more feature than bug: an accidental forget in the first repository doesn’t wipe the second.
Can Your Server Delete Its Own Backup?
This is the most important question for offsite backups, and with SFTP the answer is almost always yes. Anyone with root on your server can see the target in the backup script, has the SSH key and the restic password, and can delete everything with restic forget or plain rm. We found exactly this gap on our own server and described it in the 3-2-1 guide, including the countermeasures: rest-server with --append-only, object storage with Object Lock, or a backup server that pulls the data itself. With a Hetzner Storage Box, the Storage Box’s own snapshots also help, since the server can’t delete them over SFTP.
Step 8: Cleaning Up Old Snapshots with forget and prune
Without cleanup, the repository grows a little every day. restic splits this into two steps:
forgetdecides, based on your rules, which snapshots to remove. That’s fast and doesn’t delete any data yet.prunethen deletes all data chunks no snapshot needs anymore. That’s the expensive part.
Usually you combine both:
restic -r REPO forget --keep-daily 7 --keep-weekly 4 --keep-monthly 6 --prune
Always try new rules with --dry-run first. For us, the dry run with --keep-last 3 showed it would remove four of seven snapshots, grouped by path and host. The real run with --prune took 0.8 seconds.
| Option | Meaning |
|---|---|
--keep-last N | keep the last N snapshots |
--keep-daily N | one per day for the last N days |
--keep-weekly N | one per week for the last N weeks |
--keep-monthly N | one per month for the last N months |
--keep-within 30d | everything from the last 30 days |
--keep-tag permanent | never delete snapshots with this tag |
Retention is a security decision. If an attack or data error is only noticed after two weeks, a seven-day retention doesn’t help you anymore. Our rule of thumb: keep snapshots at least twice as long as it realistically takes you to notice a problem.
Trap 5: Stale Locks After an Abort
restic places a lock in the repository on every access. Normally it removes it again on its own. We tested what happens when a backup is killed hard mid-run, as with a power cut or an OOM kill:
restic -r REPO backup big & sleep 1.5; kill -9 $!
The next restic backup ran through normally with exit code 0. restic check and restic prune, however, refused with exit code 1:
lock was created at 2026-12-03 08:06:50 (10.834343764s ago)
storage ID dda5ff52
the `unlock` command can be used to remove stale locks
Only restic unlock (successfully removed 1 locks) freed the repository again. The nasty part: your daily backup keeps reporting success, while nightly maintenance with forget --prune fails silently and the repository keeps growing. So check every restic command in your script, not just backup. And only run unlock when you’re sure no other restic process is running. Without extra options, unlock only removes locks restic recognises as stale.
Step 9: Automating with a systemd Timer or Cron
restic has no built-in scheduler. You run it from a cron job or a systemd timer. We recommend the timer, because output lands in the journal and a failure shows up as a failed unit.
The script, with all lessons from the traps above:
#!/bin/bash
# /usr/local/bin/restic-backup.sh
set -euo pipefail
export RESTIC_PASSWORD_FILE=/root/.restic-pass
export RESTIC_REPOSITORY=sftp:storagebox:restic/myserver
PATHS=(/etc /srv /home)
# Trap 1: check for missing paths yourself
for P in "${PATHS[@]}"; do
[ -d "$P" ] || { echo "Backup path missing: $P" >&2; exit 1; }
done
# Trap 3: pipefail makes a half dump abort the script
mysqldump --all-databases --single-transaction \
| restic backup --stdin --stdin-filename mysql.sql --tag db
# Trap 2: treat exit code 3 as a warning, not success
set +e
restic backup "${PATHS[@]}" --exclude-caches --one-file-system --tag files
RC=$?
set -e
if [ $RC -eq 3 ]; then echo "WARNING: some files could not be read" >&2; exit 3; fi
[ $RC -eq 0 ] || exit $RC
# Trap 5: check maintenance too
restic forget --keep-daily 7 --keep-weekly 4 --keep-monthly 6 --prune
restic check --read-data-subset=1/10
The matching systemd units:
# /etc/systemd/system/restic-backup.service
[Unit]
Description=restic backup
Wants=network-online.target
After=network-online.target
[Service]
Type=oneshot
ExecStart=/usr/local/bin/restic-backup.sh
Nice=10
IOSchedulingClass=idle
# /etc/systemd/system/restic-backup.timer
[Unit]
Description=Daily restic backup
[Timer]
OnCalendar=*-*-* 03:30
RandomizedDelaySec=15m
Persistent=true
[Install]
WantedBy=timers.target
sudo systemctl daemon-reload
sudo systemctl enable --now restic-backup.timer
systemctl list-timers restic-backup.timer
journalctl -u restic-backup.service -n 50
Persistent=true catches up on a missed run if the server was off at the scheduled time. If you prefer cron, guard against overlapping runs with flock so a slow run isn’t overtaken by the next one:
30 3 * * * flock -n /run/restic.lock /usr/local/bin/restic-backup.sh >> /var/log/restic.log 2>&1

Who Notices When the Backup Doesn’t Run?
A timer that fails silently is worse than none, because it fakes safety. At least one of these belongs in your setup:
- A heartbeat service like Healthchecks.io or Uptime Kuma: the script calls a URL at the end. If the call doesn’t arrive, you get a message. This also catches the case where the timer never starts.
OnFailure=in the service unit, which starts a second unit for notifications on failure.- Age check of the latest snapshot:
restic snapshots --latest 1 --jsonreturns the time of the latest snapshot. If it’s older than 26 hours, something’s wrong. This catches every failure, no matter where it happened.
More on monitoring services is in our article on server monitoring.
“Mighty Backups and Restores with Restic” by That Helpdesk Guy (September 2025). Focuses on the restore side, which is exactly the part most tutorials skip.
The Real Restore Test: Once Without the Old Server
All the measurements above have one thing in common: they ran on the same server that holds the originals. In a real emergency, that server is gone. The only test that reflects this is a restore on an empty machine:
- Spin up a small new VPS or VM.
- Install restic.
- Get the password from your password manager, not from the old server.
- Set up access to the offsite repository (SSH key or S3 credentials, also from the password manager).
restic snapshots, thenrestic restore latest --target /srv/restore.- Start a service from it, for example import the database dump and run a query.
It takes an hour and exposes every gap: the password that only lived on the old server, the SSH key nobody backed up, the directory that’s been missing for six months. Do it at least once a year and after every major change to the backup script. And delete the test VM afterwards, it contains your production data.
restic vs. Borg vs. Kopia
The three tools are similar: snapshots, deduplication, encryption. The differences are in the details:
| restic | BorgBackup | Kopia | |
|---|---|---|---|
| Program | single binary, Go | Python with C parts | single binary, Go |
| Native targets | local, SFTP, S3, B2, Azure, GCS, REST, rclone | local, SSH (Borg needed on target) | local, SFTP, S3, B2, Azure, GCS, WebDAV, rclone |
| Encryption | always on | optional | always on |
| Append-only | via rest-server | via borg serve --append-only | via server mode and object storage locks |
| GUI | third-party only (e.g. Backrest) | third-party (e.g. Vorta) | built in |
| Windows | yes | only via WSL | yes |
We use restic because it backs up directly to SFTP and S3 without a counterpart on the target, and because the repository format is openly documented. Borg is often a bit faster on SSH targets and has a very mature append-only mode. Kopia is the best pick if you want a built-in GUI. You can’t go wrong with any of them. The only wrong choice is never testing a restore.
What Does a restic Backup Cost?
restic itself is free (BSD licence). Costs only come from storage. Thanks to deduplication, you usually need less than you’d think: in our test, seven snapshots with a combined 404 MiB of restorable data sat in a repository of 52 MiB. That’s an extreme case (the snapshots were nearly identical), but it shows the principle. On a typical server with daily changes in the low single-digit percent range, a repository with six months of retention is often only slightly larger than the original data.
For the offsite target, a Storage Box or an S3 bucket is enough. Provider prices change, so check the pricing page directly. An overview of the total cost of a backup strategy is in our article on the 3-2-1 rule.
Frequently Asked Questions About restic Backup
What is restic?
restic is a free, open-source backup program for Linux, macOS, Windows and BSD. It backs up files as encrypted, deduplicated snapshots into a repository that can live locally, via SFTP, in S3-compatible storage or with many other providers.
Is a restic backup encrypted?
Yes, always. restic has no unencrypted mode. Data is encrypted with AES-256 and protected against modification with Poly1305. Without the password the data is unreadable, even for the storage provider.
What happens if I lose my restic password?
Then the data is lost. There’s no recovery. Keep a copy of the password off the server and consider adding a second key with restic key add.
How do I restore a single file from restic?
With restic restore latest --target /tmp/r --include /path/to/file, or directly with restic dump latest /path/to/file > file. Find the exact path in the snapshot with restic ls latest. An --include that matches nothing doesn’t raise an error, it simply restores nothing.
How often should I run a restic backup?
For most servers once a day, more often for databases with many changes. Thanks to deduplication an extra run costs little space: a run without changes added 0 bytes for us and took under a second.
What does exit code 3 mean for restic backup?
The snapshot was saved, but at least one file couldn’t be read, for example due to missing permissions. So the backup is incomplete. Treat code 3 as a warning you need to look at, not as success.
Why does restic report success when a directory is missing?
Because restic only reports a non-existent source path with does not exist, skipping and saves the snapshot without it, with exit code 0. Check the paths in your script beforehand and regularly verify with restic ls latest what’s really in the snapshot.
Is restic better than Borg?
Not fundamentally. restic can back up directly to SFTP, S3 and many clouds without software on the target and runs natively on Windows. Borg needs a counterpart on SSH targets but is often a bit faster there and has a very mature append-only mode. Both are well suited for server backups.
Is there a GUI for restic?
restic itself is a command-line program. There are front ends from other projects, though, such as Backrest (web UI) or resticprofile (config files instead of long commands). For servers, a script with a systemd timer is usually the more robust solution.
How do I back up a database with restic?
Never the live database files, always a dump: mysqldump … | restic backup --stdin --stdin-filename mysql.sql. Always set set -o pipefail in the script, or a half-aborted dump ends up in the backup with exit code 0. From restic 0.17, --stdin-from-command is the safer option.
What do I do about “repository is already locked”?
First check whether another restic process is still running (pgrep -a restic). If not, it was usually an aborted run. restic unlock removes stale locks. In our test, such a lock blocked check and prune while new backups kept running.
Conclusion: A restic Backup Is Quick to Build, Verification Makes It Safe
restic is one of the most pleasant backup tools for Linux servers: one program, encryption with no extra effort, deduplication good enough that daily snapshots cost hardly any space, and restores of small data sets take under a second. But our measurements also show where the real work lies: a missing path, a half database dump and a stale lock all look like success to a script that only checks $? from restic backup.
The short checklist:
- Password in a file with mode
600and a copy off the server. - Always absolute paths, and the script checks that they exist first.
set -euo pipefailin every script, treat exit code 3 as a warning.- A second copy offsite, ideally one your server can’t delete.
- Monitor
forget --pruneandchecktoo, not justbackup. - Once a year, a real restore on an empty machine.
If you want to revisit the underlying rule: the 3-2-1 backup strategy explains how many copies you need and where. And if you only do one thing today, make it this: restic restore latest --target /tmp/restore-test and a diff -r against the original. Only then do you have a backup.
