Borgmatic

From ArchWiki

borgmatic is a Python-based wrapper script for Borg backup, designed to simplify and automate backups. It aims to provide an easy-to-use and flexible solution for creating backups using borgbackup.

Installation

Install the borgmatic package.

Configuration

By default no configuration file is installed. To create one you can use the command borgmatic config generate to generate one:

# borgmatic config generate
Generating a configuration file at: /etc/borgmatic/config.yaml
 
This includes all available configuration options with example values, the few
required options as indicated. Please edit the file to suit your needs. 
 
If you ever need help: https://torsion.org/borgmatic/#issues
 
summary:
Generate successful

The configuration file for borgmatic is located at one of the following

  • /etc/borgmatic/config.yaml (or drop-ins in /etc/borgmatic.d)
  • ~/.config/borgmatic/config.yaml (or drop-ins in ~/.config/borgmatic.d)

The configuration file allows you to define backup repositories, backup sources, retention policies, and other parameters.

Usage

Once you have configured borgmatic to your liking, you can run it using the following command:

# borgmatic --verbosity 2

This will start the backup process using the settings specified in your configuration file. borgmatic provides various options and flags that you can use to customize your backup behavior.

Borgmatic also provides systemd system and user units and timers.

Tips and tricks

Using systemd-creds to provide a password for borgmatic.service

First, encrypt the password

# systemd-ask-password -n | systemd-creds encrypt --name=borgpw -p - -
🔐 Password: *******                 
SetCredentialEncrypted=borgpw: \
        k6iUCUh0RJCQyvL8k8q1UyAAAAABAAAADAAAABAAAABODbSDtNZ8+PtlN3IAAAAAgAAAA \
        AAAAAALACMA8AAAACAAAAAAngAgRKW32QRYMvWeTcwb4SbbvK/QDF4tihGlL8OHlLKa86 \
        AAEHwr8IDsdxBmuRIXWSBGoFu8la+lTclW0/GN3OZwbvfeymJhqSoa3+76kJ1aRumQVul \
        Wvc9KxykzPhVoqFN3adVujhUkfeUmD/IMwzscsOh0hsOd8d1r2v3K8WyVv9ebk0hS1mVC \
        UzSTCNMsuKrPF2wXUP2QK5+WIjL1AE4ACAALAAAAEgAgY9RHOefBR+mMgV/Frr+UzQX1S \
        IsLFItIbfB6Ep76It0AEAAgNyMB30ZJ2HiqikmhgZfvFRZqxNRhXluH/cxMiohBDKRj1E \
        c558FH6YyBX8Wuv5TNBfVIiwsUi0ht8HoSnvoi3QAAAADffR0SV5WlPlCnJtJrhVnIXp3 \
        IO36xjF4iBmXjBfjaWhpFJ6yyY0HzHF9O1J7eNgls5aJX6Skh

Then, edit the provided borgmatic systemd service:

Note: Since systemd-creds provides credentials as files, you have to use BORG_PASSCOMMAND to provide the password
/etc/systemd/system/borgmatic.service.d/credentials.conf
[Service]
SetCredentialEncrypted=borgpw: \
        k6iUCUh0RJCQyvL8k8q1UyAAAAABAAAADAAAABAAAABODbSDtNZ8+PtlN3IAAAAAgAAAA \
        AAAAAALACMA8AAAACAAAAAAngAgRKW32QRYMvWeTcwb4SbbvK/QDF4tihGlL8OHlLKa86 \
        AAEHwr8IDsdxBmuRIXWSBGoFu8la+lTclW0/GN3OZwbvfeymJhqSoa3+76kJ1aRumQVul \
        Wvc9KxykzPhVoqFN3adVujhUkfeUmD/IMwzscsOh0hsOd8d1r2v3K8WyVv9ebk0hS1mVC \
        UzSTCNMsuKrPF2wXUP2QK5+WIjL1AE4ACAALAAAAEgAgY9RHOefBR+mMgV/Frr+UzQX1S \
        IsLFItIbfB6Ep76It0AEAAgNyMB30ZJ2HiqikmhgZfvFRZqxNRhXluH/cxMiohBDKRj1E \
        c558FH6YyBX8Wuv5TNBfVIiwsUi0ht8HoSnvoi3QAAAADffR0SV5WlPlCnJtJrhVnIXp3 \
        IO36xjF4iBmXjBfjaWhpFJ6yyY0HzHF9O1J7eNgls5aJX6Skh
Environment=BORG_PASSCOMMAND="cat %d/borgpw"