Set Up Automatic Incremental Backups on Linux with Restic and S3-Compatible Storage

Why Restic Is a Smart Backup Tool in 2026

Backups are one of those tasks everyone agrees are important—right up until storage fills up, scripts break, or restore day arrives and nothing works. If you need a modern backup solution for Linux servers, laptops, or small business systems, restic is a strong choice. It is fast, encrypted by default, supports incremental snapshots, and works well with local disks, SSH targets, and S3-compatible object storage (such as MinIO, Backblaze B2 S3, Wasabi, or many private clouds).

This tutorial shows how to configure automatic incremental backups with restic to an S3-compatible bucket, keep backups clean with retention policies, and validate that restores actually work. The goal is a setup you can run unattended with systemd timers.

Prerequisites

Before you start, you’ll need a Linux system with root or sudo access, network connectivity to your S3 endpoint, and an S3 bucket created for backups. You should also have an access key and secret key for a user that can read and write that bucket. For best results, create a dedicated bucket and dedicated credentials only for backups.

Step 1: Install Restic

On Ubuntu/Debian, install from the package repository:

sudo apt update && sudo apt install -y restic

On RHEL/AlmaLinux/Rocky, restic may be available via EPEL, or you can install from an official release binary. If you install a binary, place it in /usr/local/bin/restic and ensure it’s executable.

Step 2: Prepare Environment Variables for S3

Restic reads S3 settings from environment variables. Create a root-only file to store them:

sudo mkdir -p /etc/restic
sudo nano /etc/restic/env

Add values like the following (adjust to your provider). The AWS_ENDPOINT_URL line is especially important for S3-compatible services:

export AWS_ACCESS_KEY_ID="YOUR_ACCESS_KEY"
export AWS_SECRET_ACCESS_KEY="YOUR_SECRET_KEY"
export AWS_DEFAULT_REGION="us-east-1"
export AWS_ENDPOINT_URL="https://s3.your-provider.example"

Lock down permissions so only root can read it:

sudo chmod 600 /etc/restic/env

Step 3: Create and Initialize the Restic Repository

Decide where your repository will live. For S3, the syntax is s3:https://endpoint/bucketname or sometimes s3:bucketname depending on provider. A safe, explicit pattern for S3-compatible endpoints is:

export RESTIC_REPOSITORY="s3:https://s3.your-provider.example/my-linux-backups"

Set a strong repository password (store it securely). For unattended jobs, put it in a root-only file:

sudo nano /etc/restic/password

Add one line containing the password, then:

sudo chmod 600 /etc/restic/password

Initialize the repository:

sudo bash -c 'source /etc/restic/env && export RESTIC_PASSWORD_FILE=/etc/restic/password && export RESTIC_REPOSITORY="s3:https://s3.your-provider.example/my-linux-backups" && restic init'

Step 4: Run Your First Incremental Backup

Restic snapshots are incremental by design: after the first run, subsequent runs only transfer changed data. Start with a realistic set of folders. For a server, you might back up /etc, /home, and application data such as /srv. Avoid transient paths like /proc and /sys.

Example backup command:

sudo bash -c 'source /etc/restic/env && export RESTIC_PASSWORD_FILE=/etc/restic/password && export RESTIC_REPOSITORY="s3:https://s3.your-provider.example/my-linux-backups" && restic backup /etc /home /srv --exclude /home/*/.cache --exclude /srv/tmp'

List snapshots to confirm it worked:

sudo bash -c 'source /etc/restic/env && export RESTIC_PASSWORD_FILE=/etc/restic/password && export RESTIC_REPOSITORY="s3:https://s3.your-provider.example/my-linux-backups" && restic snapshots'

Step 5: Add Retention Rules (Forget + Prune)

Without retention, backups grow forever. A common policy is “keep daily backups for a week, weekly backups for a month, and monthly backups for a year.” Apply it like this:

sudo bash -c 'source /etc/restic/env && export RESTIC_PASSWORD_FILE=/etc/restic/password && export RESTIC_REPOSITORY="s3:https://s3.your-provider.example/my-linux-backups" && restic forget --keep-daily 7 --keep-weekly 4 --keep-monthly 12 --prune'

The --prune option actually removes unreferenced data, keeping storage costs under control.

Step 6: Automate Backups with a Systemd Service and Timer

Create a simple backup script so the systemd unit stays clean:

sudo nano /usr/local/sbin/restic-backup.sh

Paste (adjust paths and repository):

