Install and Configure Borgmatic on Rocky Linux

This guide will take you through on how to install and configure Borgmatic on Rocky Linux. Borgmatic is backup software for servers and workstations that is simple to use and configure. It creates a backup, deletes any previous backups that don’t meet the retention policy’s requirements, and ensures backup consistency.

Install Borgmatic on Rocky Linux

  • Update your packages.
sudo dnf update
  • Then Install Borgmatic on Rocky Linux.
pip3 install --user --upgrade borgmatic

Sample output

Collecting borgmatic
  Using cached
Collecting requests (from borgmatic)
  Using cached
Collecting setuptools (from borgmatic)
  Using cached
Collecting ruamel.yaml0.15.0 (from borgmatic)
  Using cached
Collecting colorama=0.4.1 (from borgmatic)
  Using cached
Collecting jsonschema (from borgmatic)
  Using cached
Collecting idna=2.5; python_version >= "3" (from requests->borgmatic)
  Using cached
Collecting charset-normalizer~=2.0.0; python_version >= "3" (from requests->borgmatic)
  Using cached
Collecting certifi>=2017.4.17 (from requests->borgmatic)
  Using cached
Collecting urllib3=1.21.1 (from requests->borgmatic)
  Using cached
Collecting ruamel.yaml.clib>=0.2.6; platform_python_implementation == "CPython" and python_version < "3.11" (from ruamel.yaml0.15.0->borgmatic)
  Using cached
Collecting attrs>=17.4.0 (from jsonschema->borgmatic)
  Using cached
Collecting importlib-metadata; python_version borgmatic)
  Using cached
Collecting pyrsistent!=0.17.0,!=0.17.1,!=0.17.2,>=0.14.0 (from jsonschema->borgmatic)
  Using cached
Collecting zipp>=0.5 (from importlib-metadata; python_version jsonschema->borgmatic)
  Using cached
Collecting typing-extensions>=3.6.4; python_version < "3.8" (from importlib-metadata; python_version jsonschema->borgmatic)
  Using cached
Installing collected packages: idna, charset-normalizer, certifi, urllib3, requests, setuptools, ruamel.yaml.clib, ruamel.yaml, colorama, attrs, zipp, typing-extensions, importlib-metadata, pyrsistent, jsonschema, borgmatic
Successfully installed attrs-21.4.0 borgmatic-1.5.22 certifi-2021.10.8 charset-normalizer-2.0.12 colorama-0.4.4 idna-3.3 importlib-metadata-4.8.3 jsonschema-4.0.0 pyrsistent-0.18.0 requests-2.27.1 ruamel.yaml-0.17.21 ruamel.yaml.clib-0.2.6 setuptools-59.6.0 typing-extensions-4.1.1 urllib3-1.26.9 zipp-3.6.0
  • After installing, use the following command to add borgmatic’s commands to your system PATH.
export PATH="$HOME/.local/bin:$PATH"
  • Update your current session using the command below.
source ~/.bashrc
  • To make sure everything went smoothly, run the command below to check the version.
borgmatic --version
  • Next, install borgbackup using the following commands.
yum install -y openssl-devel gcc-c++ python3-devel libacl-devel
dnf install -y redhat-rpm-config
pip3 install virtualenv
virtualenv --python=python3 borg-env
source borg-env/bin/activate
pip3 install borgbackup
  • After installation, initiate the backup repository.
borg init -e repokey borg

Sample output

Enter new passphrase: 
Enter same passphrase again: 
Do you want your passphrase to be displayed for verification? [yN]: y
Your passphrase (between double-quotes): "1234"
Make sure the passphrase displayed above is exactly what you wanted.

By default repositories initialized with this version will produce security
errors if written to with an older version (up to and including Borg 1.0.8).

If you want to use these older versions, you can disable the check by running:
borg upgrade --disable-tam borg

See for details about the security implications.

IMPORTANT: you will need both KEY AND PASSPHRASE to access this repo!
If you used a repokey mode, the key is stored in the repo, but you should back it up separately.
Use "borg key export" to export the key, optionally in printable format.
Write down the passphrase. Store both at safe place(s).

Configure Borgmatic on Rocky Linux

  • Make a Borgamatic configuration file using the command below.
generate-borgmatic-config -d demo.yaml

Sample output

Generated a sample configuration file at demo.yaml.

Please edit the file to suit your needs. The values are representative.
All fields are optional except where indicated.

If you ever need help:
  • Next, customize the configuration file. Open the config file using the following command.
sudo nano demo.yaml
  • Make changes to the configuration file to match your needs, e.g., backup directories under source directories, retention time, prohibited directories, etc. See the example file below.
# Where to look for files to backup, and where to store thos>
# See>
# for details.
    # List of source directories to backup (required). Globs>
    # tildes are expanded.
        - /home
        - /etc
        - /var/log/syslog*

    # Paths to local or remote repositories (required). Tild>
    # expanded. Multiple repositories are backed up to in
    # sequence. Borg placeholders can be used. See the outpu>
    # "borg help placeholders" for details. See ssh_command >
    # SSH options like identity file or port. If systemd ser>
    # is used, then add local repository paths in the systemd
    # service file to the ReadWritePaths list.
        - borg

# Retention policy for how many backups to keep in each cate>
# details. At least one of the "keep" options is required fo>
# to work. To skip pruning entirely, run "borgmatic create" >
# without the "prune" action. See borgmatic documentation fo>
    # Keep all archives within this time interval.
    # keep_within: 3H

    # Number of secondly archives to keep.
    # keep_secondly: 60

    # Number of minutely archives to keep.
    # keep_minutely: 60

    # Number of hourly archives to keep.
    # keep_hourly: 24

    # Number of daily archives to keep.
    keep_daily: 7

    # Number of weekly archives to keep.
    # keep_weekly: 4

    # Number of monthly archives to keep.
    # keep_monthly: 6

    # Number of yearly archives to keep.
    # keep_yearly: 1

    # When pruning, only consider archive names starting wit>
    # prefix.  Borg placeholders can be used. See the output>
    # "borg help placeholders" for details. Defaults to
    # "{hostname}-". Use an empty value to disable the defau>
    # prefix: sourcehostname

Create Backup

  • Run the command below to create your first backup.
borg create --list borg::archive demo.yaml
  • List the created backups using the command below.
sudo borgmatic -c demo.yaml --list

Sample output

borg: Listing archives
Enter passphrase for key /home/itnixpro/borg: 
Enter passphrase for key /home/itnixpro/borg: 
archive                              Thu, 2022-05-12 10:16:50 [019d10f5a2f5a33dcb9188d9f9befcb82754fef874b73193ec796995c4a1592a]

Automate Backup

  • Run the following command to create a borgmatic systemd service file.
sudo nano /etc/systemd/system/borgmatic.service

Insert the content below.

Description=Borgmatic system backup

ExecStart=/usr/bin/borgmatic --verbosity -1 --syslog-verbosity 1
  • Next, create a timer config file to define backup time.
sudo nano /etc/systemd/system/borgmatic.timer

Copy the configuration file and change the backup time to your preference.

Description=Daily backup timer

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

  • Enable the timer.
systemctl enable --now borgmatic.timer
  • That marks the end of our article, Cheers! You have learned how to Install and Configure Borgmatic on Rocky Linux.

Read more on Borgmatic Documentation

Other Tutorials

Install and Configure Borgmatic on Debian 11

Install and Configure Borgmatic on Ubuntu 22.04

Install Mattermost on Rocky Linux 8

System administrator | Software Developer | DevOps

Leave a Comment