Install and Configure Borgmatic on Debian 11

This guide will take you through on how to install and configure Borgmatic on Debian 11. Borgmatic is backup software for servers and workstations that is simple to use and configure. It creates a backup, prunes any old backups that don’t meet the retention policy’s and checks backups for consistency.

Install and Configure Borgmatic on Debian 11

  • Update your packaged.
sudo apt update
  • Next install Borgmatic on Debian 11 using the command below.
sudo apt install borgmatic

Sample output

Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages were automatically installed and are no longer required:
  bc cups cups-browsed cups-client cups-core-drivers cups-daemon cups-filters
  cups-filters-core-drivers cups-ipp-utils cups-ppdc cups-server-common
  fonts-symbola hyphen-en-us iw javascript-common libcupsfilters1
  libfontembed1 libglu1-mesa liblouisutdml-bin liblouisutdml-data
  liblouisutdml9 libpoppler-cpp0v5 libqpdf28 libreoffice-help-common
  libreoffice-help-en-us mythes-en-us node-normalize.css sudo x11-apps
  x11-session-utils xinit
Use 'sudo apt autoremove' to remove them.
The following additional packages will be installed:
  borgbackup libb2-1 python3-colorama python3-dateutil python3-docopt
  python3-llfuse python3-pykwalify python3-ruamel.yaml
Suggested packages:
  borgbackup-doc python-llfuse-doc
The following NEW packages will be installed:
  borgbackup borgmatic libb2-1 python3-colorama python3-dateutil
  python3-docopt python3-llfuse python3-pykwalify python3-ruamel.yaml
0 upgraded, 10 newly installed, 0 to remove and 2 not upgraded.
Need to get 1,372 kB of archives.
After this operation, 5,512 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 bullseye/main amd64 libb2-1 amd64 0.98.1-1.1 [40.9 kB]
Get:2 bullseye/main amd64 borgbackup amd64 1.1.16-3 [708 kB]
Get:3 bullseye/main amd64 python3-colorama all 0.4.4-1 [28.5 kB]
Get:4 bullseye/main amd64 python3-dateutil all 2.8.1-6 [79.2 kB]
Get:5 bullseye/main amd64 python3-docopt all 0.6.2-3 [26.6 kB]
Get:6 bullseye/main amd64 python3-ruamel.yaml.clib amd64 0.2.2-1+b2 [132 kB]
Get:7 bullseye/main amd64 python3-ruamel.yaml all 0.16.12-2 [110 kB]
Get:8 bullseye/main amd64 python3-pykwalify amd64 1.8.0-1 [22.7 kB]
Get:9 bullseye/main amd64 borgmatic all 1.5.12-2 [47.5 kB]
Get:10 bullseye/main amd64 python3-llfuse amd64 1.3.8+dfsg-2 [176 kB]
Fetched 1,372 kB in 2s (652 kB/s)        
Selecting previously unselected package libb2-1:amd64.
(Reading database ... 143649 files and directories currently installed.)
Preparing to unpack .../0-libb2-1_0.98.1-1.1_amd64.deb ...
Unpacking libb2-1:amd64 (0.98.1-1.1) ...
Selecting previously unselected package borgbackup.
Preparing to unpack .../1-borgbackup_1.1.16-3_amd64.deb ...
Unpacking borgbackup (1.1.16-3) ...
Selecting previously unselected package python3-colorama.
Preparing to unpack .../2-python3-colorama_0.4.4-1_all.deb ...
Unpacking python3-colorama (0.4.4-1) ...
Selecting previously unselected package python3-dateutil.
Preparing to unpack .../3-python3-dateutil_2.8.1-6_all.deb ...
Unpacking python3-dateutil (2.8.1-6) ...
Selecting previously unselected package python3-docopt.
Preparing to unpack .../4-python3-docopt_0.6.2-3_all.deb ...
Unpacking python3-docopt (0.6.2-3) ...
  • After installation, initialize backup repository.
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]:  

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!
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 Debian 11

  • Create Borgamatic configuration file.
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:
  • Open the configuration file to configure it.
sudo nano demo.yaml
  • Customize the configuration file according to your needs i.e. directories to be backed up under source_directories, retention time, directories to be excluded etc. Check 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

  • Run the command below to create your first backup.
sudo borgmatic --config demo.yaml --verbosity 1

Sample output

demo.borg: Pruning archives
demo.borg: Creating archive
Enter passphrase for key /home/itnixpro/demo.borg: 
Creating archive at "demo.borg::{hostname}-{now:%Y-%m-%dT%H:%M:%S.%f}"
demo.borg: Running consistency checks
Starting repository check
Starting repository index check
Index object count match.
Completed repository check, no problems found.
Enter passphrase for key /home/itnixpro/demo.borg: 
Starting archive consistency check...
Analyzing archive debian-2022-05-07T00:33:52.990455 (1/2)
Analyzing archive debian-2022-05-07T10:52:26.851959 (2/2)
Orphaned objects check skipped (needs all archives checked).
Archive consistency check complete, no problems found.

demo.yaml: Successfully ran configuration file
  • Check backup using the following command.
sudo borgmatic -c demo.yaml --list

Sample output

demo.borg: Listing archives
Enter passphrase for key /home/itnixpro/demo.borg: 
debian-2022-05-07T00:33:52.990455    Sat, 2022-05-07 00:34:02 [2dac6a6f5eb070b6ec143303ebcfd8e8f7b4818e663129493015ddec53d25b86]
debian-2022-05-07T10:52:26.851959    Sat, 2022-05-07 10:52:30 [b03f5f1d4e182c45f614de384a094d7851315fcfad89865bd36c9caf4ecd277f]

Automate Backup

  • Create systemd service file for borgmatic.
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 specify backup time by creating timer config file using the following command.
sudo nano /etc/systemd/system/borgmatic.timer

Paste the configuration file and specify your preferred backup time.

Description=Daily backup timer

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

  • Next enable the timer.
systemctl enable --now borgmatic.timer
  • You have made it to the end of our article, Cheers! You have learned how to install and configure Borgmatic on Debian 11.

Read more on Borgmatic Documentation

Other Tutorials

How to Backup Windows systems using Veeam Agent

How to Backup Linux systems using Veeam Agent

Backup Windows Systems using BackupPC

System administrator | Software Developer | DevOps

Leave a Comment