#!/bin/bash
set -euo pipefail
source /etc/restic/env
export RESTIC_PASSWORD_FILE=/etc/restic/password
export RESTIC_REPOSITORY="s3:https://s3.your-provider.example/my-linux-backups"
restic backup /etc /home /srv --exclude /home/*/.cache --exclude /srv/tmp
restic forget --keep-daily 7 --keep-weekly 4 --keep-monthly 12 --prune
restic check

Make it executable:

sudo chmod 700 /usr/local/sbin/restic-backup.sh

Now create the systemd service:

sudo nano /etc/systemd/system/restic-backup.service

Service content:

[Unit]
Description=Restic Backup to S3
Wants=network-online.target
After=network-online.target

[Service]
Type=oneshot
ExecStart=/usr/local/sbin/restic-backup.sh

Create the timer (daily at 02:15):

sudo nano /etc/systemd/system/restic-backup.timer

Timer content:

[Unit]
Description=Run Restic Backup Daily

[Timer]
OnCalendar=*-*-* 02:15:00
Persistent=true

[Install]
WantedBy=timers.target

Enable it:

sudo systemctl daemon-reload
sudo systemctl enable --now restic-backup.timer

Check status and recent runs:

systemctl status restic-backup.timer
journalctl -u restic-backup.service --since "2 days ago"

Step 7: Test a Restore (The Part Most People Skip)

A backup you never test is just a theory. Create a restore directory and restore a single file or folder to verify permissions and content:

sudo mkdir -p /restore-test
sudo bash -c 'source /etc/restic/env && export RESTIC_PASSWORD_FILE=/etc/restic/password && export RESTIC_REPOSITORY="s3:https://s3.your-provider.example/my-linux-backups" && restic restore latest --target /restore-test --include /etc/ssh'

Confirm the restored files exist under /restore-test. If you can restore cleanly, you can trust the automation far more.

Final Notes for a Reliable Backup Routine

For production systems, keep the repository password in a secure vault when possible, restrict bucket permissions, and consider enabling object-lock or versioning if your provider supports it. Restic’s encryption and incremental design make it efficient, but the real win is consistency: automated snapshots, retention rules, and periodic restore tests turn backups into a predictable safety net instead of a last-minute panic.

Set Up Restic + S3-Compatible Storage for Secure, Automated Linux Backups

Why Restic Is a Smart Backup Choice in 2026

Backups are easy to postpone until the day you need them. Restic is a modern backup tool that helps you avoid that trap by making backups fast, encrypted by default, and storage-efficient through deduplication. It works especially well with S3-compatible object storage (such as MinIO, Wasabi, Backblaze B2 S3, Cloudflare R2 via S3 API, and many NAS appliances), giving you an offsite backup that is both resilient and scalable.

In this tutorial, you will install Restic on Linux, connect it to an S3-compatible bucket, create a secure backup policy, automate it with systemd, and verify that restores work. The steps focus on a practical, production-friendly setup you can run on a server or workstation.

Prerequisites

Before you start, you need: a Linux machine (Debian/Ubuntu, RHEL/Rocky/Alma, or similar), credentials for an S3-compatible bucket (access key, secret key, endpoint URL, and bucket name), and enough permissions to read the directories you want to back up. If you are backing up system paths like /etc and /var, you will likely run Restic as root.

Step 1: Install Restic

On Ubuntu/Debian, you can install Restic from the package manager:

sudo apt update && sudo apt install -y restic

On RHEL/Rocky/Alma, Restic is often available via EPEL:

sudo dnf install -y epel-release && sudo dnf install -y restic

After installation, confirm the version:

restic version

Step 2: Define Environment Variables for S3 Storage

Restic reads S3 credentials from environment variables. Create a root-only environment file so secrets are not exposed in shell history:

sudo install -m 0600 /dev/null /etc/restic.env

Edit the file:

sudo nano /etc/restic.env

Add the following (adjust values for your provider):

AWS_ACCESS_KEY_ID=YOUR_ACCESS_KEY

AWS_SECRET_ACCESS_KEY=YOUR_SECRET_KEY

AWS_DEFAULT_REGION=us-east-1

RESTIC_REPOSITORY=s3:https://s3.example.com/my-restic-bucket

RESTIC_PASSWORD=Use-A-Long-Unique-Passphrase

If you are using a custom endpoint (common with MinIO and many S3-compatible services), the repository URL format is important: s3:https://ENDPOINT/BUCKET. Keep the password strong; it encrypts your data, and there is no recovery if you lose it.

Step 3: Initialize the Restic Repository

Load the environment and initialize the repository:

sudo -E bash -c 'set -a; source /etc/restic.env; set +a; restic init'

This creates the repository structure in your bucket. If initialization fails, double-check your endpoint URL, bucket name, and credentials. Also ensure the bucket exists and the credentials have permission to list, put, and delete objects.

Step 4: Run Your First Backup

Start with a clear, high-value set of directories. For example, backing up system configuration and user data:

sudo -E bash -c 'set -a; source /etc/restic.env; set +a; restic backup /etc /home --exclude /home/*/.cache'

