It is vital to have the latest backup copies of your files, tools, and configurations in case of error, system failure, or a cyber attack. Having a backup allows you to restore your system to your most recent state with minimal downtime.

This tutorial will show you how to install and use the Restic Backup Utility on your machine.

What is the Restic Backup Utility?

Restic is a simple, feature-rich backup utility written in the Go Programming language. Restic is a modern, secure, and cross-platform software, making it usable on most of the main operating systems. It offers features such as the ability to verify backups, automate the backup process, and more.

To learn more about Restic, check the resource provided below:

https://restic.net

How to Install Restic Backup Utility

Restic is available in major Linux distributions, and you can install it using simple commands using various package managers.

Debian/Ubuntu

To install on Debian and other Debian based distributions, use the apt command:

sudo apt-get install restic -y

Manjaro/Arch Linux

On Manjaro and Arch distros, use the pacman command:

CentOS/REHL

On the REHL family of distributions, you can use Copr repository or download the Restic binary.

Use wget to download the binary and move it to the bin directory:

[centos@centos8 ~]$ wget https://github.com/restic/restic/releases/download/v0.12.0/restic_0.12.0_linux_amd64.bz2

[centos@centos8 ~]$ bzip2 -d restic_0.12.0_linux_amd64.bz2

[centos@centos8 ~]$ sudo mv restic_0.12.0_linux_amd64 restic && sudo mv restic /usr/bin

[centos@centos8 ~]$ sudo chmod a x /usr/bin/restic

How to Create a Restic Repository

To create Restic backups, we need to initialize a directory that acts as the repository for Restic to store the files. A Restic repository can be both local or on a remote server or service.

Let us discuss how to initialize a local repository.

Local Repository

To initialize a local repository, use the Restic init command followed by — repo and the directory where you want to create the repository.

For example:

sudo restic init –repo /srv/backup-repo

<img data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/05/echo/word-image-481.png" data-lazy- height="147" src="data:image/svg xml,” width=”484″>

It is good to ensure that you remember the password; you will need it to access the files in the repository.

Remote Repository

To create a remote repository on a server, use SFTP protocol. Before doing this, ensure the server is configured with SSH and Passwordless login as Restic will fail if prompted for a password. To learn how to use a public key for SSH logins, consider the following tutorial:

https://linuxhint.com/setup_ssh_without_passwords/

https://linuxhint.com/passwordless_login_ssh/

Once you have everything configured on your remote host, use the command below:

sudo restic -r sftp:user@192.168.0.22:/srv/backup-repo init

How to Create Restic Backups

Now that we have the repositories set up on local and remote hosts, we can move on how to back up some data. In Restic, we call backups as snapshots.

To create a simple backup, use the command shown below:

$ sudo restic backup -r /srv/backup-repo/ ~/archives –verbose

<img data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/05/echo/word-image-482.png" data-lazy- height="322" src="data:image/svg xml,” width=”638″>

The above command automatically creates a snapshot of the ~/archives directory and adds it to the repository we created earlier. You will notice the snapshot value is in the form of hexadecimal characters, thus making them easier and faster to identify.

Restic is a fast tool that can process many files in a few minutes with no strain on the computing resources. You can minimize the output of the Restic backup process by skipping the — verbose option.

It is good to note that Restic is very efficient, and it will skip duplicate files before adding them to the repository.

If Restic encounters a backed-up file, it scans the file to ensure that only the contents of the files get stored in the snapshot. It uses change detection mechanisms such as metadata to detect changes to a file.

How to Add Tags to Snapshots

Restic also allows you to add tags or additional information to a snapshot. Thus, allowing you to identify a snapshot easily. To add a tag, use the command as:

$ sudo restic -r /srv/backup-repo backup –tag MySQL-Backups –tag nginx-mysql ~/archives

Then, you can reference a snapshot using the specified tags.

Working with Repositories

To view the snapshots in a repository, use the command:

sudo restic snapshots -r /srv/backup-repo

<img data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/05/echo/word-image-483.png" data-lazy- height="147" src="data:image/svg xml,” width=”664″>

Removing a Snapshot

To remove a snapshot from a repository, use the forget command followed by the name or tag of the snapshot.

Use the command:

sudo restic forget 9e549b6d -r /srv/backup-repo

<img data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/05/echo/word-image-484.png" data-lazy- height="88" src="data:image/svg xml,” width=”524″>

However, the forget command still reserves the data referenced by the files stored in the removed snapshot. You can remove the unreferenced data using the prune command.

sudo restic prune -r /srv/backup-repo

<img data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/05/echo/word-image-485.png" data-lazy- height="404" src="data:image/svg xml,” width=”614″>

Restore Backup

Restoring files from a saved snapshot is simple. Use the command below to restore a backup:

sudo restic restore -r /srv/backup-repo/ 194f005a –target /tmp/restores

<img data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/05/echo/word-image-486.png" data-lazy- height="85" src="data:image/svg xml,” width=”847″>

Conclusion

In this tutorial, we have discussed how to install and use a Restic backup utility. This tutorial is a starter guide that teaches you how to perform basic backup and restore operations. To learn more about how to use the Restic backup tool, consider the documents in the resource provided below:

https://restic.readthedocs.io/en/latest/

About the author

<img alt="" data-del="avatar" data-lazy-src="https://kirelos.com/wp-content/uploads/2021/05/echo/john.png60ab3f23bc232.jpg" height="112" src="data:image/svg xml,” width=”112″>

John Otieno

My name is John and am a fellow geek like you. I am passionate about all things computers from Hardware, Operating systems to Programming. My dream is to share my knowledge with the world and help out fellow geeks. Follow my content by subscribing to LinuxHint mailing list