Backups are essential for ensuring data security. In this guide, I will walk you through setting up Restic, a fast and secure backup tool, to work with Wasabi S3-compatible storage on Debian 12 Bullseye.

This tutorial uses the Wasabi region Osaka (ap-northeast-2) and a bucket named bucket-osaka-sandbox.

We will organize backups using subdirectories and tags for each virtual machine.

Step 1.1 : Install Restic

First, install Restic using the package manager.

Verify the installation:

Step 1.2 : Install AWS CLI

Next, install AWS CLI using the package manager.

Setup the access key and secret key using value from Wasabi:

Step 2: Set Up Environment Files

Create a directory to store Restic configuration files:

2.1 Create the .restic-env File

This file stores environment variables for Restic. Use the following template:

Add the following content:

Replace your_wasabi_access_key and your_wasabi_secret_key with your Wasabi credentials.

Secure the file:

2.2 Create the .restic-password File

This file stores the encryption password for your backups.

Add a strong password:

Secure the file:

Step 3: Create the Restic Script

Next, create a bash script to handle Restic operations.

Add the following content:

Make the script executable:

Step 4: Initialize the Restic Repository

Run the script to initialize the repository.

Uncomment the Init repository line in the script (Option 1) and re-run the script to initialize:

Step 5: Perform a Backup

To perform a backup, ensure the Backup section (Option 2) in the script is uncommented, then execute:

The backup will store data from /var/app to s3://bucket-osaka-sandbox/vm-osaka-1 with the tag vm-osaka-1.

Step 6: List Snapshots

To list snapshots, uncomment the List snapshots line (Option 3) and run the script:

Step 7: Perform Housekeeping

Housekeeping removes old backups and optimizes the repository. Uncomment the Housekeeping line (Option 4) and run the script:

This setup keeps:

  • Last 7 snapshots
  • 7 daily snapshots
  • 4 weekly snapshots
  • 6 monthly snapshots

Step 8: Automate Backups with Systemd

To schedule backups, create a systemd service and timer.

Create the Systemd Service

Add the following:

Create the Systemd Timer

Add the following:

Enable and start the timer:

Summary

With this setup, Restic will securely back up your files to Wasabi S3 storage. The use of subdirectories and tags makes it easy to manage backups for multiple virtual machines.

Automating the process with systemd ensures your data remains secure with minimal effort.

Leave A Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.