Restic will scan files, upload only new chunks, and output a snapshot ID. The next backups are usually much faster thanks to deduplication.

Step 5: Verify Snapshots and Test a Restore

List snapshots to confirm your backup history:

sudo -E bash -c 'set -a; source /etc/restic.env; set +a; restic snapshots'

To restore safely, do a test restore to a temporary directory:

sudo mkdir -p /restore-test

sudo -E bash -c 'set -a; source /etc/restic.env; set +a; restic restore latest --target /restore-test'

Open a few restored files and confirm permissions and content. A backup you never tested is not a backup; it is a guess.

Step 6: Add Retention and Repository Maintenance

Without retention rules, storage can grow quietly. A common policy keeps daily backups for a week, weekly backups for a month, and monthly backups for a year:

sudo -E bash -c 'set -a; source /etc/restic.env; set +a; restic forget --keep-daily 7 --keep-weekly 4 --keep-monthly 12 --prune'

Also schedule an integrity check occasionally (weekly or monthly):

sudo -E bash -c 'set -a; source /etc/restic.env; set +a; restic check'

Step 7: Automate Backups with systemd

Create a service unit that loads the environment file. Save this as /etc/systemd/system/restic-backup.service:

[Unit]

Description=Restic Backup

Wants=network-online.target

After=network-online.target

[Service]

Type=oneshot

EnvironmentFile=/etc/restic.env

