If you use the Linux platform for various servers or desktops, you know that for every task there can be multiple possible solutions. One very good example of that is in the realm of backups. There are tons of routes to choose when trying to backup your data—even when you're looking to backup your data over a network.
One such solution is the open source BorgBackup. BorgBackup (or Borg, for short) is a deduplicating backup program that supports compression, authenticated encryption, and backing up over a network.
I want to walk you through the process of installing Borg, creating a local repository, and then backing up to a remote repository on your network. This will only cover a fraction of what Borg can do. To get the most out of this solution, make sure to give the official documentation a read.
With that said, let's get our Borg on.
Borg is found in the standard repositories, so installation is simple. I will be demonstrating on the Ubuntu platform. If you work with a different distribution, modify the installation command as needed.
To install Borg, open up a terminal window and issue the command:
sudo apt install borgbackup
That's all there is to it. Do note, you must have Borg installed on both local and remote machine. With this installation out of the way, you're ready to rock.
Create a local repository
I'm going to first walk you through the process of creating a local repository with Borg. Once you understand that, then you can move on to create a remote repository. We'll be creating a repository that makes use of an encryption key (because ... security!). The command to create a local repository looks like this:
borg init --encryption=repokey /REPOSITORY
Where REPOSITORY is the direct path to the directory to be used. Let's say, for example, you have the directory /data to be used as a repository. Obviously, before you use this directory, the user who will run the command must have read/write access. For this, you'd issue the command sudo chown USER:USER /data (Where USER is the actual username). To create the /data repository, issue the command:
borg init --encryption=repokey /data
You will be prompted to create (and verify) an encryption password for the new repository. Once you've created the repository, it can be used to backup files and directories. Say you have the directory ~/Documents and you want it backed up to your new repository, with the name THURS (as we're backing it up on Thursday). The command for this would be:
borg create /data::THURS ~/Documents
You will be prompted for the encryption passphrase for the repository. Once authenticated, the ~/Documents directory will be backed up to /data.
If you issue the command borg list /data, you will see a listing of the newly created backup (Figure A).
Now that you have a basic understanding of how Borg works, let's create a remote repository and then backup to it. Before you can do this, you must be able to SSH into the remote machine. If you don't already have the necessary server installed (on the remote machine), you can do so with the command:
sudo apt install openssh-server
With that secure shell connection working, you can then create a remote repository with a command like so:
borg init USER@IP:/REPO
Where USER is the remote username, IP is the IP address of the remote server, and REPO is the directory to be used as the repository. Let's say we're going to use the remote directory /BACKUP, with the user jack, on the remote remote machine at IP address 192.168.1.90. The command for this would be:
borg init email@example.com:/BACKUP
You will first be prompted for the ssh password for the remote user. Next you'll be prompted for a passphrase for the backup. Once you've verified that password, you will then be asked if you want to display the newly typed passphrase. Accept the default (N) and the repository will be created.
Backing up to the remote repository is similar to backing up locally. Let's backup the ~/Documents directory to our newly created remote repository. The command for this looks like:
borg create firstname.lastname@example.org:/BACKUP::THURS ~/Documents
The above command would create a new backup on the remote repository, named THURS. You can list that backup with the command:
borg list email@example.com:/BACKUP
Our newly created backup will be listed (Figure B).
Resistance is futile
At this point, you know just enough to be dangerous with Borg. This tool is capable of quite a bit more, so make sure to comb through the official documentation to learn more of what it can do. Once you start using Borg, resistance will be, of course, futile.
- How to prevent Google Drive backup from taking up precious space on your local drive (TechRepublic)
- How to sync your Linux GUI-less server to your cloud service with rclone (TechRepublic)
- 2 ways to better secure your Linux home directory (TechRepublic)
- How to set bridged networking in a VirtualBox virtual machine (TechRepublic)
- How to connect VirtualBox VMs to your company network (TechRepublic Video)
- How to use Let's Encrypt to secure your websites (ZDNet)
Jack Wallen is an award-winning writer for TechRepublic and Linux.com. He’s an avid promoter of open source and the voice of The Android Expert. For more news about Jack Wallen, visit his website jackwallen.com.