How to Install Borgmatic for Easy Linux Server Backups

0
Image: ribkhan/Adobe Stock

Do you have a reliable backup solution running on your Linux servers? If not, what is your disaster recovery plan? The word “disaster” alone should be enough to help you realize that backups are an absolutely crucial part of your organization.

If you’re looking for a new Linux backup solution, there’s a lesser-known solution that does an outstanding job and is fairly easy to install and configure. This solution is Borgmatic. This simple, configuration-based backup solution protects your files (and even your databases) with client-side encryption and even offers third-party integration for things like monitoring.

I want to walk you through the process of installing Borgmatic on Ubuntu Server 22.04. Once done, you should be sure that your important data is regularly backed up.

SEE: 40+ open source and Linux terms you need to know (TechRepublic Premium)

What you will need

The only things you will install and use Borgmatic are an instance of Ubuntu Server (you can also install it on Ubuntu Desktop and any Debian-derived distribution) and a user with sudo privileges. That’s it: Let’s do with the backups.

How to install Borgmatic

The first thing you might want to do is update and upgrade the Ubuntu server. This can be done with the two commands:

sudo apt-get update

sudo apt-get upgrade -y

If the kernel is updated during the process, you will need to reboot for the changes to take effect.

Once the update/upgrade is complete, install Borgmatic with the command:

sudo apt-get install borgmatic -y

Believe it or not, that’s it for the installation.

How to initialize a repository

Our next step is to initialize a repository for the backup. You will want to change to a directory to house the new repository. For example, if you have an external drive to house your backup that is mounted in the /data directory, change to /data with cd /data. We will call our repository test.borg and initialize it using a repository key. This command is:

borg init -e repokey test.borg

You will be prompted to enter and verify a password for the new repository. You should now see a new directory, inside /data, called test.borg.

How to create a configuration file

Now we can generate a configuration file. To do this run the command:

generate-borgmatic-config -d test.yaml

Open this new file for editing with:

nano test.yaml

You will see a section in this file that looks like this:

source_directories:

- /home

- /etc

- /var/log/syslog*

In this section, configure any directories you need to include in the backup.

You will also find a section that looks like this:

repositories:

- [email protected]:sourcehostname.borg

- [email protected]:{fqdn}

You’ll need to add the new repository and comment out the examples, so this section looks like this (modifying the name of the repository you created):

repositories:

- test.borg

#     - [email protected]:sourcehostname.borg

#     - [email protected]:{fqdn}

Save and close the file.

How to run your first backup

You can now run the first backup with the command:

sudo borgmatic --config test.yaml --verbosity 1

You will first be prompted for your sudo password, then twice for your repository key password.

Once the backup is complete, verify it with:

sudo borgmatic -c test.yaml --list

Your output should look like this:

jammy-2022-05-19T12:13:28.105102 Thu, 2022-05-19 12:13:32 [91df7f2c66fa516d026fc0fb8e9ad777d2533e81e22b7da1da9a4b0245804fea]

Congratulations, your first backup was successful.

How to automate backup

To automate the backup, we first need to create a systemd file with the command:

sudo nano /etc/systemd/system/borgmatic.service

In this file, paste the following:

[Unit]

Description=Borgmatic system backup

Requires=network.target

After=network.target

[Service]

Type=oneshot

Nice=10

IOSchedulingClass=best-effort

IOSchedulingPriority=6

ProtectSystem=full

ExecStart=/usr/bin/borgmatic --verbosity -1 --syslog-verbosity 1

Save and close the file. Next we need to specify the backup time. To do this, we create a timer configuration file (which runs the backup at the same time every day) with:

sudo nano /etc/systemd/system/borgmatic.timer

In this new file, paste the following:

[Unit]

Description=Daily backup timer

[Timer]

OnCalendar=*-*-* 12:00:00

Persistent=true

[Install]

WantedBy=timers.target

Activate the timer with the command:

sudo systemctl enable --now borgmatic.timer

You will be prompted to enter your repository key password. After this command completes, Borgmatic is set to run every day at the same time. Congratulations on creating a new backup system for your Linux server in record time.

Subscribe to TechRepublic How to make technology work on YouTube for all the latest tech tips for professionals from Jack Wallen.

Share.

Comments are closed.