How to Set Up Incremental Backups with Restic and S3-Compatible Storage (Fast, Encrypted, and Automated)

Modern backups are not just about copying files to an external disk. If you manage a Linux server, a development workstation, or even a home lab, you need backups that are incremental, encrypted, and easy to restore. In this tutorial, you’ll configure restic (a fast, deduplicating backup tool) to send backups to S3-compatible object storage such as MinIO, Backblaze B2 (S3 API), Wasabi, or an on-prem S3 gateway. The result is a secure backup setup that scales well and can be automated with systemd.

Why restic + S3 is a strong backup combo

Restic is popular because it encrypts data before it leaves your machine, stores only changed blocks (deduplication), and keeps snapshots you can browse and restore from. Pairing it with S3-compatible storage makes your backups resilient: object storage is designed for durability, and you can back up over the network without mounting remote filesystems.

Prerequisites

You’ll need a Linux machine (Debian/Ubuntu/Fedora/AlmaLinux all work), an S3 endpoint (cloud or self-hosted), and credentials (access key and secret key). Make sure the target bucket exists or that your provider allows creating it via API. Also decide what to back up: typical choices are /etc, application configs, and data directories like /srv or /var/lib (be careful with databases; see notes below).

Step 1: Install restic

On Ubuntu/Debian:

sudo apt update && sudo apt install -y restic

On Fedora:

sudo dnf install -y restic

Verify:

restic version

Step 2: Export S3 credentials securely

Restic uses environment variables for S3 credentials. For a quick test in your current shell:

export AWS_ACCESS_KEY_ID="YOUR_ACCESS_KEY"

export AWS_SECRET_ACCESS_KEY="YOUR_SECRET_KEY"

If you’re using a non-AWS endpoint (MinIO, Wasabi, etc.), also set a custom endpoint URL:

export AWS_DEFAULT_REGION="us-east-1"

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

For AWS S3, your repository might look like:

export RESTIC_REPOSITORY="s3:s3.amazonaws.com/my-restic-bucket"

Step 3: Initialize the backup repository

Initialize once per repository. Restic will prompt for a repository password (this is used for encryption):

restic init

Store this password carefully. If you lose it, you cannot decrypt your backups.

Step 4: Run your first incremental backup

Start with a small but meaningful set of paths. Example:

