How to back up Linux directories over a network with restic app

Learn how to install and use restic backup tool on a network, for easy data backup and restore.

There are so many options when you need to back up your data. This is especially true when using the Linux platform. You can use a full GUI application or a simple command line tool (or anything in between). One such command line tool (which has a lot of potential) is remains . Restic is a fast and secure backup application that can handle local or network backups with speed and ease. With this tool, you can create bash scripts or cron jobs to meet your Linux backup needs.

I want to walk you through installing restic, creating a remote repository, and backing up data to your network. I will be demoing on Ubuntu Server 18.04 platform.

SEE: System Update Policy Template Download (Tech Pro Research)

What do you need

To do this job successfully, you need the following:

  • An Ubuntu Server 18.04 instance.
  • Another Linux server (or desktop) that hosts the data to be backed up.
  • Authentication by SSH key configured between the two machines (See: How to configure authentication by ssh key).
  • A user with sudo privileges.

With these elements in hand, let’s get to work.

Installing restic

Since restic can be found in standard Ubuntu repositories, installation can be done with a single command:

sudo apt-get install restic -y

Once the installation is complete, you are ready to continue.

Creating a repository

The next step is to create a repository. First, we need a destination directory on our remote server. Connect to this server and create the new directory with the command:

sudo mkdir /srv/restic-repo

Be sure to change permissions for this directory if needed. For example, suppose the user socket handles backups. To do this, you want to change the owner with the command:

sudo chown jack.jack /srv/restic-repo

You might be better off creating a group that can use the backups, adding all necessary users to that group, and changing the group ownership of the directory with the command:

sudo chgrp -R /srv/restic-repo GROUP

Where GROUP is the name of the group you created.

Next, we need to initialize the repository. From the client machine, issue the command:

restic -r sftp:[email protected]_IP:/srv/restic-repo init

Where USER is the remote username and SERVER_IP is the remote server IP address. You will be prompted to enter the SSH key password and then create (and verify) a password for the repository. Once this command completes, you are ready to save.

Backup

Let’s say we have the directory ~/data on the client machine, and we want to save it to the remote repository we just created. The command to do this is:

restic backup data -r sftp:[email protected]_IP:/srv/restic-repo

Where USER is the remote user and SERVER_IP is the remote server IP address.

Restic will send the backup to the remote server and report the results (Figure A).

Restore from backup

Now that you’ve backed up to the remote repository, how do you restore that data to your local computer? Easy. On the local client, issue the command:

restic restore latest --target ~/data-restore -r sftp:[email protected]_IP:/srv/restic-repo

Where USER is the remote user and SERVER_IP is the remote server IP address.

The above command will restore the data from the remote repository to a new file ~/data-restore directory (restic will create it for you).

Congratulations, you have backed up and restored your data directory to a remote restic repository. You should now have all the information you need to use restic in a useful and creative way.

Comments are closed.