Install and Configure Borgmatic on Ubuntu 22.04

This guide will take you through on how to install and configure Borgmatic on Ubuntu 22.04. Borgmatic is easy-to-use and configure backup software for servers and workstations. It makes a backup, prunes any old backups that don’t meet the retention policy’s requirements, and verifies backup consistency.

Install Borgmatic on Ubuntu 22.04

  • Update your packaged.
sudo apt update
  • Then, using the command below, install Borgmatic on Ubuntu 22.04.
sudo apt install borgmatic

Sample output

Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  borgbackup python3-async-generator python3-attr
  python3-distutils python3-jsonschema python3-llfuse
  python3-msgpack python3-outcome python3-packaging
  python3-pyfuse3 python3-pyrsistent python3-ruamel.yaml
  python3-ruamel.yaml.clib python3-setuptools
  python3-sniffio python3-sortedcontainers python3-trio
Suggested packages:
  borgbackup-doc python-attr-doc python-jsonschema-doc
  python-llfuse-doc python-setuptools-doc
The following NEW packages will be installed:
  borgbackup borgmatic python3-async-generator python3-attr
  python3-distutils python3-jsonschema python3-llfuse
  python3-msgpack python3-outcome python3-packaging
  python3-pyfuse3 python3-pyrsistent python3-ruamel.yaml
  python3-ruamel.yaml.clib python3-setuptools
  python3-sniffio python3-sortedcontainers python3-trio
0 upgraded, 18 newly installed, 0 to remove and 19 not upgraded.
Need to get 2,544 kB of archives.
After this operation, 11.4 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 jammy/main amd64 python3-msgpack amd64 1.0.3-1build1 [67.8 kB]
Get:2 jammy/main amd64 python3-packaging all 21.3-1 [30.7 kB]
Get:3 jammy/universe amd64 borgbackup amd64 1.2.0-1 [792 kB]
Get:4 jammy/main amd64 python3-attr all 21.2.0-1 [44.0 kB]
Get:5 jammy/main amd64 python3-distutils all 3.10.4-0ubuntu1 [138 kB]
Get:6 jammy/main amd64 python3-setuptools all 59.6.0-1.2 [339 kB]
Get:7 jammy/main amd64 python3-pyrsistent amd64 0.18.1-1build1 [55.5 kB]
Get:8 jammy/main amd64 python3-jsonschema all 3.2.0-0ubuntu2 [43.1 kB]
Get:9 jammy/universe amd64 python3-ruamel.yaml.clib amd64 0.2.6-1build1 [134 kB]
Get:10 jammy/universe amd64 python3-ruamel.yaml all 0.17.16-1 [86.3 kB]
Get:11 jammy/universe amd64 borgmatic all 1.5.20-1 [51.0 kB]
Get:12 jammy/universe amd64 python3-async-generator all 1.10-3 [17.5 kB]
Get:13 jammy/universe amd64 python3-llfuse amd64 1.3.8+dfsg-2build1 [291 kB]
Get:14 jammy/universe amd64 python3-outcome all 1.1.0-1 [5,820 B]
Get:15 jammy/universe amd64 python3-sniffio all 1.2.0-1 [6,438 B]
Get:16 jammy/main amd64 python3-sortedcontainers all 2.1.0-2 [27.3 kB]
Get:17 jammy/universe amd64 python3-trio all 0.19.0-1 [238 kB]
Get:18 jammy/universe amd64 python3-pyfuse3 amd64 3.2.0-3build1 [176 kB]
Fetched 2,544 kB in 1s (3,212 kB/s)       
Selecting previously unselected package python3-msgpack.
(Reading database ... 216323 files and directories currently 
Preparing to unpack .../00-python3-msgpack_1.0.3-1build1_amd6
4.deb ...
Unpacking python3-msgpack (1.0.3-1build1) ...
Selecting previously unselected package python3-packaging.
Preparing to unpack .../01-python3-packaging_21.3-1_all.deb .
  • Initialize the backup repository after installation.
borg init -e repokey demo.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 demo.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 Ubuntu 22.04

  • Make a configuration file for Borgamatic.
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, open the configuration file so as to customize it.
sudo nano demo.yaml
  • Customize the configuration file to meet your requirements. i.e. backup directories under source directories, retention time, excluded directories, and so forth. 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.
        - demo.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 using Borgmatic

  • To create your first backup, run the command below.
sudo borgmatic --config demo.yaml --verbosity 1

Sample output

Enter passphrase for key /home/itinixpro/demo.borg: 
demo.borg: Creating archive
Enter passphrase for key /home/itinixpro/demo.borg: 
Creating archive at "demo.borg::nfs-2022-05-09T11:07:29.717951"

demo.borg: Running consistency checks
Starting repository check
finished segment check at segment 17
Starting repository index check
Index object count match.
Finished full repository check, no problems found.
Starting archive consistency check...
Enter passphrase for key /home/itinixpro/demo.borg: 
Analyzing archive nfs-2022-05-09T11:03:32.672099.checkpoint (1/2)
Analyzing archive nfs-2022-05-09T11:07:29.717951 (2/2)
Orphaned objects check skipped (needs all archives checked).
Archive consistency check complete, no problems found.

demo.yaml: Successfully ran configuration file
  • Use the following command to check your backup.
sudo borgmatic -c demo.yaml --list

Sample output

demo.borg: Listing archives
Enter passphrase for key /home/itinixpro/demo.borg: 
nfs-2022-05-09T11:07:29.717951       Mon, 2022-05-09 11:07:32 [ef8234af25bcfdac828ab8463cfca99d0eecb9ee15f116799aa460249f507873]

Automate Backup

  • Create a borgmatic systemd service file.
sudo nano /etc/systemd/system/borgmatic.service

Paste the content below.

Description=Borgmatic system backup

ExecStart=/usr/bin/borgmatic --verbosity -1 --syslog-verbosity 1
  • Then, using the following command, 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=*-*-* 02:00:00

  • Enable the timer.
systemctl enable --now borgmatic.timer
  • It’s a wrap! You have made it to the end of our article, Cheers! You have learned how to install and configure Borgmatic on Ubuntu 22.04.

Read more on Borgmatic Documentation

Other Tutorials

How to Backup Windows systems using Veeam Agent

How to Backup Linux systems using Veeam Agent

Backup Linux systems using BackupPC

System administrator | Software Developer | DevOps

Leave a Comment