JRehkemper.de

Restic OpenSource Backup-Tool for Linux and Windows

Restic is a backup-tool written in Go and compatible with Windows and Linux.
From a user-standpoint it is kind of similar to Borg-Backup, with some differences, for e.g. that a repository can be shared with multiple hosts for better compression and deduplication. And since it is written in Go it is faster than Borg which uses Python.

Installation

There are a few ways to install restic.

On Fedora you could install it with dnf but the packages is a few versions behind the upstream.
Normally this wouldn’t be an issue, but since the Repository-Format changed in v0.14 you should look for newer versions.

It is also available over flatpak but in an older version as well.

My preferred method is downloading the binary from GitHub and placing it in /usr/local/bin. Since I don’t want to specify the version while calling the binary, I will add a link restic -> restic-v0.16.4.

Usage

All commands will work the same on windows and linux. You only need to adjust the path format. For Example /mnt/restic or D:\Restic.

Initialize Repository

First we need to create/initialize a repository to save the backups in.
You can use multiple backends to store repositories but I will focus on local folders (which includes mounted nfs and smb shares) and sftp/ssh.

# local
restic -r /path/to/repo init

# sftp
restic -r sftp:user@host:/path/to/repo init

If your SFTP server is running on a different port you can either specify the port

sftp://user@host:port//path/to/repo

or create a entry in your ~/.ssh/config

Host backuphost
	User restic
	Port 2222

and than use the server as if it would use the default port.

restic -r sftp:backuphost:/path/to/repo init

While creating the Repository it will ask you for a password which is the only way to access your backups. Keep it Safe!

Backup Data

Backing up data is fairly straight forward as well.

This command will backup all home-directories to a local repository. If you are using a SFTP-Repository specify it after the -r-flag. Just as in the Repo-Initialization.

restic -r /path/to/repo backup /home

That’s it.

If you want to backup multiple directories you should use an include-list. That way all the directories get combined into a single snapshot which makes it easier to manage than running seperate jobs for each directory.

Simply create a text-file with one path per line. For Example this file called dir-list.txt:

/home
/root
/etc
/opt
/usr/local
/var

Than reference that file in your restic-command

restic -r /path/to/repo backup --files-from dir-list.txt

The first Backup will take quite long but every successive backup will use this existing snapshot to only read and save the delta, which is really fast even if you need to backup a few TB from a HDD.

Listing Backups

Every Backup is a Snapshot in restic terms. You can list them like so.

restic -r /path/to/repo snapshots

Clean Up Old Backups

Of course you want to delete some of the old backups after some time.
Restic uses the same approach as for e.g. the Proxmox-Backup-Server where you define it to keep the last-x.

A list with all parameters can be found here in the official documentation.
My usual cleanup looks like this.

restic -r /path/to/repo forget --keep-daily 7 --keep-weekly 4 --keep-monthly 6

This will keep on backup for every day in the last week. One for the last 4 weeks and one for the last 6 Months. This usually covers all my needs.

The forget command will only mark the chunk as unused. They are still stored. To finally delete them use prune

restic -r /path/to/repo prune

Using a password-file

If you want to create backups with a script without the password from stdin you can use a password-file which is a textfile containing just you password. Keep the permissions on that file to a minimum!

restic -r /path/to/repo -p /home/user/passwordfile

Restoring Backups

The easiest way is to restore the latest backup to a temporary location and then coping the files from there.

restic -r /path/to/repo restore latest --target /tmp/restic-restore

You can also specify a different snapshot

restic -r /path/to/repo restore 7896896 --target /tmp/restic-restore

To filter paths you can use --include /home/myfile and --exclude /home/myotherfile.

restic -r /path/to/repo restore latest --target /tmp/restic-restore --path /home/jannik/Desktop --include my-image.png

On Linux you can also mount a snapshot to browse it’s content and copy the desired files. This is not supported on Windows yet.

restic -r /path/to/repo mount /mnt/restic

Finding a file in a Backup

If you are searching for a specific file you can search for it.

restic -r /path/to/repo find myfile.txt

Stats of your Backup-Repo

If you want to get information like the size of your repo you can use the stats command.
It has multiple modes: restore-size will show how much space you would need to restore this snapshot. This is default mode.
raw-data shows how much space the backup takes up on our disk. This way you can see how much the compression and deduplication helped.

restic -r /path/to/repo stats --mode raw-data
Stats in raw-data mode:
     Snapshots processed:  8
        Total Blob Count:  690859
 Total Uncompressed Size:  40.142 GiB
              Total Size:  20.157 GiB
    Compression Progress:  100.00%
       Compression Ratio:  1.99x
Compression Space Saving:  49.79%
profile picture of the author

Jannik Rehkemper

I'm an professional Linux Administrator and Hobby Programmer. My training as an IT-Professional started in 2019 and ended in 2022. Since 2023 I'm working as an Linux Administrator.