ExecStart=/usr/bin/restic backup /etc /home --exclude /home/*/.cache

ExecStartPost=/usr/bin/restic forget --keep-daily 7 --keep-weekly 4 --keep-monthly 12 --prune

[Install]

WantedBy=multi-user.target

Now create a timer at /etc/systemd/system/restic-backup.timer:

[Unit]

Description=Run Restic Backup Daily

[Timer]

OnCalendar=daily

Persistent=true

[Install]

WantedBy=timers.target

Enable and start the timer:

sudo systemctl daemon-reload

sudo systemctl enable --now restic-backup.timer

To confirm it will run, check timers and the last run logs:

systemctl list-timers --all | grep restic

journalctl -u restic-backup.service --no-pager -n 100

Common Troubleshooting Tips

If you see authentication errors, re-check the environment file permissions and values, and confirm your storage provider’s S3 endpoint URL. If backups are slow, review exclusions (caches and build directories can explode in size) and consider backing up database dumps instead of live database directories. If you are backing up a server over a flaky connection, Restic’s incremental design helps, but you should still schedule backups during quieter hours.

With Restic plus S3-compatible storage, you get encrypted offsite backups, predictable automation, and a restore process that is straightforward. Once your daily job is stable, the next best improvement is to document a full recovery runbook and test it quarterly.

How to Set Up Restic + S3-Compatible Storage for Fast, Encrypted Linux Backups (With Automation and Restore Testing)

Why Restic Is a Smart Backup Tool in 2026

If you want a modern backup system on Linux that is fast, encrypted by default, and easy to automate, restic is one of the most practical options available today. It creates deduplicated snapshots, supports incremental backups automatically, and works with many backends including local disks, SSH, and S3-compatible object storage (Amazon S3, Backblaze B2 S3 API, MinIO, Wasabi, and more). In this tutorial, you will set up restic with an S3-compatible bucket, run your first backup, verify integrity, and automate daily runs with systemd.

What You Need Before You Start

You will need a Linux machine (server or workstation), an S3-compatible bucket, and access credentials (Access Key ID and Secret Access Key). Make sure the bucket exists and that your account has permission to list, write, and delete objects. Also plan a secure place for a restic password (a file readable only by root is typical). If you are backing up a server, decide which paths to include and which to exclude (temporary folders, caches, and large build artifacts).

Step 1: Install Restic

On Ubuntu/Debian, you can install from the repo, but for newer features you may prefer the official binary release. First try the package manager:

Debian/Ubuntu: sudo apt update && sudo apt install -y restic

RHEL/Fedora: sudo dnf install -y restic

Confirm the version with restic version. If your distro version is old and you need a newer build, download the official release from restic’s GitHub and place it in /usr/local/bin.

Step 2: Create a Secure Password File

Restic encrypts the repository using a password. Store it in a root-owned file and lock down permissions:

sudo mkdir -p /etc/restic
sudo bash -c 'umask 077; printf "%s\n" "REPLACE_WITH_A_LONG_RANDOM_PASSWORD" > /etc/restic/repo.pass'
sudo chmod 600 /etc/restic/repo.pass

Use a long random password. If you lose it, you lose access to the backup data.

Step 3: Export S3 and Restic Environment Variables

Restic reads configuration from environment variables. For an S3-compatible provider, you will typically set the endpoint URL too (MinIO, Wasabi, or private S3 gateways). Create a config file you can reuse for scripts:

sudo bash -c 'cat > /etc/restic/env.sh <<EOF export AWS_ACCESS_KEY_ID="YOUR_ACCESS_KEY" export AWS_SECRET_ACCESS_KEY="YOUR_SECRET_KEY" export RESTIC_PASSWORD_FILE="/etc/restic/repo.pass" export RESTIC_REPOSITORY="s3:https://s3.example.com/my-linux-backups" # Optional but common for S3-compatible services: export AWS_DEFAULT_REGION="us-east-1" EOF chmod 600 /etc/restic/env.sh'

Replace s3.example.com with your provider endpoint (or omit it for AWS), and use your bucket name in the repository path.

Step 4: Initialize the Backup Repository

Initialize the repo once. After that, all backups go into this encrypted repository:

sudo bash -c 'source /etc/restic/env.sh; restic init'

If you see an error about permissions or endpoint connectivity, confirm that the endpoint URL is correct and that your credentials can write to the bucket.

Step 5: Run Your First Backup (With Sensible Exclusions)

A good first backup for a Linux server is often /etc, home directories, and important app data. Exclude caches and ephemeral content to reduce cost and time:

sudo bash -c 'source /etc/restic/env.sh; restic backup /etc /home \ --exclude "/home/*/.cache" \ --exclude "/home/*/.local/share/Trash" \ --exclude "/var/tmp" \ --exclude "/tmp"'

Restic will create a snapshot ID. That snapshot is an immutable point-in-time view you can list and restore later.

Step 6: Verify Backups and Test Restore

A backup that has never been verified is not a backup. Start by listing snapshots:

sudo bash -c 'source /etc/restic/env.sh; restic snapshots'

Then run an integrity check occasionally (especially after large backups):

sudo bash -c 'source /etc/restic/env.sh; restic check'

Finally, do a small restore test to a temporary directory to confirm you can recover files:

sudo mkdir -p /root/restore-test
sudo bash -c 'source /etc/restic/env.sh; restic restore latest --target /root/restore-test --include "/etc/hostname"'

Open the restored file and confirm it matches the live system. This simple step catches password, permissions, and repository issues early.

Step 7: Automate Daily Backups with systemd

For reliable automation, systemd timers are cleaner than cron because they can track failures and integrate with logs. Create a backup script:

sudo bash -c 'cat > /usr/local/sbin/restic-backup.sh <<EOF #!/bin/bash set -euo pipefail source /etc/restic/env.sh restic backup /etc /home \ --exclude "/home/*/.cache" \ --exclude "/home/*/.local/share/Trash" \ --exclude "/tmp" --exclude "/var/tmp" # Keep policy: adjust to your needs and storage costs restic forget --keep-daily 7 --keep-weekly 4 --keep-monthly 6 --prune EOF chmod 700 /usr/local/sbin/restic-backup.sh'

Now create a systemd service and timer:

sudo bash -c 'cat > /etc/systemd/system/restic-backup.service <<EOF [Unit] Description=Restic backup to S3 [Service] Type=oneshot ExecStart=/usr/local/sbin/restic-backup.sh EOF'

sudo bash -c 'cat > /etc/systemd/system/restic-backup.timer <<EOF [Unit] Description=Run restic backup daily [Timer] OnCalendar=daily Persistent=true [Install] WantedBy=timers.target EOF'

Enable and start the timer:

sudo systemctl daemon-reload
sudo systemctl enable --now restic-backup.timer
systemctl list-timers | grep restic

Troubleshooting Tips

If backups fail with S3 errors, double-check the endpoint URL, DNS, firewall rules, and bucket permissions. If you see slow performance, consider placing the repository in a region closer to your server, and avoid backing up huge temporary directories. If pruning takes too long, run it weekly instead of daily, or prune during low-traffic hours. Most importantly, schedule a recurring restore test (monthly is a good baseline) so you know recovery is possible when you actually need it.

Wrap-Up

With restic and S3-compatible storage, you get encrypted, deduplicated backups that scale from a single VPS to multiple servers. The setup is lightweight, the restore process is straightforward, and automation with systemd makes it dependable. Once this is working, the next advanced step is to add monitoring (alert on failed timers) and document your restore procedure so anyone on your team can recover data under pressure.

3.

Set Up Incremental Backups on Linux with Restic and S3-Compatible Storage (Ransomware-Resistant)

Why Restic + S3-Compatible Storage Is a Modern Backup Strategy

If you are still copying folders to an external drive or relying on a single NAS, you are one accident, hardware failure, or ransomware event away from a bad day. A current, practical approach is to use incremental, encrypted backups pushed to S3-compatible object storage (such as MinIO, Backblaze B2 S3, Wasabi, or many private cloud providers). This tutorial walks you through implementing that setup on Linux using Restic, a fast backup tool that deduplicates data, encrypts everything, and supports snapshots you can restore from in minutes.

What You Will Build

By the end of this guide, your Linux server or workstation will automatically create incremental backups to an S3 bucket, keep only a sensible number of snapshots, and run on a schedule using systemd. The result is a backup workflow that is efficient (deduplication), secure (client-side encryption), and resilient (object storage with versioning and immutability options, depending on provider).

Prerequisites

You need a Linux machine with sudo access, an S3-compatible endpoint (provider URL, access key, secret key), and a bucket you can write to. Make sure the system clock is correct (NTP enabled) because snapshot timestamps matter for troubleshooting. If you can, enable bucket-level features like versioning or object lock on the storage side for extra protection.

Step 1: Install Restic

On Debian/Ubuntu, you can install from the repository, although it may not always be the newest version:

sudo apt update && sudo apt install -y restic

On RHEL/CentOS/Fedora systems, check your distro packages or download a current release from Restic’s official GitHub releases. The key point is to use a recent version to benefit from performance and compatibility improvements.

Step 2: Set Environment Variables Securely

Restic reads credentials from environment variables. Create a root-only file to store them. This keeps secrets out of shell history and scripts.

sudo mkdir -p /etc/restic
sudo nano /etc/restic/restic-env

Add values like these (adjust for your provider):

export AWS_ACCESS_KEY_ID="YOUR_ACCESS_KEY"
export AWS_SECRET_ACCESS_KEY="YOUR_SECRET_KEY"
export RESTIC_REPOSITORY="s3:https://s3.example.com/my-linux-backups"
export RESTIC_PASSWORD="Use-A-Long-Unique-Passphrase"

Lock the permissions down:

sudo chmod 600 /etc/restic/restic-env

Step 3: Initialize the Backup Repository

Load the environment file and initialize the repository. This creates the encrypted Restic structure in your bucket.

sudo -i
source /etc/restic/restic-env
restic init

If you get TLS or endpoint errors, verify the S3 URL format and whether your provider requires a region setting. For some S3-compatible services, you may also need to export AWS_DEFAULT_REGION, even if it is a placeholder value.

Step 4: Create an Exclude File (Recommended)

Backups get faster and cleaner when you avoid caches and temporary files. Create an exclude file:

nano /etc/restic/excludes.txt

Example entries:

/proc
/sys
/dev
/run
/tmp
/var/tmp
**/.cache