restic backup /etc /home --exclude /home/*/.cache

Run the same command again later and you’ll get an incremental snapshot: restic will upload only what changed. To see what was saved:

restic snapshots

To verify repository integrity (recommended after initial setup):

restic check

Step 5: Create a smart retention policy (forget + prune)

Backups are only useful if they don’t grow forever. Restic can enforce retention rules and remove unneeded data. A common policy is: keep daily backups for 7 days, weekly for 4 weeks, and monthly for 12 months:

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

The --prune flag actually removes unreferenced data, reclaiming space in the S3 bucket.

Step 6: Automate backups with systemd (service + timer)

For reliable automation, use a systemd timer instead of cron. Create an environment file that root can read, for example:

sudo nano /etc/restic.env

Add:

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=YOUR_STRONG_REPO_PASSWORD

Now create the service unit:

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

Example content:

[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

Create the timer:

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

Example content:

[Unit]
Description=Run Restic Backup Daily

[Timer]
OnCalendar=daily
Persistent=true

[Install]
WantedBy=timers.target

Enable and start:

sudo systemctl daemon-reload

sudo systemctl enable --now restic-backup.timer

Check status and logs:

systemctl list-timers | grep restic

journalctl -u restic-backup.service -e

Step 7: Test a restore (don’t skip this)

A backup you haven’t restored from is just a hope. List snapshots, pick one, then restore to a temporary directory:

restic snapshots

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

To restore a single file or folder, you can use restic dump or browse snapshots with restic ls to find the path.

Practical notes for servers and databases

If you back up database files directly (like PostgreSQL under /var/lib/postgresql), you risk capturing inconsistent data. Prefer application-aware backups: use pg_dump for PostgreSQL, mysqldump for MySQL/MariaDB, or filesystem snapshots (LVM/ZFS) followed by restic. Also exclude large volatile paths such as caches, build folders, and container image layers unless you truly need them.

Conclusion

With restic and S3-compatible storage, you get fast incremental backups, strong encryption, simple retention rules, and clean automation through systemd timers. Once you’ve tested restores and verified the schedule, you’ll have a backup system that behaves like a reliable utility: quiet when it works, loud when it fails, and easy to trust when disaster strikes.

Set Up Incremental Backups on Linux with Restic and S3-Compatible Storage (Rclone + Encryption)

Why Restic + S3 Is a Smart Backup Combo

If you want a modern Linux backup solution that is fast, encrypted by default, and easy to automate, restic is one of the best tools available today. It creates deduplicated, incremental snapshots, so repeated backups are much smaller than full copies. Pairing restic with an S3-compatible object storage (such as MinIO, Backblaze B2 S3, Wasabi, or a private S3 gateway) gives you reliable offsite storage without managing a traditional backup server.

In this tutorial, you will set up restic on Linux, connect it to an S3-compatible destination using environment variables, run your first backup, verify it, and schedule it with systemd. The steps are designed to be practical for a workstation or a small server.

Prerequisites

You will need: a Linux machine (Ubuntu/Debian/RHEL-based are fine), access keys for an S3-compatible bucket, outbound internet access (or network access to your S3 endpoint), and a user account with permission to read the folders you plan to back up. Choose a directory to store your restic password securely (or use a password manager and a root-only file).

Step 1: Install Restic (and Rclone if Needed)

On Ubuntu/Debian, install restic with:

sudo apt update && sudo apt install -y restic

On RHEL/CentOS/Fedora, you can use your distribution repositories or install a package from your vendor. If you prefer a consistent version everywhere, you can also download the official restic release binary from the project site and place it in /usr/local/bin.

Restic can speak to S3 directly, so rclone is optional. However, rclone is useful if you want a single configuration tool for many cloud backends or if your environment already relies on it. If you want it:

sudo apt install -y rclone

Step 2: Create Your Bucket and Gather S3 Settings

Create a bucket in your S3-compatible storage, for example my-linux-backups. Collect these values: Access Key, Secret Key, Bucket name, Region (if required), and the S3 endpoint URL. For AWS S3, the endpoint is usually implicit; for MinIO or other providers, you will typically use something like https://s3.example.com.

Step 3: Set Restic Environment Variables

Restic reads credentials from environment variables. Create a root-only file to store them. This approach avoids leaving secrets in shell history and makes automation easier.

Create /etc/restic/env:

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

Add the following (adjust values to your provider):

export RESTIC_REPOSITORY="s3:https://s3.example.com/my-linux-backups"
export AWS_ACCESS_KEY_ID="YOUR_ACCESS_KEY"
export AWS_SECRET_ACCESS_KEY="YOUR_SECRET_KEY"
export AWS_DEFAULT_REGION="us-east-1"

Now create a password file for the repository encryption key:

sudo nano /etc/restic/password

Put a long passphrase on a single line, then lock down permissions:

sudo chmod 600 /etc/restic/env /etc/restic/password

Step 4: Initialize the Restic Repository

Load the environment variables and initialize the repo:

source /etc/restic/env
sudo RESTIC_PASSWORD_FILE=/etc/restic/password restic init

If everything is correct, restic will create the repository structure in the bucket and confirm initialization. If you see endpoint or TLS errors, double-check the endpoint URL and whether your provider requires a specific region.

Step 5: Run Your First Backup (Incremental by Default)

Choose what to back up. A common starting point is /home plus important configuration under /etc. You should exclude cache folders and other noise to keep snapshots clean.

Create an exclude file:

sudo nano /etc/restic/excludes

Example excludes:

*/.cache
*/Downloads
/var/tmp
/tmp

