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 https://files.pythonhosted.org/packages/a4/e1/7c753c512eebfa0aef96a52f7dc04dc32394d56793a082b0f84d16c75ad9/borgmatic-1.5.22-py3-none-any.whl
Collecting requests (from borgmatic)
  Using cached https://files.pythonhosted.org/packages/2d/61/08076519c80041bc0ffa1a8af0cbd3bf3e2b62af10435d269a9d0f40564d/requests-2.27.1-py2.py3-none-any.whl
Collecting setuptools (from borgmatic)
  Using cached https://files.pythonhosted.org/packages/b0/3a/88b210db68e56854d0bcf4b38e165e03be377e13907746f825790f3df5bf/setuptools-59.6.0-py3-none-any.whl
Collecting ruamel.yaml0.15.0 (from borgmatic)
  Using cached https://files.pythonhosted.org/packages/9e/cb/938214ac358fbef7058343b3765c79a1b7ed0c366f7f992ce7ff38335652/ruamel.yaml-0.17.21-py3-none-any.whl
Collecting colorama=0.4.1 (from borgmatic)
  Using cached https://files.pythonhosted.org/packages/44/98/5b86278fbbf250d239ae0ecb724f8572af1c91f4a11edf4d36a206189440/colorama-0.4.4-py2.py3-none-any.whl
Collecting jsonschema (from borgmatic)
  Using cached https://files.pythonhosted.org/packages/e0/d9/05587ac378b9fd2c352c6f024f13240168365bd753a7e8007522b7025267/jsonschema-4.0.0-py3-none-any.whl
Collecting idna=2.5; python_version >= "3" (from requests->borgmatic)
  Using cached https://files.pythonhosted.org/packages/04/a2/d918dcd22354d8958fe113e1a3630137e0fc8b44859ade3063982eacd2a4/idna-3.3-py3-none-any.whl
Collecting charset-normalizer~=2.0.0; python_version >= "3" (from requests->borgmatic)
  Using cached https://files.pythonhosted.org/packages/06/b3/24afc8868eba069a7f03650ac750a778862dc34941a4bebeb58706715726/charset_normalizer-2.0.12-py3-none-any.whl
Collecting certifi>=2017.4.17 (from requests->borgmatic)
  Using cached https://files.pythonhosted.org/packages/37/45/946c02767aabb873146011e665728b680884cd8fe70dde973c640e45b775/certifi-2021.10.8-py2.py3-none-any.whl
Collecting urllib3=1.21.1 (from requests->borgmatic)
  Using cached https://files.pythonhosted.org/packages/ec/03/062e6444ce4baf1eac17a6a0ebfe36bb1ad05e1df0e20b110de59c278498/urllib3-1.26.9-py2.py3-none-any.whl
Collecting ruamel.yaml.clib>=0.2.6; platform_python_implementation == "CPython" and python_version < "3.11" (from ruamel.yaml0.15.0->borgmatic)
  Using cached https://files.pythonhosted.org/packages/2a/25/5b1dfc832ef3b83576c546d1fb3e27f136022cdd1008aab290a1e28ef220/ruamel.yaml.clib-0.2.6-cp36-cp36m-manylinux1_x86_64.whl
Collecting attrs>=17.4.0 (from jsonschema->borgmatic)
  Using cached https://files.pythonhosted.org/packages/be/be/7abce643bfdf8ca01c48afa2ddf8308c2308b0c3b239a44e57d020afa0ef/attrs-21.4.0-py2.py3-none-any.whl
Collecting importlib-metadata; python_version borgmatic)
  Using cached https://files.pythonhosted.org/packages/a0/a1/b153a0a4caf7a7e3f15c2cd56c7702e2cf3d89b1b359d1f1c5e59d68f4ce/importlib_metadata-4.8.3-py3-none-any.whl
Collecting pyrsistent!=0.17.0,!=0.17.1,!=0.17.2,>=0.14.0 (from jsonschema->borgmatic)
  Using cached https://files.pythonhosted.org/packages/6c/19/1af501f6f388a40ede6d0185ba481bdb18ffc99deab0dd0d092b173bc0f4/pyrsistent-0.18.0-cp36-cp36m-manylinux1_x86_64.whl
Collecting zipp>=0.5 (from importlib-metadata; python_version jsonschema->borgmatic)
  Using cached https://files.pythonhosted.org/packages/bd/df/d4a4974a3e3957fd1c1fa3082366d7fff6e428ddb55f074bf64876f8e8ad/zipp-3.6.0-py3-none-any.whl
Collecting typing-extensions>=3.6.4; python_version < "3.8" (from importlib-metadata; python_version jsonschema->borgmatic)
  Using cached https://files.pythonhosted.org/packages/45/6b/44f7f8f1e110027cf88956b59f2fad776cca7e1704396d043f89effd3a0e/typing_extensions-4.1.1-py3-none-any.whl
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 https://borgbackup.readthedocs.io/en/stable/changes.html#pre-1-0-9-manifest-spoofing-vulnerability 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: https://torsion.org/borgmatic/#issues
  • 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 https://borgbackup.readthedocs.io/en/stable/quickstart>
# https://borgbackup.readthedocs.io/en/stable/usage/create.h>
# for details.
location:
    # List of source directories to backup (required). Globs>
    # tildes are expanded.
    source_directories:
        - /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.
    repositories:
        - borg


# Retention policy for how many backups to keep in each cate>
# https://borgbackup.readthedocs.io/en/stable/usage/prune.ht>
# 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>
retention:
    # 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.

[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
  • 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.

[Unit]
Description=Daily backup timer

[Timer]
OnCalendar=*-*-* 12:00:00
Persistent=true

[Install]
WantedBy=timers.target
  • 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