Step 5: Run Your First Backup

Start with important directories such as /etc, home folders, and application data. For servers, you might also include /var/lib for databases or container volumes (with proper application-aware procedures).

source /etc/restic/restic-env
restic backup /etc /home --exclude-file /etc/restic/excludes.txt

Then confirm a snapshot was created:

restic snapshots

Step 6: Set a Smart Retention Policy

Incremental backups are only useful if you keep enough history without growing storage forever. A common policy is to keep daily snapshots for a week, weekly for a month, and monthly for a year.

restic forget --keep-daily 7 --keep-weekly 4 --keep-monthly 12 --prune

The --prune flag removes unneeded data chunks after snapshots are forgotten, keeping storage usage under control.

Step 7: Automate Backups with systemd

Create a service that runs one backup job. Save this as /etc/systemd/system/restic-backup.service:

[Unit]
Description=Restic Backup to S3
After=network-online.target
Wants=network-online.target

[Service]
Type=oneshot
EnvironmentFile=/etc/restic/restic-env
ExecStart=/usr/bin/restic backup /etc /home --exclude-file /etc/restic/excludes.txt
ExecStartPost=/usr/bin/restic forget --keep-daily 7 --keep-weekly 4 --keep-monthly 12 --prune

[Install]
WantedBy=multi-user.target

Now create a timer at /etc/systemd/system/restic-backup.timer:

