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.

How to Set Up a Backup System on Windows Server Using PowerShell

Setting up a robust backup system is crucial for any organization to safeguard against data loss due to hardware failures, cyberattacks, or accidental deletions. In this tutorial, we'll explore how to configure a backup system on Windows Server using PowerShell, providing a step-by-step guide that system administrators can follow to ensure their data remains secure.

Requirements: Before we begin, ensure you have administrative access to a Windows Server (2012 or later) and have PowerShell installed. This tutorial assumes you are familiar with basic PowerShell commands and Windows Server management.

Step 1: Install Windows Server Backup Feature

First, we need to install the Windows Server Backup feature if it's not already installed. Open PowerShell as an administrator and run the following command:

Install-WindowsFeature -Name Windows-Server-Backup

This command installs the necessary features on your Windows Server to allow backups. You can confirm the installation by using the Get-WindowsFeature command.

Step 2: Configure Backup Using PowerShell

Once the backup feature is installed, you can configure your backup schedule and settings. Use the following PowerShell script to create a daily backup of the entire server:

$backupSchedule = New-WBPolicy
Add-WBVolume -Policy $backupSchedule -VolumePath "C:"
$backupTime = New-WBBackupTarget -NetworkPath "\\BackupServer\Backups"
Set-WBSchedule -Policy $backupSchedule -Schedule 02:00
Start-WBBackup -Policy $backupSchedule

This script sets up a new backup policy, adds the C: drive to the policy, specifies a network location for storing the backup, sets the backup to occur daily at 2 AM, and starts the backup operation.

Step 3: Monitoring and Managing Backups

Monitoring your backups is as important as setting them up. To check the status of your backups, use the following command:

Get-WBJob

This command provides information about the current status of backup jobs. For a more detailed view, you can access the Windows Server Backup feature in the Server Manager dashboard.

Managing your backups typically involves adjusting settings, pruning old backups, or recovering data. PowerShell offers a comprehensive suite of commands for backup management, such as Remove-WBBackupSet and Get-WBBackupSet, which help in maintaining the health and efficiency of your backup system.

By following these steps, you can establish a reliable backup system for your Windows Server using PowerShell, ensuring your data is protected and easily recoverable in the event of a disaster. Remember, regular testing of your backup and recovery process is essential to guarantee data integrity and availability.

3.

Automating Windows Server Tasks with PowerShell

Automating Windows Server Tasks with PowerShell

Managing a Windows Server manually can be time-consuming and error-prone. PowerShell offers a powerful way to automate repetitive tasks, ensuring efficiency and accuracy. In this guide, we will explore how to use PowerShell to automate key administrative functions on a Windows Server.

1. Why Use PowerShell for Automation?

PowerShell is a command-line scripting language developed by Microsoft. It allows administrators to control system settings, manage Active Directory, automate software deployment, and handle repetitive tasks with simple scripts.

2. Basic PowerShell Commands for Automation

Here are some essential PowerShell commands for automation:

  • Get-Service – Lists all services running on the server.
  • Restart-Service – Restarts a specific service.
  • Get-EventLog – Fetches logs for system monitoring.
  • New-ScheduledTask – Creates an automated task.

3. Automating a Task with PowerShell

To create an automated backup task, use the following script:

$BackupPath = "C:\Backup\"
$Date = Get-Date -Format "yyyy-MM-dd"
$BackupDestination = "$BackupPath\ServerBackup-$Date.zip"

Compress-Archive -Path "C:\ImportantData\" -DestinationPath $BackupDestination
Write-Output "Backup completed successfully at $BackupDestination"

This script creates a compressed backup of the "ImportantData" folder with a timestamped filename.

4. Scheduling the Script

You can schedule this script to run automatically using Task Scheduler:

  1. Open Task Scheduler and create a new task.
  2. Under the "Actions" tab, select "Start a program" and enter `powershell.exe`.
  3. In the "Add arguments" field, enter `-File C:\Scripts\backup.ps1`.
  4. Set the trigger to run the task daily at a specified time.

With this setup, your Windows Server will automatically back up critical data without manual intervention.

Conclusion

PowerShell is a game-changer for Windows Server automation. By leveraging its powerful scripting capabilities, administrators can streamline tasks, reduce errors, and enhance server efficiency. Start automating today and take your server management to the next level!

PowerShell


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