Skip to main content

Restic Commands

Restic & Autorestic Backup Management Guide

This guide provides step-by-step instructions for managing backups stored in Backblaze B2 using Restic and Autorestic. It covers how to check snapshots, delete snapshots, prune old backups, and other useful commands.

Docs: https://autorestic.vercel.app/


Install autorestic:

sudo wget -qO - https://raw.githubusercontent.com/cupcakearmy/autorestic/master/install.sh | bash

1. Checking Existing Snapshots

To list all snapshots stored in your Backblaze B2 repository, run:

restic -r b2:Macslodge:/docker-backups snapshots

Example Output:

ID        Time                 Host        Tags                                 Paths                                                  Size
--------------------------------------------------------------------------------------------------------------------------------------------------
80d2af5c  2025-03-11 12:44:05  mac-omen    ar:location:ansible_semaphore-mysql  /var/lib/docker/volumes/ansible_semaphore-mysql/_data  213.160 MiB
b7ca284a  2025-03-11 12:47:44  mac-omen    ar:location:ansible_semaphore-mysql  /var/lib/docker/volumes/ansible_semaphore-mysql/_data  213.160 MiB

šŸ“Œ Key Information:

  • ID is the unique snapshot identifier.
  • Time is when the snapshot was taken.
  • Paths show the data stored in the snapshot.

To check snapshots for a specific volume:

restic -r b2:Macslodge:/docker-backups snapshots --path /var/lib/docker/volumes/ansible_semaphore-mysql/_data

2. Deleting Snapshots

To delete a specific snapshot, use its ID:

restic -r b2:Macslodge:/docker-backups forget 80d2af5c

To delete multiple snapshots:

restic -r b2:Macslodge:/docker-backups forget b7ca284a 80d2af5c

šŸ“Œ Note: This removes the snapshot reference but does not free space immediately.


3. Pruning Old Backups to Free Space

After deleting snapshots, run:

restic -r b2:Macslodge:/docker-backups prune

šŸ“Œ This permanently removes unreferenced data, freeing storage space in Backblaze B2.

To check available space after pruning:

restic -r b2:Macslodge:/docker-backups stats

4. Automating Backup Cleanup (Retention Policy)

Instead of manually deleting snapshots, configure Autorestic to manage them automatically. In .autorestic.yml, add:

locations:
  ansible_semaphore-mysql:
    forget: prune
    options:
      forget:
        keep-daily: 7
        keep-weekly: 4
        keep-monthly: 12

Then enforce the retention policy with


5. Restoring Snapshots

autorestic restore [-l, --location] [--from backend] [--to <out dir>] [-f, --force] [snapshot]

This will restore the location to the selected target. If for one location there are more than one backends specified autorestic will take the first one. If no specific snapshot is specifiedĀ autoresticĀ will useĀ latest.

If you are sure you can pass theĀ -f, --forceĀ flag and the data will be overwritten in the destination. However note that this will overwrite all the data existent in the backup, not only the 1 file that is missing e.g.

Example

autorestic restore -l home --from hdd --to /path/where/to/restore

This will restore the locationĀ homeĀ to theĀ /path/where/to/restoreĀ folder and taking the data from the backendĀ hdd


6. Managing Repositories

Creating a New Repository

To initialize a new Restic repository in Backblaze B2:

restic -r b2:Macslodge:/docker-backups init

You will be prompted to set a repository password. Keep this password safe, as it is required for restoring data.


Deleting a Repository

To delete an entire repository and all backups:

Delete the repo manually is the easiest way

šŸ“Œ Warning: This permanently deletes all backups. Use with caution.


Editing a Repository (Changing Password)

To change the repository encryption password:

restic -r b2:Macslodge:/docker-backups change-password

7. Additional Useful Commands

Check Repository Integrity

restic -r b2:Macslodge:/docker-backups check

Verify Snapshot Integrity

restic -r b2:Macslodge:/docker-backups check --read-data

List Backup Statistics

restic -r b2:Macslodge:/docker-backups stats

Manually Run Backup

autorestic backup -a

Mount the backup as a Filesystem

Note: Mount on a directory the user owns, or you will have permission errors.

restic -r b2:Macslodge:/docker-backups mount /home/restic

Mount a specific snapshot

restic -r b2:Macslodge:/docker-backups /home/restic --snapshot <snapshot_id>

Unlock a repo

restic -r b2:Macslodge:/backups/apex unlock

Verify if an instance is running

Ā ps aux | grep autorestic

Ā