[Unit]
Description=Nightly Restic Backup

[Timer]
OnCalendar=*-*-* 02:00:00
Persistent=true

[Install]
WantedBy=timers.target

Enable and start the timer:

sudo systemctl daemon-reload
sudo systemctl enable --now restic-backup.timer
systemctl list-timers | grep restic

Step 8: Test Restores (Do Not Skip This)

A backup is only proven when you restore from it. To restore a single file, first browse snapshots:

source /etc/restic/restic-env
restic snapshots
restic ls latest

Restore a directory to a safe location:

mkdir -p /tmp/restic-restore
restic restore latest --target /tmp/restic-restore --include /etc

For quick checks, you can also run integrity verification occasionally:

restic check

Practical Security Notes

Treat the Restic password like a master key. Store it in a password manager, not only in a file. If your S3 provider supports object lock (WORM) or immutable retention, consider enabling it for the backup bucket to reduce the risk of backup deletion during an attack. Finally, keep at least one additional backup copy or bucket replication in a different region or account for true defense in depth.

Configure Linux Backups with Restic and S3-Compatible Storage (Ransomware-Resistant How-To)

Why Restic + Object Storage Is a Modern Backup Strategy

Traditional file copy backups are easy to set up, but they are also easy to destroy. If ransomware encrypts your server or a compromised account deletes local snapshots, a “backup” stored on the same machine is usually gone. A more resilient approach is to use encrypted, deduplicated backups pushed to remote object storage (S3-compatible services like MinIO, Wasabi, Backblaze B2 S3, or AWS S3). In this tutorial, you will configure Restic on Linux to back up important folders to an S3 bucket, verify restores, and automate everything with a systemd timer.

What You Need

You will need a Linux server (Ubuntu/Debian/RHEL-based), outbound HTTPS access to your object storage endpoint, and credentials for an S3-compatible bucket. It is strongly recommended to use a dedicated bucket (or dedicated prefix) per server. You should also decide which paths to back up (for example: /etc, /home, application config, and data directories) and which directories to exclude (cache, node_modules, temporary files, and large rebuildable artifacts).

Step 1: Install Restic

On Ubuntu or Debian, install Restic from the package manager:

sudo apt update && sudo apt install -y restic

On RHEL/CentOS/AlmaLinux/Rocky, Restic is commonly available via EPEL:

sudo dnf install -y epel-release && sudo dnf install -y restic

Step 2: Prepare S3 Environment Variables

Restic uses environment variables for S3 authentication. Create a protected file so you do not store secrets in shell history. This example uses an S3-compatible endpoint (change values to match your provider):

sudo install -m 600 -o root -g root /dev/null /etc/restic.env

Edit /etc/restic.env and add:

export AWS_ACCESS_KEY_ID="YOUR_ACCESS_KEY"
export AWS_SECRET_ACCESS_KEY="YOUR_SECRET_KEY"
export RESTIC_PASSWORD="USE_A_LONG_UNIQUE_PASSPHRASE"
export RESTIC_REPOSITORY="s3:https://s3.example.com/your-bucket/your-hostname"
export AWS_DEFAULT_REGION="us-east-1"

If you are using AWS S3 itself, your repository line may look like:

export RESTIC_REPOSITORY="s3:s3.amazonaws.com/your-bucket/your-hostname"

Step 3: Initialize the Repository

Load the environment file and initialize the repo. The repository will be encrypted using the password you set:

sudo bash -c 'source /etc/restic.env && restic init'

If you see “created restic repository,” you are ready to back up. If you get TLS or endpoint errors, re-check the endpoint URL and whether your provider requires a specific region or hostname style.

Step 4: Run Your First Backup (with Practical Excludes)

Start with a focused set of folders. Backing up everything under / is rarely ideal because it includes virtual filesystems and caches. Create an excludes file:

sudo install -m 644 /dev/null /etc/restic-excludes.txt

Add common excludes (customize as needed):

/proc
/sys
/dev
/run
/tmp
/var/tmp
/var/cache
/var/log/journal

Run a backup of key paths:

sudo bash -c 'source /etc/restic.env && restic backup /etc /home /var/www --exclude-file /etc/restic-excludes.txt --tag daily'

Restic performs deduplication automatically, so future backups are usually fast and storage-efficient.

Step 5: Verify Snapshots and Test a Restore

A backup is only useful if you can restore it. List snapshots:

sudo bash -c 'source /etc/restic.env && restic snapshots'

To test restoring a single file or folder safely, restore into a temporary directory:

sudo mkdir -p /restore-test