Run the backup:

source /etc/restic/env
sudo RESTIC_PASSWORD_FILE=/etc/restic/password restic backup /home /etc --exclude-file=/etc/restic/excludes

The next time you run the same command, restic will automatically create an incremental snapshot and upload only new or changed data blocks. This is where deduplication saves both time and storage.

Step 6: Verify and Test a Restore

A backup you never tested is not a strategy. List snapshots:

source /etc/restic/env
sudo RESTIC_PASSWORD_FILE=/etc/restic/password restic snapshots

Check repository consistency (run occasionally, not every hour):

sudo RESTIC_PASSWORD_FILE=/etc/restic/password restic check

To restore a single file safely, restore into a temporary directory first:

sudo mkdir -p /restore-test
sudo RESTIC_PASSWORD_FILE=/etc/restic/password restic restore latest --target /restore-test --include /etc/hosts

Confirm the file is correct, then copy it to the desired location if needed.

Step 7: Set a Retention Policy (Forget + Prune)

Backups grow over time unless you define retention. A practical policy keeps daily snapshots for a week, weekly for a month, and monthly for a year:

source /etc/restic/env
sudo RESTIC_PASSWORD_FILE=/etc/restic/password restic forget --keep-daily 7 --keep-weekly 4 --keep-monthly 12 --prune

The --prune step removes unneeded data blocks so your S3 storage usage stays under control.

Step 8: Automate Backups with systemd

Create a simple script so the job is repeatable. Create /usr/local/sbin/restic-backup.sh:

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

Add:

#!/bin/sh
set -eu
. /etc/restic/env
export RESTIC_PASSWORD_FILE=/etc/restic/password
restic backup /home /etc --exclude-file=/etc/restic/excludes
restic forget --keep-daily 7 --keep-weekly 4 --keep-monthly 12 --prune

Make it executable:

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

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

[Unit]
Description=Restic Backup

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

And a timer /etc/systemd/system/restic-backup.timer to run daily:

[Unit]
Description=Daily Restic Backup

[Timer]
OnCalendar=daily
Persistent=true

[Install]
WantedBy=timers.target

Enable the timer:

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

You can confirm runs with:

systemctl list-timers --all | grep restic

Final Tips for Reliable Offsite Backups

Keep your restic password file protected, and consider storing a sealed copy in a secure vault so you are not locked out during an emergency. If you are backing up a server with databases, add application-aware steps (such as dumping PostgreSQL or MySQL) before running restic. Most importantly, schedule a recurring restore test so you know the entire chain works—from Linux to S3 and back.

How to Back Up Linux Servers to Backblaze B2 with Restic and Rclone (Encrypted, Automated, Pruned)

Summary: This guide shows how to back up a Linux server to Backblaze B2 using Restic with Rclone as the transport. You will set up encryption, implement a retention policy, automate runs with systemd timers, and test restores. The result is a fast, encrypted, and low-cost off-site backup that you control.

Why Restic + Rclone + Backblaze B2?

Restic is a modern, deduplicating backup tool with built-in encryption. Rclone provides wide storage compatibility and reliable transfers. Backblaze B2 offers affordable object storage with per-GB pricing. Together, they form a portable, verifiable, and cost-effective backup solution that works on any Linux distribution.

Prerequisites

- A Linux server (Ubuntu/Debian/RHEL/AlmaLinux, etc.) with sudo/root access
- Backblaze B2 account
- Basic terminal familiarity

Step 1: Create a B2 Bucket and Key

1) In Backblaze, create a bucket (e.g., mycompany-backups). Leave it private.
2) Create an Application Key restricted to that bucket. Copy the KeyID and Application Key now; you will not see the secret again.

Step 2: Install Restic and Rclone

sudo apt update && sudo apt install -y restic rclone

