Learn how to install and use the restic back-up tool over a network, for easy data back up 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 go with a full-blown GUI application or a simple command line tool (or anything in between). One such command line tool (that has a great deal of potential) is restic . Restic is a fast, secure back-up application that can handle local or network back ups with speed and ease. With this tool, you can create bash scripts or cron jobs to suit your Linux backup needs.
I want to walk you through the installation of restic, the creation of a remote repository, and backing up data over your network. I’ll demonstrate on the Ubuntu Server 18.04 platform.
What you need
To successfully make this work, you need the following:
- A Ubuntu Server 18.04 instance.
- Another Linux server (or desktop) that houses the data to be backed up.
- SSH key authentication configured between the two machines (See: How to set up ssh key authentication).
- A user with sudo privileges.
With those bits in hand, let’s get to work.
Because restic can be found in the standard Ubuntu repositories, installation can be taken care of with a single command:
sudo apt-get install restic -y
Once the installation completes, you’re ready to continue.
Creating a repository
The next step is to create a repository. First, we need a destination directory on our remote server. Log into that server and create the new directory with the command:
sudo mkdir /srv/restic-repo
Make sure to alter the permissions for that directory as needed. Say, for example, the user jack will handle the backups. For that, you want to change the ownership with the command:
sudo chown jack.jack /srv/restic-repo
You might be better off creating a group that can use the backups, add all the necessary users to that group, and change 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 IP address of the remote server. You will be prompted for the SSH key password, and then prompted to create (and verify) a password for the repository. Once that command completes, you’re ready to back up.
Let’s say we have the directory ~/data on the client machine, and we want to back it up 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 IP address of the remote server.
Restic will send the backup to the remote server and report back the results (Figure A).
Restoring from a backup
Now that you backed up to the remote repository, how do you restore that data back to your local machine? 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 in a newly created ~/data-restore directory (restic will create this for you).
Congratulations, you 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 useful and creative ways.
>> Source Link