sudo bash -c 'source /etc/restic.env && restic restore latest --target /restore-test --include /etc/ssh'

Confirm files are present, then remove the test directory when you are satisfied.

Step 6: Add Maintenance: Forget and Prune

Without retention rules, backups will grow forever. Restic separates “forget” (remove snapshot references) from “prune” (actually remove unneeded data). A common policy keeps daily backups for two weeks, weekly backups for two months, and monthly backups for a year:

sudo bash -c 'source /etc/restic.env && restic forget --keep-daily 14 --keep-weekly 8 --keep-monthly 12 --prune'

Also schedule occasional integrity checks (for example weekly):

sudo bash -c 'source /etc/restic.env && restic check'

Step 7: Automate with systemd (Safer Than Cron)

Systemd timers provide better logging and predictable behavior. Create a script:

sudo install -m 700 /dev/null /usr/local/sbin/restic-backup.sh

Edit /usr/local/sbin/restic-backup.sh:

#!/bin/bash
set -euo pipefail
source /etc/restic.env
restic backup /etc /home /var/www --exclude-file /etc/restic-excludes.txt --tag daily
restic forget --keep-daily 14 --keep-weekly 8 --keep-monthly 12 --prune

Create a service unit at /etc/systemd/system/restic-backup.service:

[Unit]
Description=Restic Backup to S3

[Service]
Type=oneshot
ExecStart=/usr/local/sbin/restic-backup.sh

Create a timer at /etc/systemd/system/restic-backup.timer:

[Unit]
Description=Daily Restic Backup Timer

[Timer]
OnCalendar=daily
Persistent=true

[Install]
WantedBy=timers.target

Enable and start the timer:

sudo systemctl daemon-reload
sudo systemctl enable --now restic-backup.timer

Check status and logs:

sudo systemctl list-timers | grep restic
sudo journalctl -u restic-backup.service --since today

Final Hardening Tips

For better ransomware resistance, use credentials with the minimum required permissions (write, list, and read for restores), and consider an object storage feature like bucket versioning or object lock if your provider supports it. Keep the Restic password in a secure secrets manager when possible, and document your restore steps so you can recover quickly during an incident. With encrypted offsite backups and regular restore tests, you move from “we have backups” to “we can reliably recover.”

How to Set Up Incremental Backups on Linux with Restic and S3 (Fast, Encrypted, and Reliable)

Why Restic + S3 is a Modern Backup Strategy

Traditional backups often fail for the same reasons: they are slow, unencrypted, hard to automate, or too expensive to store long term. Restic is a modern backup tool designed for speed and simplicity. It creates deduplicated and encrypted backups by default, and it works great with object storage such as Amazon S3 and S3-compatible services (Backblaze B2 S3, Wasabi, MinIO, etc.). In this tutorial, you will set up incremental backups on Linux, store them in S3, and add an automated schedule with pruning and retention.

What You Need Before You Start

You will need a Linux server or desktop with shell access, an S3 bucket (or an S3-compatible endpoint), and credentials that can read/write to that bucket. Make sure your system clock is correct (NTP enabled), because backups and retention policies rely on timestamps. This guide uses a systemd-based distro such as Ubuntu Server, Debian, Fedora, or Rocky Linux.

Step 1: Install Restic

On many distributions, Restic is available in the default repositories. On Ubuntu/Debian you can install it with:

sudo apt update && sudo apt install -y restic

On Fedora/RHEL-based systems:

sudo dnf install -y restic

Verify the installation:

restic version

Step 2: Create an S3 Bucket and Credentials

Create an S3 bucket dedicated to backups, ideally in a region close to your server. Then create an IAM user (or service account) with permissions limited to that bucket. For security, avoid using broad admin keys. At minimum, the credentials must allow listing the bucket and reading/writing objects inside it.

