👍 What we like
- Genuinely follows the 3-2-1 rule, with an off-site copy.
- Client-side encryption: neither the NAS, nor the cloud provider, nor the person hosting the remote NAS can read your data.
- Deduplication: after the first backup, only changes are transferred.
- Fine-grained restore of a single file or folder with restore --include or dump.
- Free and open-source software, no mandatory proprietary service.
👎 What to watch
- Command-line setup: no official graphical interface.
- Losing a repository password makes that repository unrecoverable.
- The server holds the credentials for both repositories: plan versioning, Object Lock or snapshots against ransomware.
- Cloud storage and data re-reads (check) may be billed by the provider; a NAS at a relative's home depends on their connection and power.
📑 Contents ▾
- 01 What counts as a copy, and what doesn’t
- 02 If your data lives on the NAS
- 03 Prerequisites
- 04 Step-by-step installation
- 05 Variant: the off-site copy on a NAS at a relative’s home
- 06 Other NAS models usable as an SFTP target (copy 2)
- 07 Verification checks
- 08 Security and best practices
- 09 Troubleshooting common errors
- 10 FAQ
- Our picks
The 3-2-1 rule calls for three copies of your data, on two different media, with one off-site. This tutorial sets it up with restic, a free and open-source backup tool that encrypts everything client-side: the original data on your server, a repository on your NAS, and an off-site copy in an S3-compatible bucket or on a second NAS installed at a relative’s home. NAS snapshots don’t count as a copy, and a backup is only worth something once its restore has been tried: both points are covered below.
The architecture looks like this:
- Copy 1: the original data on your Linux server (for example
/etc,/home,/srv). - Copy 2: a restic repository on your NAS, reached over SFTP on the local network.
- Copy 3: a second restic repository in an S3-compatible bucket (Amazon S3, Backblaze B2’s S3 API, Wasabi, an off-site MinIO…), filled by
restic copyfrom the NAS repository. Subscription-free variant: an SFTP repository on a NAS placed at a relative’s home (dedicated section after the tutorial).
restic encrypts the repositories before anything is sent, so neither the NAS nor the cloud provider stores anything readable without the password. restic reads no YAML configuration file. Everything goes through command-line options and environment variables (RESTIC_PASSWORD_FILE, AWS_ACCESS_KEY_ID…), which is why you’ll write a small shell script below.
What counts as a copy, and what doesn’t
- A NAS snapshot is a frozen image of a volume at a given moment. It is created almost instantly, because it doesn’t copy the data (copy-on-write, for example on a Synology’s Btrfs volumes). It lets you roll back after a deletion, an unfortunate change or files encrypted by ransomware. But it is stored on the same volume: if the volume or the NAS is lost (drive failures, theft, disaster), the snapshots go with it. So it is not one of the three copies.
- RAID protects against a drive failure, not against a deletion, software corruption or the loss of the device. It isn’t a copy either.
- A backup is a copy on another medium (another drive, another NAS, cloud storage), with history, that you check and restore from time to time.
The two work together: scheduled snapshots on the NAS share that holds the restic repository protect it against a deletion launched from a compromised server (see “Security and best practices”).
If your data lives on the NAS
This tutorial’s layout starts from a Linux server. If your files live on the NAS in the first place (photos, shared documents), the NAS becomes copy 1 and you need two more copies:
- copy 2, local, on another medium: an external USB drive, fed by the NAS’s own backup tool, such as Hyper Backup on Synology (see our tutorial on backing up a NAS to an external drive);
- copy 3, off-site: cloud storage, which DSM (Synology) and QTS (QNAP) can back up to, or a second NAS at a relative’s home (dedicated section below).
You can also stick with restic: from a Linux machine that mounts the NAS share, the step 6 script backs up that mount point like any other folder.
Prerequisites
- A recent Linux server with
rootorsudoaccess: Debian 12/13 or Ubuntu 22.04/24.04. Commands are run as root, because the scheduled job will run as root to read every file. - A NAS on the local network, with the SFTP service enabled and a dedicated shared folder (for example
backup). A QNAP TS-453D or a Synology DiskStation DS1821+ works as the SFTP target for copy 2 (other models are covered below). But the NAS alone does not satisfy the 3-2-1 rule: it stays in your home and is not the off-site copy. - An account with an S3-compatible storage provider, with an empty bucket and an access key restricted to that bucket (to choose one, see our Backblaze B2 vs Wasabi vs AWS S3 comparison). For Backblaze B2, the restic documentation recommends the S3-compatible API rather than the native
b2:backend. If you go with a NAS at a relative’s home, you don’t need this account. - No inbound ports need to be opened: the server connects to the NAS over the LAN and reaches the cloud outbound over HTTPS.
Step-by-step installation
Step 1: Install restic
The distribution package is the easiest to install, but it often lags behind the current version (0.19.1 at the time of writing). Install it, then fetch the current official binary into /usr/local/bin, without overwriting the file managed by dpkg:
sudo apt update
sudo apt install -y restic
sudo restic self-update --output /usr/local/bin/restic
hash -r
restic version
If self-update isn’t available in your distribution’s package, install the official binary by hand (set VER to the latest release on GitHub, and change amd64 to arm64 if needed):
mkdir -p /tmp/restic-dl && cd /tmp/restic-dl
VER=0.19.1
curl -LO "https://github.com/restic/restic/releases/download/v${VER}/restic_${VER}_linux_amd64.bz2"
curl -LO "https://github.com/restic/restic/releases/download/v${VER}/SHA256SUMS"
sha256sum --ignore-missing -c SHA256SUMS
bunzip2 "restic_${VER}_linux_amd64.bz2"
sudo install -m 755 "restic_${VER}_linux_amd64" /usr/local/bin/restic
Check: command -v restic must return /usr/local/bin/restic, and restic version the expected version. sha256sum must print OK for the downloaded file.
Step 2: Prepare SFTP access to the NAS
Enable SFTP on the NAS:
- Synology DSM 7: Control Panel > File Services > FTP, tick Enable SFTP service, then Apply.
- QNAP QTS 5.1.8+ / QuTS hero: Control Panel > Network & File Services > Telnet / SSH, tick Enable SFTP, then Apply.
Create a dedicated user on the NAS (for example backup) with write access to the backup shared folder only. Then, on the server, generate an SSH key without a passphrase (cron must be able to use it) and declare an alias:
sudo ssh-keygen -t ed25519 -N "" -f /root/.ssh/id_ed25519_restic
sudo tee -a /root/.ssh/config >/dev/null <<'EOF'
Host nas
HostName 192.168.1.20
User backup
Port 22
IdentityFile /root/.ssh/id_ed25519_restic
IdentitiesOnly yes
EOF
sudo chmod 600 /root/.ssh/config
sudo ssh-copy-id -i /root/.ssh/id_ed25519_restic.pub nas
Replace 192.168.1.20 with your NAS’s address. If ssh-copy-id fails, see your NAS documentation for how to enable key-based authentication. On DSM, you usually need to enable the user home service.
Check: sudo sftp nas must open a session without asking for a password. Type ls: the shared folder should appear (on DSM, shares show up as /backup). Note the exact path, then exit with bye.
Step 3: Create the secret files
Each repository gets its own password, stored in a file only root can read. The S3 credentials go into an environment file:
sudo install -d -m 700 /etc/restic
sudo sh -c 'openssl rand -base64 32 > /etc/restic/nas.pass'
sudo sh -c 'openssl rand -base64 32 > /etc/restic/cloud.pass'
sudo tee /etc/restic/cloud.env >/dev/null <<'EOF'
AWS_ACCESS_KEY_ID=YOUR_KEY_ID
AWS_SECRET_ACCESS_KEY=YOUR_SECRET
AWS_DEFAULT_REGION=eu-central-1
CLOUD_REPO=s3:https://YOUR_PROVIDER_S3_ENDPOINT/BUCKET_NAME/restic
EOF
sudo sh -c 'chmod 600 /etc/restic/*'
Take the endpoint and region from your provider’s console. On Backblaze B2, the S3 endpoint is listed in the bucket details. Copy both passwords into a password manager right away, off the server: without them, the repositories cannot be recovered.
Check: sudo ls -l /etc/restic must show three files (cloud.env, cloud.pass, nas.pass) as -rw------- root root.
Step 4: Initialize the NAS repository (copy 2)
sudo restic -r sftp:nas:/backup/restic --password-file /etc/restic/nas.pass init
Adjust /backup/restic to the path you noted in step 2. restic creates the restic folder itself.
Check:
sudo restic -r sftp:nas:/backup/restic --password-file /etc/restic/nas.pass cat config
The command should print JSON containing "version" and "chunker_polynomial".
Step 5: Initialize the cloud repository (copy 3)
The cloud repository is created with the same chunker parameters as the NAS repository, so deduplication works during restic copy. These parameters can’t be changed after creation.
sudo bash -c 'set -a; . /etc/restic/cloud.env; set +a
restic -r "$CLOUD_REPO" --password-file /etc/restic/cloud.pass init \
--from-repo sftp:nas:/backup/restic --from-password-file /etc/restic/nas.pass \
--copy-chunker-params'
Check: your provider’s console should show a restic/ prefix in the bucket containing config, keys/, and so on. The same command with snapshots in place of init ... should run without errors (no snapshots yet).
Step 6: Write the backup script
First, create the exclusion list:
sudo tee /etc/restic/excludes.txt >/dev/null <<'EOF'
/home/*/.cache
/var/tmp
*.tmp
EOF
Then create /usr/local/sbin/restic-321.sh. It backs up to the NAS, applies retention, copies the snapshots to the cloud, then applies the same retention on the cloud side:
sudo tee /usr/local/sbin/restic-321.sh >/dev/null <<'EOF'
#!/usr/bin/env bash
set -euo pipefail
export PATH=/usr/local/bin:/usr/bin:/bin
exec >>/var/log/restic-321.log 2>&1
trap 'echo "$(date -Is) FAILED (line $LINENO)"' ERR
echo "=== $(date -Is) start ==="
NAS_REPO="sftp:nas:/backup/restic"
NAS_PASS=/etc/restic/nas.pass
set -a; . /etc/restic/cloud.env; set +a
KEEP=(--keep-daily 7 --keep-weekly 4 --keep-monthly 12)
restic -r "$NAS_REPO" --password-file "$NAS_PASS" backup \
/etc /home /srv --exclude-file /etc/restic/excludes.txt
restic -r "$NAS_REPO" --password-file "$NAS_PASS" forget "${KEEP[@]}" --prune
restic -r "$CLOUD_REPO" --password-file /etc/restic/cloud.pass copy \
--from-repo "$NAS_REPO" --from-password-file "$NAS_PASS"
restic -r "$CLOUD_REPO" --password-file /etc/restic/cloud.pass forget "${KEEP[@]}" --prune
echo "=== $(date -Is) end OK ==="
EOF
sudo chmod 700 /usr/local/sbin/restic-321.sh
sudo /usr/local/sbin/restic-321.sh
Change /etc /home /srv to your own data. A path that doesn’t exist makes backup exit with an error code, and the script then stops. The first run can take a while: everything is uploaded once, and after that only changes are sent.
Check: sudo tail -n 20 /var/log/restic-321.log must end with end OK. Then:
sudo restic -r sftp:nas:/backup/restic --password-file /etc/restic/nas.pass snapshots
sudo bash -c 'set -a; . /etc/restic/cloud.env; set +a; restic -r "$CLOUD_REPO" --password-file /etc/restic/cloud.pass snapshots'
Both lists must contain the same snapshot: same date, same paths.
Step 7: Schedule the daily backup
sudo tee /etc/cron.d/restic-321 >/dev/null <<'EOF'
SHELL=/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
30 2 * * * root flock -n /run/restic-321.lock /usr/local/sbin/restic-321.sh
EOF
sudo chmod 644 /etc/cron.d/restic-321
flock -n prevents two runs at the same time, for example if a prune takes longer than expected. Output is not sent to /dev/null: the script writes to /var/log/restic-321.log itself.
Check: the next day, sudo journalctl -u cron --since yesterday | grep restic-321 should show the run, and the log should contain a new end OK line. To try it without waiting, temporarily set the time a few minutes ahead.
Step 8: Test a restore
A backup that has never been restored is not a backup. Restore a folder from the cloud (the worst case) into a temporary directory, then compare:
sudo bash -c 'set -a; . /etc/restic/cloud.env; set +a
restic -r "$CLOUD_REPO" --password-file /etc/restic/cloud.pass \
restore latest --target /tmp/restore-test --include /etc/ssh'
sudo diff -r /etc/ssh /tmp/restore-test/etc/ssh && echo "Restore identical"
sudo rm -rf /tmp/restore-test
Check: Restore identical should be printed. A difference can be normal if the file changed since the backup.
Variant: the off-site copy on a NAS at a relative’s home
Cloud storage is billed by the provider, month after month. A second NAS installed at a relative’s or a friend’s home avoids that subscription and keeps the off-site copy under your control. With restic, the logic doesn’t change: copy 3 becomes an SFTP repository on that remote NAS, and client-side encryption guarantees that the person hosting it cannot read your data.
Set up the remote repository
1. Reach the NAS without opening a port. Install Tailscale on the remote NAS and on your server (see our Tailscale tutorial). The server then reaches it by its MagicDNS name, with no port forwarding on your relative’s Internet box. Enable SFTP and create the backup user on that NAS as in step 2.
2. Declare a second SSH alias, with the same key:
sudo tee -a /root/.ssh/config >/dev/null <<'EOF'
Host nas-proche
HostName MAGICDNS_NAME_OF_THE_REMOTE_NAS
User backup
Port 22
IdentityFile /root/.ssh/id_ed25519_restic
IdentitiesOnly yes
EOF
sudo ssh-copy-id -i /root/.ssh/id_ed25519_restic.pub nas-proche
sudo sftp nas-proche must open a session without a password.
3. Create the remote repository with its own password and the NAS repository’s chunker parameters:
sudo sh -c 'openssl rand -base64 32 > /etc/restic/proche.pass'
sudo chmod 600 /etc/restic/proche.pass
sudo restic -r sftp:nas-proche:/backup/restic --password-file /etc/restic/proche.pass init \
--from-repo sftp:nas:/backup/restic --from-password-file /etc/restic/nas.pass \
--copy-chunker-params
4. Adapt the script: in /usr/local/sbin/restic-321.sh, replace the two restic -r "$CLOUD_REPO" ... commands (copy and forget) with these (and remove the line that loads cloud.env if you no longer use the cloud):
restic -r sftp:nas-proche:/backup/restic --password-file /etc/restic/proche.pass copy \
--from-repo "$NAS_REPO" --from-password-file "$NAS_PASS"
restic -r sftp:nas-proche:/backup/restic --password-file /etc/restic/proche.pass forget "${KEEP[@]}" --prune
The checks and the step 8 restore apply as they are, with -r sftp:nas-proche:/backup/restic --password-file /etc/restic/proche.pass. Store this third password with the other two, off the server.
What changes with a remote NAS
- The first upload. The first
restic copysends the whole repository over your Internet connection. To save time, run it while the remote NAS is still at your place, on the local network, then install it at your relative’s home: restic will only send changes after that. Since the alias points to the Tailscale name, nothing needs to change after the move. - Your relative’s connection and power. If their box is off or the power goes out, that night’s copy fails. Have the script monitored (see “Security and best practices”) so you find out the same day rather than when you need the backup.
- Power consumption. The NAS runs on your relative’s electricity bill. As an example, the QNAP TS-673A spec sheet lists 21.9 W with drives in sleep mode and 45.9 W in typical operation, with all bays populated. The Synology DS423+ supports scheduled power on/off: you can power it on only during the backup window, as long as the cron time matches. To put a figure on the cost, see how to measure your homelab’s power consumption.
- Throughput. Transfers are limited by the Internet link between the two homes long before the NAS’s network: 2.5GbE ports make no difference to the off-site copy.
Which NAS to install at a relative’s home
According to their manufacturer spec sheets:
| Model | Processor | Memory | Slots | Network |
|---|---|---|---|---|
| Synology DS423+ | Intel Celeron J4125 | 2 GB DDR4, up to 6 GB | 4 x 3.5”/2.5” SATA bays | 2 x 1GbE |
| QNAP TS-673A | AMD Ryzen Embedded V1500B, 4 cores at 2.2 GHz | 8 GB DDR4, up to 64 GB | 6 x 3.5” SATA bays | 2 x 2.5GbE |
| Asustor Flashstor 6 FS6706T | Intel Celeron N5105 | 4 GB DDR4 | 6 M.2 NVMe slots | 2 x 2.5GbE |
- The Synology DS423+ is the easiest to hand over to someone else: DSM, four bays, two extra M.2 NVMe slots, and the scheduled power on/off mentioned above.
- The QNAP TS-673A suits a large volume to protect: six bays, two PCIe Gen3 x4 slots (faster networking or SSDs), expandable memory. It has no integrated GPU, which doesn’t matter for a backup target. Its spec sheet lists 20.3 dB(A).
- The Asustor Flashstor 6 FS6706T only takes M.2 SSDs (no 3.5” drives): capacity depends on the number and size of the SSDs installed, but the device is quiet, 18.7 dB at idle according to its spec sheet, which matters if it sits in someone’s living room.
Other NAS models usable as an SFTP target (copy 2)
For copy 2, any NAS that enables SFTP and accepts a dedicated user will do, as long as it has room for the restic repository and its snapshots.
- QNAP TS-453D: four 3.5”/2.5” bays and two 2.5GbE ports; its manufacturer page lists 11.3 W with drives in sleep mode and 25.98 W in typical operation. It supports snapshots and backups to an external drive or the cloud.
- Synology DiskStation DS1821+: a Synology NAS running DSM; SFTP is enabled as shown in step 2, and the
backupuser is created the same way. - Synology DiskStation DS920+: four 3.5”/2.5” bays plus two M.2 NVMe slots, two 1GbE ports, expandable up to nine drives according to its spec sheet, and snapshots on Btrfs volumes. DSM can also back up to cloud services, including Amazon S3.
- WD My Cloud EX4100: a simpler option, with fewer advanced features; check that it still receives updates and offers SFTP before making it a restic target.
- Asustor AS6402T: check the Asustor page for the number of bays and snapshot support before making it a restic target.
Verification checks
Every so often, for example once a month, run an integrity check on both repositories. --read-data-subset actually re-reads part of the data, not just the metadata:
sudo restic -r sftp:nas:/backup/restic --password-file /etc/restic/nas.pass check --read-data-subset=10%
sudo bash -c 'set -a; . /etc/restic/cloud.env; set +a; restic -r "$CLOUD_REPO" --password-file /etc/restic/cloud.pass check --read-data-subset=5%'
Expected result: no errors were found. On the cloud side, re-reading data generates egress traffic, which some providers charge for, so keep the percentage modest.
Security and best practices
- Never expose to the Internet the NAS admin interface (DSM, QTS), its SSH or its SFTP, and set up no port forwarding to them. For remote administration, go through a mesh VPN: see our Tailscale tutorial.
- Lost password = lost data: restic offers no way to recover it. Keep the passwords off the server.
- Least privilege: the NAS
backupuser can only write to its share, and the S3 key only has access to its bucket. - Ransomware: the server holds the credentials for the repositories, so an attacker who compromises it could delete them. To protect yourself, enable bucket versioning or Object Lock if your provider offers it, and scheduled snapshots on the NAS share that holds the repository: they are managed by the NAS, out of reach of the server’s credentials. Check how they work with
prunein your provider’s documentation and in the restic documentation (“append-only” section). - Get warned about failures: a backup that fails silently is only discovered when you try to restore. Add a call to the URL of an Uptime Kuma Push monitor or a Healthchecks check at the end of the script, after the
end OKline (curl -fsS -o /dev/null "MONITOR_URL" || true): the alert fires when the call doesn’t arrive. The setup is described in our homelab monitoring guide. - Updates:
sudo apt update && sudo apt upgradefor the system,sudo restic self-update --output /usr/local/bin/resticfor restic.
Troubleshooting common errors
- Symptom:
Fatal: unable to open config file/Is there a repository at the following location?Cause: wrong SFTP path or S3 URL, or the repository was never initialized. Fix: check the path withsudo sftp nasthenls, and checkCLOUD_REPO(formats3:https://endpoint/bucket/prefix, path-style). - Symptom:
subsystem request failed on channel 0or connection refused. Cause: SFTP is disabled on the NAS, or the port is wrong. Fix: re-enable SFTP (menu paths in step 2) and checkPortin/root/.ssh/config. - Symptom:
wrong password or no key found. Cause: you are using one repository’s password file on another. Fix:nas.passgoes with the NAS repository,cloud.passwith the cloud repository,proche.passwith the remote NAS (and--from-password-filewith the source ofcopy). - Symptom:
Access Deniedor a region error on the S3 side. Cause: the key has no rights on the bucket, or the region is wrong. Fix: generate a new key restricted to the bucket and setAWS_DEFAULT_REGIONto the value your provider gives. - Symptom:
repository is already locked. Cause: another operation is running, or a run was interrupted. Fix: check withpgrep -a resticthat no restic process is running, then runrestic -r ... unlockon the repository concerned. - Symptom: the remote NAS no longer answers (
connection timed outonnas-proche). Cause: your relative’s NAS or box is off, or Tailscale is disconnected on one of the two devices. Fix: check withtailscale statusthat the remote NAS shows as online, then run the script by hand once the link is back.
FAQ
Are the backups encrypted?
Yes. restic encrypts and authenticates all data on the server before sending it (AES-256 in counter mode, authenticated with Poly1305-AES, according to its design documentation). The NAS, the cloud provider or the remote NAS only see encrypted blobs.
Why restic copy instead of two independent backups?
Files are read only once, and both repositories hold exactly the same snapshots. Thanks to --copy-chunker-params, only data missing from the off-site copy is transferred.
How do I restore a single file?
Find its path with restic -r ... ls latest, then run restic -r ... restore latest --target /tmp/r --include /path/to/file. To print the file to standard output, use restic -r ... dump latest /path/to/file.
How do I check that the off-site backups are intact?
restic check verifies the repository structure. Add --read-data-subset to re-read and verify part of the data actually stored.
Key facts
Our picks
Affiliate links · same price for youQNAP TS-453D
- 4 x 3.5"/2.5" bays
- 2 x 2.5GbE ports
Amazon · price and availability on the listing
Synology DiskStation DS1821+
Amazon · price and availability on the listing
Synology DiskStation DS920+
- 4 x 3.5"/2.5" bays + 2 M.2 NVMe
- 2 x 1GbE ports
Amazon · price and availability on the listing
Synology DS423+
- Intel Celeron J4125
- 2 GB DDR4 (up to 6 GB)
- 4 SATA bays
- 2 x 1GbE ports
Amazon · price and availability on the listing
QNAP TS-673A
- AMD Ryzen Embedded V1500B
- 8 GB DDR4 (up to 64 GB)
- 6 x 3.5" SATA bays
- 2 x 2.5GbE ports
Amazon · price and availability on the listing
Asustor Flashstor 6 FS6706T
- Intel Celeron N5105
- 4 GB DDR4
- 6 M.2 NVMe slots
- 2 x 2.5GbE ports
Amazon · price and availability on the listing
See all our recommended gear in the shop.