In this article, I will show you how to install and use Restic on Ubuntu 18.04 LTS. Let’s get started.
Installing Restic on Ubuntu 18.04
In this section, I will show you how to install Restic 0.8.3, which is the latest stable version as of this writing. It is available in the official package repository of Ubuntu 18.04 LTS.
First update the apt package repository of Ubuntu 18.04 LTS with the following command:
The apt package repository cache should be updated.
Now run the following command to install Restic:
Restic should be installed.
Now you can check whether Restic is working with the following command:
As you can see from the screenshot below, the version of Restic currently installed on my machine is 0.8.3.
Taking Local Backups with Restic
In this section, I will show you how to take local backup with Restic.
First you have to create or initialize a new Restic repository anywhere on your Local filesystem. It may be an external hard drive or USB thumb drive mounted on your local filesystem as well.
I assume you’re taking a backup of your user’s HOME directory to an external hard drive or an USB thumb drive. Let’s say the block device is /dev/sdb1 on my Ubuntu 18.04 machine.
You can find out what it is on your computer with the following command:
Now create a /backup directory on your filesystem with the following command:
Now mount the external hard drive or USB thumb drive (/dev/sdb1 in my case) to /backup directory with the following command:
You can verify that the external hard drive or USB thumb drive is mounted to the correct location with the following command:
As you can see from the marked section of the screenshot below, the block device /dev/sdb1 is mounted on /backup directory.
You can create or initialize a Restic repository on /backup directory with the following command:
Now type in a password for your Restic repository and press <Enter>. Remember, you can’t access your Restic repository without this password and the Restic repository is unrecoverable without the password.
Now type in your Restic repository password again and press <Enter>.
The Restic repository should be created or initialized.
Now you’re ready to backup your files and directories.
Let’s say, you want to backup your user’s HOME directory with Restic, you can do so with the following command:
NOTE: Here /home/shovon is my user’s HOME directory.
Now type in your Restic repository password and press <Enter>.
The backup should be taken. As you can see in the marked section of the screenshot below, the /home/shovon directory is backed up and a snapshot id 21f198eb is printed. This is important as you can refer to or select a certain backup with the snapshot id. But you don’t have to remember it. You can find out what snapshots are available on your Restic backup. I will show you how shortly.
Let’s backup another directory /etc for the sake of demonstration.
The backup is complete.
Now you can list all the available Restic snapshots with the following command:
Now type in your Restic repository password and press <Enter>.
The Restic snapshots should listed as you can see in the screenshot below. The marked section of the screenshot shows the snapshot id for each directory you backed up in Restic.
NOTE: Restic supports incremental backup. If you backup the same directory as you backed up before, only the changes should be saved and a new snapshot id should be generated.
Now it’s time to show you how to recover files and directories from Restic backup.
Let’s say you want to restore the HOME directory (/home/shovon in my case) from Restic backup. You can run the following command to restore a Restic backup by it’s snapshot id.
NOTE: Here 21f198eb is the SNAPSHOT_ID and /home/shovon is the RESTORE_DIRECTORY in my case. Remember that RESTORE_DIRECTORY may be different from the directory that was backed up. For example, you may take a backup of /etc directory, but when you restore, if you want, you can put the contents of /etc directory to some other directory, for example /restore/etc directory.
Now type in your Restic repository password and press <Enter>.
The data should be recovered from the backup.
If you take incremental backups with Restic, it may be difficult for you to find out the latest snapshot id for a certain backup directory. Gladly, Restic comes with a way for you restore from the latest snapshot id of certain backup directory.
You can run the following command to restore the latest version of backup for a certain directory (in my case /home/shovon directory):
The latest version of the backup for the path /home/shovon is restored on the target /home/shovon.
Taking Remote Backups with Restic
Make sure that the Ubuntu 18.04 machine where Restic is installed have SFTP server installed before you try to take remote backups with Restic.
You can install SFTP server on your Ubuntu 18.04 LTS machine with the following command:
Press y and then press <Enter> to continue.
SFTP server should be installed.
Now replace every -r /LOCAL/PATH to -r sftp:username@hostname:/REMOTE/PATH
For example, the command for creating or initializing a Restic local repository should be converted from
to
$ sudo restic init -r sftp:username@hostname:/backup
Here username and hostname are the username and hostname or IP address of the remote server where Restic is installed. /backup is the directory where the Restic backup directory should be created or is already available.
That’s how you install and use Restic on Ubuntu 18.04 LTS. Thanks for reading this article.