If you are using an S3-compatible provider, note the endpoint URL (for example: https://s3.us-west-000.backblazeb2.com or your own MinIO endpoint). Restic can use standard AWS environment variables and an optional endpoint override.

Step 3: Set Environment Variables Securely

Restic reads S3 credentials from environment variables. Create a root-only file to store them so they are not exposed in shell history:

sudo nano /etc/restic/env

Add the following (adjust values for your environment):

export AWS_ACCESS_KEY_ID="YOUR_ACCESS_KEY"
export AWS_SECRET_ACCESS_KEY="YOUR_SECRET_KEY"
export RESTIC_PASSWORD="USE_A_LONG_RANDOM_PASSPHRASE"
export RESTIC_REPOSITORY="s3:s3.amazonaws.com/your-bucket-name"

If you need a custom endpoint (S3-compatible storage), add:

export AWS_DEFAULT_REGION="us-east-1"
export RESTIC_REPOSITORY="s3:https://YOUR-ENDPOINT/your-bucket-name"

Lock down permissions:

sudo chmod 600 /etc/restic/env

Step 4: Initialize the Restic Repository

Load the environment file and initialize the repository:

source /etc/restic/env
restic init

Restic will create the repository structure in your bucket. If it says the repo already exists, you can proceed.

Step 5: Run Your First Incremental Backup

Choose what you want to back up. Common targets are /etc, application configuration, and data directories (for example, /var/www or /home). Run:

restic backup /etc /home

Restic backups are incremental by design. After the first run, subsequent backups only upload changed data blocks, which saves bandwidth and storage.

Step 6: Verify and Test Restore (Don’t Skip This)

List available snapshots:

restic snapshots

Check repository integrity occasionally:

restic check

To restore, first create a test folder and restore the latest snapshot:

mkdir -p /tmp/restic-restore-test
restic restore latest --target /tmp/restic-restore-test

A backup that cannot be restored is not a backup. Testing restore early helps you catch permission issues, missing paths, or incorrect repository settings.

Step 7: Add Retention and Pruning

Without retention rules, backups grow forever. A practical policy for many servers is: keep 7 daily, 4 weekly, and 6 monthly snapshots. Run:

restic forget --keep-daily 7 --keep-weekly 4 --keep-monthly 6 --prune

Pruning removes unneeded data blocks. It can take time on large repositories, so schedule it during low usage.

Step 8: Automate Backups with systemd Timer

Create a script that loads the environment file and runs backup + retention. Create:

sudo nano /usr/local/sbin/restic-backup.sh

Example content:

#!/bin/bash
set -euo pipefail
source /etc/restic/env
restic backup /etc /home --exclude /home/*/.cache
restic forget --keep-daily 7 --keep-weekly 4 --keep-monthly 6 --prune

Make it executable:

sudo chmod 750 /usr/local/sbin/restic-backup.sh

Now create a systemd service:

sudo nano /etc/systemd/system/restic-backup.service

Use:

[Unit]
Description=Restic Backup to S3

[Service]
Type=oneshot
ExecStart=/usr/local/sbin/restic-backup.sh

Create a timer to run daily:

sudo nano /etc/systemd/system/restic-backup.timer

Use:

[Unit]
Description=Daily Restic Backup

[Timer]
OnCalendar=daily
Persistent=true

[Install]
WantedBy=timers.target

Enable and start:

sudo systemctl daemon-reload
sudo systemctl enable --now restic-backup.timer
systemctl list-timers | grep restic

Troubleshooting Tips

If you see access denied errors, confirm the bucket policy and IAM permissions, and double-check the repository URL. If backups are slow, test DNS and network throughput, and consider excluding large temporary folders. If you changed credentials, restart your shell or ensure the systemd service reads the correct environment (this guide sources /etc/restic/env directly in the script, which is straightforward and reliable).

Next Steps for Production Hardening

For production servers, consider adding alerting (email on failure via a monitoring tool), using a dedicated backup user, and enabling immutable storage features if your provider supports it. With Restic + S3, you get encrypted, incremental backups with clean automation—without relying on complex backup suites.

3.

Popular Posts

Install Ollama and Open WebUI on Ubuntu 24.04 with NVIDIA GPU Acceleration (Step-by-Step)

Install Ollama + Open WebUI on Ubuntu 24.04 with NVIDIA GPU Acceleration (Step-by-Step)

Install a Local AI Chatbot on Ubuntu 24.04 with Ollama and Open WebUI (Step-by-Step)

Trending Now

Recovering from Btrfs Boot Failures Using GUI Tools on Fedora

By the end of this guide the reader will be able to identify a Btrfs‑based Fedora installation, boot from a live USB, list and restore snapshots using the graphical utilities btrfs‑assistant and snapper, and verify that the system returns to a functional state without resorting to the command line. Understanding the Btrfs Layout Used by Fedora Fedora Workstation and Fedora KDE install the root filesystem as a single Btrfs partition that contains two default sub‑volumes. One sub‑volume holds the traditional “/” hierarchy, while the second is dedicated to /var/lib/machines . The latter exists to keep container images out of snapshot operations; it remains empty on systems that do not run virtual machines. Because Btrfs stores data in sub‑volumes rather than separate partitions, a snapshot captures the state of an entire sub‑volume at a point in time. The installer (Anaconda) automatically registers these sub‑volumes with the snapper service. Snapper maintains a series of read‑only ...