LINUX, FOSS AND LIBRARY TECHNOLOGY ENTHUSIAST

Wednesday, July 8, 2026

Getting Started with Restic: A Beginner's Guide to Secure Backups on Linux

0 comments
Data loss can happen at any time—hardware failures, accidental deletion, ransomware, or even a simple typo in the terminal. Having a reliable backup strategy is essential, and Restic is one of the best open-source backup tools available for Linux, macOS, Windows, and BSD systems.

Restic is fast, secure, cross-platform, and designed with encryption and deduplication built in. Whether you're backing up your laptop, a home server, or a production system, Restic provides an efficient and reliable solution.

In this guide, we'll learn how to install Restic, create a backup repository, back up files, view snapshots, and restore data.

Why Choose Restic?

Restic offers several powerful features:

  • End-to-end encryption using AES-256
  • Incremental backups that only store changed data
  • Deduplication to save storage space
  • Snapshot-based backups
  • Cross-platform support
  • Supports local disks, external drives, SSH, SFTP, cloud storage, Amazon S3, Backblaze B2, Google Cloud Storage, Azure Blob Storage, and more.

Install Restic

On Debian or Ubuntu:

sudo apt update
sudo apt install -y restic

Verify the installation:

restic version

Create Your First Backup Repository

A repository is where Restic stores all backup data.

Create one:

restic init -r /home/mahesh/backup-repository

During initialization, Restic asks for a password.

Choose a strong password and store it safely.

Important: If you lose the repository password, your backups cannot be decrypted or recovered.

Create Your First Backup

Suppose you want to back up the folder:

/home/mahesh/photos

Run:

restic -r /home/mahesh/backup-repository backup /home/mahesh/photos

Restic scans the folder and creates the first snapshot.


View Available Backups

List all snapshots:

restic -r /home/mahesh/backup-repository snapshots

Example:

ID        Time                 Host         Tags        Paths
---------------------------------------------------------------------------
09a474c5  2026-07-07 23:03:59  home-server              /home/mahesh/photos
---------------------------------------------------------------------------

Each backup is stored as a snapshot.


Incremental Backups

Run the backup command again:

restic -r /home/mahesh/backup-repository backup /home/mahesh/photos

View snapshots:

restic -r /home/mahesh/backup-repository snapshots

Example:

ID        Time                 Host         Tags        Paths
---------------------------------------------------------------------------
09a474c5  2026-07-07 23:03:59  home-server              /home/mahesh/photos
7730356c  2026-07-07 23:06:13  home-server              /home/mahesh/photos
---------------------------------------------------------------------------

Although two snapshots exist, Restic stores only changed data thanks to deduplication. This keeps backups fast and saves storage space.


Restore a Specific Snapshot

To restore an older backup, use its snapshot ID.

Example:

restic -r /home/mahesh/backup-repository restore 09a474c5 --target /home/mahesh/

This restores the exact state of your files from that snapshot.

Remove Old Backups

Over time, snapshots accumulate. Restic allows you to define retention policies.

Keep only the last seven snapshots:

restic -r /home/mahesh/backup-repository forget --keep-last 7 --prune

Keep backups from only the last 30 days:

restic -r /home/mahesh/backup-repository forget --keep-within 30d --prune

The --prune option removes unreferenced data and frees disk space.

Avoid Typing the Password Every Time

For automation, store the repository password in a file.

Create the configuration directory:

mkdir -p ~/.config/restic

Create the password file:

nano ~/.config/restic/password

Place only the repository password in the file.

Secure it:

chmod 600 ~/.config/restic/password

Verify permissions:

ls -l ~/.config/restic/password

You should see something similar to:

-rw------- 1 mahesh mahesh ...

Use the Password File

Backup:

restic -r /home/mahesh/backup-repository \
    --password-file ~/.config/restic/password \
    backup /home/mahesh/photos

List snapshots:

restic -r /home/mahesh/backup-repository \
    --password-file ~/.config/restic/password \
    snapshots

Restore the latest backup:

restic -r /home/mahesh/backup-repository \
    --password-file ~/.config/restic/password \
    restore latest --target /home/mahesh/

Initialize a new repository using the password file:

restic init \
    -r /home/mahesh/backup-repository \
    --password-file ~/.config/restic/password

Automate Daily Backups with Cron

Open your user's crontab:

crontab -e

Add the following line to run a backup every day at 2:00 AM:

0 2 * * * /usr/bin/restic -r /home/mahesh/backup-repository --password-file /home/mahesh/.config/restic/password backup /home/mahesh/photos

Your photos will now be backed up automatically every night.

Verify Repository Integrity

Occasionally verify that your repository is healthy:

restic -r /home/mahesh/backup-repository check

Using the password file:

restic -r /home/mahesh/backup-repository \
    --password-file ~/.config/restic/password \
    check

Show Repository Statistics

See how much storage is being used:

restic -r /home/mahesh/backup-repository stats

Common Restic Commands

Task Command
Initialize repository restic init -r REPOSITORY
Backup folder restic backup FOLDER
List snapshots restic snapshots
Restore latest backup restic restore latest --target DIRECTORY
Restore specific snapshot restic restore SNAPSHOT_ID --target DIRECTORY
Check repository integrity restic check
Show repository statistics restic stats
Keep last 7 backups restic forget --keep-last 7 --prune
Keep backups from the last 30 days restic forget --keep-within 30d --prune

Reference:


No comments:

Post a Comment