On RHEL/Fedora-based systems:
sudo dnf install -y restic rclone

Step 3: Configure Rclone for B2

We will keep Rclone’s config out of your home directory for clarity.

sudo mkdir -p /etc/rclone
sudo chmod 750 /etc/rclone

sudo rclone config create b2 b2 account <KeyID> key <ApplicationKey> hard_delete true --config /etc/rclone/rclone.conf

Verify the config:

sudo rclone lsd b2: --config /etc/rclone/rclone.conf

Step 4: Initialize the Restic Repository (via Rclone)

Create a password file and initialize the repository path inside the bucket.

sudo mkdir -p /etc/restic
echo "choose-a-strong-long-passphrase" | sudo tee /etc/restic/password > /dev/null
sudo chmod 600 /etc/restic/password

Initialize:

sudo env RCLONE_CONFIG=/etc/rclone/rclone.conf restic -r rclone:b2:mycompany-backups/restic --password-file /etc/restic/password init

Step 5: Exclusions and Environment File

Define what not to back up (caches, runtime, VM disks, etc.).

sudo tee /etc/restic/excludes.txt > /dev/null <<'EOF'
/proc/**
/sys/**
/dev/**
/run/**
/tmp/**
/var/tmp/**
/var/cache/**
*.iso
*.img
*.qcow2
EOF

Create an environment file to avoid repeating flags:

sudo tee /etc/restic/restic.env > /dev/null <<'EOF'
RESTIC_REPOSITORY=rclone:b2:mycompany-backups/restic
RESTIC_PASSWORD_FILE=/etc/restic/password
RCLONE_CONFIG=/etc/rclone/rclone.conf
RESTIC_CACHE_DIR=/var/cache/restic
EOF
sudo mkdir -p /var/cache/restic && sudo chown root:root /var/cache/restic && sudo chmod 700 /var/cache/restic

Step 6: Create a Backup Script

This script performs a backup, applies retention, and verifies the repository.

sudo tee /usr/local/bin/restic-backup.sh > /dev/null <<'EOF'
#!/usr/bin/env bash
set -euo pipefail

# Sources to back up (adjust to your server)
SOURCES=(/etc /home /var/www)

# Nice/ionice to reduce system impact
nice -n 10 ionice -c2 -n7 \

env $(grep -v '^\s*#' /etc/restic/restic.env | xargs) \\
restic backup "${SOURCES[@]}" --exclude-file /etc/restic/excludes.txt --tag scheduled --one-file-system

# Retention policy: keep last 7 daily, 4 weekly, 6 monthly
env $(grep -v '^\s*#' /etc/restic/restic.env | xargs) \\
restic forget --prune --keep-daily 7 --keep-weekly 4 --keep-monthly 6 --tag scheduled

# Optional consistency check (weekly via timer, or keep here for every run)
env $(grep -v '^\s*#' /etc/restic/restic.env | xargs) restic check --read-data-subset=1/20 || true
EOF
sudo chmod 750 /usr/local/bin/restic-backup.sh

Step 7: systemd Service and Timer

Create a systemd unit to run the script, and a timer to schedule it daily.

sudo tee /etc/systemd/system/restic-backup.service > /dev/null <<'EOF'
[Unit]
Description=Restic backup to Backblaze B2 (via rclone)
After=network-online.target
Wants=network-online.target

[Service]
Type=oneshot
EnvironmentFile=/etc/restic/restic.env
ExecStart=/usr/local/bin/restic-backup.sh
Nice=10
IOSchedulingClass=best-effort
IOSchedulingPriority=7
PrivateTmp=yes
NoNewPrivileges=yes
ProtectSystem=full
ProtectHome=yes
ProtectKernelLogs=yes
ProtectKernelModules=yes
ProtectKernelTunables=yes
LockPersonality=yes
MemoryDenyWriteExecute=yes

[Install]
WantedBy=multi-user.target
EOF

sudo tee /etc/systemd/system/restic-backup.timer > /dev/null <<'EOF'
[Unit]
Description=Daily Restic backup timer

[Timer]
OnCalendar=03:15
RandomizedDelaySec=20m
Persistent=true

[Install]
WantedBy=timers.target
EOF

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

Step 8: First Run and Verification

Trigger a manual run and watch the output:

sudo systemctl start restic-backup.service
sudo journalctl -u restic-backup.service -n 200 -f

List snapshots to confirm:

sudo env $(grep -v '^\s*#' /etc/restic/restic.env | xargs) restic snapshots

Step 9: Tune Retention and Costs

Adjust the restic forget policy to meet recovery objectives and budget. More aggressive pruning reduces storage but limits historical versions. Backblaze B2 costs depend on stored GB, transaction counts, and egress; deduplication in Restic helps keep usage low.

Step 10: Test a Restore

Never trust backups you have not restored. Create a temporary restore folder and recover a small file.

sudo mkdir -p /tmp/restore-test
sudo env $(grep -v '^\s*#' /etc/restic/restic.env | xargs) restic restore latest --target /tmp/restore-test --include /etc/hostname
ls -l /tmp/restore-test/etc/hostname

Security Best Practices

- Use a long, unique Restic password stored in a root-only file.
- Restrict the Backblaze Application Key to one bucket with minimal permissions.
- Enable MFA on your Backblaze account.
- Keep /etc/rclone/rclone.conf and /etc/restic/password mode 600 and owned by root.
- Consider server-side encryption on B2 as a secondary layer if required by policy, although Restic already encrypts data client-side.

Performance Tips

- Parallel uploads: Restic auto-tunes, but you can increase concurrency on bigger servers via RESTIC_OPTIONS like --jobs 4 for backups or use Rclone env vars (RCLONE_B2_UPLOAD_CONCURRENCY).
- Bandwidth limits: Add --limit-upload 4MiB to Restic, or --bwlimit via Rclone if needed.
- Exclude large/ephemeral paths to reduce churn.

Troubleshooting

Fatal: wrong password or no key found: The password in /etc/restic/password does not match the repository. Fix the password file or re-init a new repo.

Repository locked: A previous run crashed. Remove stale locks only when you are certain no job is running:
sudo env $(grep -v '^\s*#' /etc/restic/restic.env | xargs) restic unlock

Slow uploads or timeouts: Check outbound bandwidth, raise concurrency, and ensure your firewall allows long-lived HTTPS connections. Try adding a randomized delay (already in the timer) to avoid contention on shared links.

What You Achieved

You now have an automated, encrypted, off-site backup pipeline for Linux using Restic, Rclone, and Backblaze B2. Snapshots are deduplicated, retention is enforced, and restores are provable. Regularly verify snapshots, monitor storage usage, and adjust policies as your data grows.

How to Back Up to Backblaze B2 with Restic: Installation, Automation, and Pruning (Linux and Windows)

Overview

Backups should be encrypted, efficient, and easy to automate. Restic meets all three goals: it is a fast, deduplicating, and end‑to‑end encrypted backup tool that works on Linux, Windows, and macOS. In this guide, you will learn how to back up files to Backblaze B2, schedule automatic runs, set a sensible retention policy, and verify your data. The steps cover both Linux and Windows with actionable commands and clear defaults you can copy and adapt.

Why Restic + Backblaze B2

Restic encrypts everything (including filenames) before it leaves your machine. It also deduplicates data, so repeating backups are small and fast. Backblaze B2 is affordable object storage with predictable pricing and a robust API that restic supports natively. The combination gives you offsite, encrypted, incremental backups you can restore from any machine.

Prerequisites

You need a Backblaze B2 account, a bucket created for backups, and an Application Key with permissions limited to that bucket (read, write, list, delete). Note the Key ID and Key. Decide on a repository path such as b2:my-backups:laptop01 so multiple devices can share one bucket cleanly.

Step 1 — Install Restic

Linux (Debian/Ubuntu): sudo apt update && sudo apt install restic. On other distributions, use your package manager or the official binary release. Verify with restic version.

Windows 10/11: Install via Winget: winget install restic.restic. Or via Chocolatey: choco install restic. Verify with restic version in PowerShell.

Step 2 — Configure Environment and Initialize the Repository

Linux: Export the following environment variables in your shell or place them into a root‑readable file such as /etc/restic/env and source it in your scripts.

export B2_ACCOUNT_ID="YOUR_KEY_ID"
export B2_ACCOUNT_KEY="YOUR_APP_KEY"
export RESTIC_REPOSITORY="b2:my-backups:laptop01"
export RESTIC_PASSWORD_FILE="/etc/restic/pass"

Create the password file with strong permissions and a long random passphrase: sudo install -m 600 /dev/null /etc/restic/pass then sudo sh -c 'openssl rand -base64 48 > /etc/restic/pass'. Initialize the repository: restic init. If successful, you will see “created restic repository.”

Windows: In PowerShell, create C:\restic\env.ps1 with:
$env:B2_ACCOUNT_ID="YOUR_KEY_ID"
$env:B2_ACCOUNT_KEY="YOUR_APP_KEY"
$env:RESTIC_REPOSITORY="b2:my-backups:laptop01"
$env:RESTIC_PASSWORD_FILE="C:\restic\pass.txt"

Generate a passphrase: New-Guid | Out-File C:\restic\pass.txt -Encoding ascii (or choose your own). Then run: powershell -ExecutionPolicy Bypass -File C:\restic\env.ps1; restic init.

Step 3 — Choose What to Back Up and What to Skip

Create an exclude file to avoid caches, temp folders, and large throwaway data. Examples:

# Linux excludes
/proc
/sys
/dev
/tmp
/var/tmp
/var/cache
*.ISO

# Windows excludes
C:\Windows\Temp
C:\Users\*\AppData\Local\Temp
*.iso
*.vhdx

Step 4 — Run Your First Backup

Linux: sudo --preserve-env=B2_ACCOUNT_ID,B2_ACCOUNT_KEY,RESTIC_REPOSITORY,RESTIC_PASSWORD_FILE restic backup /home /etc --exclude-file /etc/restic/excludes --tag baseline. List snapshots with restic snapshots. Sanity‑check data with restic check --read-data-subset=10%.

Windows: Open PowerShell as Administrator, then: powershell -ExecutionPolicy Bypass -File C:\restic\env.ps1; restic backup "C:\Users" "D:\Data" --exclude-file "C:\restic\excludes.txt" --tag baseline. View snapshots with restic snapshots.

Step 5 — Automate Daily Backups (Linux via systemd)

Store environment variables in /etc/restic/env and your excludes in /etc/restic/excludes. Create a systemd service /etc/systemd/system/restic-backup.service with:
[Unit]
Description=Restic backup to B2

[Service]
Type=oneshot
EnvironmentFile=/etc/restic/env
ExecStart=/usr/bin/restic backup /home /etc --exclude-file /etc/restic/excludes --tag daily
Nice=10
IOSchedulingClass=best-effort

Create the timer /etc/systemd/system/restic-backup.timer:
[Unit]
Description=Daily Restic backup

[Timer]
OnCalendar=daily
Persistent=true
RandomizedDelaySec=10m

[Install]
WantedBy=timers.target

Enable and start: sudo systemctl daemon-reload && sudo systemctl enable --now restic-backup.timer.

Step 6 — Retention and Pruning

Keep what you need and trim the rest. A good starting policy keeps a week of daily points, a month of weekly points, and a year of monthly points. Run weekly: restic forget --prune --keep-daily 7 --keep-weekly 4 --keep-monthly 12 --keep-yearly 3. Add this to a separate systemd timer (e.g., restic-prune.timer) or include it after the daily backup on Sundays.

To reduce API load and speed up operations on B2, consider limiting parallel connections when pruning: restic -o b2.connections=8 forget --prune .... You can also set a cache directory to speed up metadata operations: export RESTIC_CACHE_DIR=/var/cache/restic (ensure it’s persistent and has room).

Step 7 — Automate on Windows (Task Scheduler)

Create C:\restic\backup.ps1 with:
. C:\restic\env.ps1
restic backup "C:\Users" "D:\Data" --exclude-file "C:\restic\excludes.txt" --tag daily
restic forget --prune --keep-daily 7 --keep-weekly 4 --keep-monthly 12

Then open Task Scheduler → Create Task → General: Run whether user is logged on or not, run with highest privileges. Triggers: Daily at a quiet hour. Actions: Start a Program → Program/script: powershell → Arguments: -ExecutionPolicy Bypass -File C:\restic\backup.ps1 → Start in: C:\restic.

Step 8 — Restores You Can Trust

List snapshots and pick a point in time: restic snapshots. Restore everything to a safe directory: restic restore latest --target /tmp/restore. Restore only a folder: restic restore latest --target /tmp/restore --include "/home/alex/Documents". On Windows, run the same commands in PowerShell with paths like "C:\Users\Alex\Documents". For browsing, Linux supports FUSE: restic mount /mnt/restic (unmount with fusermount -u /mnt/restic).

Security and Cost Tips

Protect your password file and environment files with strict permissions; never hardcode keys in scripts. Use a bucket‑scoped Application Key limited to your backup bucket. Tag backups (e.g., --tag daily, --tag before-upgrade) to make pruning and auditing easier. Keep your monthly bill predictable by excluding caches and VM images that change often, and by using a sensible retention policy.

Troubleshooting

If you see transient B2 errors (429/503), restic will retry; adding -o b2.connections=4 can help. For permission errors, confirm that your Application Key has delete permissions (needed for pruning). If backups seem slow, verify your excludes and consider running restic check --with-cache during off‑hours. Always test a small restore before you need a big one.

What You Achieved

You now have encrypted, offsite, incremental backups to Backblaze B2 with restic, running on a schedule, pruned to a clear retention policy, and verified for integrity. Keep the password safe, periodically test restores, and you will be ready when hardware fails or ransomware strikes.

Ransomware‑Resilient Backups on Linux with Restic and Backblaze B2 Object Lock

Overview

If you need cloud backups that ransomware cannot silently erase, combine Restic with Backblaze B2 buckets that have Object Lock enabled. Restic gives fast, deduplicated encrypted backups, while B2 Object Lock makes every uploaded backup file immutable for a time you choose. This guide shows how to set up the entire pipeline on Linux, from creating an Object Lock bucket to scheduling backups and verifying restores.

What You Need

- A Linux machine with shell access (Ubuntu/Debian/RHEL/AlmaLinux etc.)

- A Backblaze B2 account

- Restic 0.12 or newer (most modern distros provide it)

- Basic understanding of environment variables and systemd (for scheduling)

Step 1 — Create a Backblaze B2 Bucket with Object Lock

1) Sign in to the Backblaze B2 web console and create a new bucket. Choose a unique name, keep it Private, and enable Object Lock during creation. You cannot turn this on later for an existing bucket.

2) In the bucket settings, set a Default Bucket Retention under Object Lock. A common starting point is Governance mode with a retention of 30 days. This applies immutability automatically to all new objects (Restic pack files), blocking deletion or modification until retention expires.

3) Optional: configure lifecycle rules for versioning if you store non-Restic data in the same bucket. For a pure Restic repository, the default retention plus Restic’s own forget/prune policy is usually enough.

Step 2 — Generate a Restricted Application Key

Create a new application key limited to your bucket. In Backblaze, go to App Keys, click Add a New Application Key, restrict it to the bucket you created, and copy the KeyID and Application Key. Treat these like passwords.

Step 3 — Install Restic

On Ubuntu/Debian, run: sudo apt update && sudo apt install restic. On RHEL/AlmaLinux/Rocky, use: sudo dnf install restic. If your distro is outdated, download the latest static binary from Restic’s releases page and place it in /usr/local/bin with executable permissions.

Step 4 — Export Environment Variables

Set environment variables so Restic knows how to reach B2 and encrypt your repository:

export RESTIC_REPOSITORY=b2:your-bucket-name:restic-repo

export B2_ACCOUNT_ID=your-key-id

export B2_ACCOUNT_KEY=your-application-key

export RESTIC_PASSWORD=strong-passphrase (or use RESTIC_PASSWORD_FILE to read it from a file)

Tip: store these in a root-only file such as /root/.restic-env, then source it: set -a; . /root/.restic-env; set +a.

Step 5 — Initialize the Repository

Create the Restic repository in your B2 bucket: restic init. You should see “created restic repository.” From now on, all data is encrypted client-side and written as immutable objects (because the bucket has Object Lock with default retention).

Step 6 — Run Your First Backup

Start with a focused scope. For example: restic backup /etc /home /var/www --exclude "*/node_modules/*" --tag initial. Restic deduplicates files automatically and shows a summary when done. Use tags like --tag server01 to identify hosts or workloads.

Step 7 — Set a Retention Policy (Forget + Prune)

Tell Restic how many restore points to keep. A common policy is: restic forget --keep-daily 7 --keep-weekly 4 --keep-monthly 6 --prune. Note: pruning cannot remove pack files that are still under Object Lock. That is expected. Deletion will occur automatically once retention expires and the data is no longer referenced by any snapshot.

Step 8 — Schedule Automatic Backups with systemd

Create a service file, e.g. /etc/systemd/system/restic-backup.service with:

[Unit]
Description=Restic backup
Wants=network-online.target
After=network-online.target

[Service]
Type=oneshot
EnvironmentFile=/root/.restic-env
ExecStart=/usr/bin/restic backup /etc /home /var/www --exclude "*/node_modules/*" --tag daily
ExecStart=/usr/bin/restic forget --keep-daily 7 --keep-weekly 4 --keep-monthly 6 --prune

Add a timer in /etc/systemd/system/restic-backup.timer:

[Unit]
Description=Run Restic backup daily

[Timer]
OnCalendar=daily
Persistent=true

[Install]
WantedBy=timers.target

Enable with: sudo systemctl daemon-reload && sudo systemctl enable --now restic-backup.timer.

Step 9 — Test a Restore

List snapshots: restic snapshots. Restore the latest to a safe directory: restic restore latest --target /tmp/restore. To restore a single path, add --include "/etc" or --include "/home/user/Documents". Verify that the restored files open normally.

Security and Cost Tips

- Use RESTIC_PASSWORD_FILE with a root-only file and consider storing it via a secrets manager or an encrypted password store.

- Restrict your B2 application key to the single bucket and avoid account-wide keys.

- Monitor storage growth. Deduplication helps, but backups expand over time. Object Lock increases short-term storage because data cannot be deleted until retention ends.

Troubleshooting

- Permission errors (403): verify the KeyID/key, bucket restriction, and that Object Lock is enabled.

- Time sync issues: B2 rejects requests if the server time is off. Ensure NTP is running (systemd-timesyncd or chrony).

- Prune failures: if objects are still under retention, pruning cannot delete them. This is normal. They will be removed automatically once retention expires and no snapshots reference them.

You’re Done

You now have a backup strategy that is fast, encrypted, deduplicated, and resilient to ransomware. Restic handles the heavy lifting, while Backblaze B2 Object Lock prevents attackers or accidents from wiping out recent restore points. Periodically test restores and review your retention window to balance recoverability and storage costs.

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 ...