Borgmatic installation and configuration

0 Shares
0
0
0
0

Introduction

This tutorial will give you a brief introduction to Borgmatic and how to create a full system backup of your server onto your storage box. Borgmatic is a simple tool that simplifies the use of BorgBackup and extends it with some more features.

Prerequisites
  • A Linux server that you want to back up.
  • A Storage Box with enough free space and SSH keys setup.

Step 1 – Install and configure Borgmatic

In this step, we will cover how to install and configure Borgmatic.

Step 1.1 Install BorgBackup and Borgmatic

Borgmatic does not automatically include BorgBackup, so we need to install both packages manually:

apt install borgbackup borgmatic
Step 1.2 – Borgmatic Configuration

An example configuration can be created with generate

generate-borgmatic-config

This is a configuration with example values in /etc/borgmatic/conf.yml Creates.

For this tutorial, you can use the following settings:

location:
    # Here you can specify a list of Storage Boxes as backup target.
    repositories:
        - [email protected]-storagebox.de:backups

    # A list of all directoy which should be included within the backup.
    # As we want to create a full system backup "/" is sufficient.
    source_directories:
        - /

    # Exclude the default mount directory and any directories which are created at runtime.
    exclude_patterns:
        - /dev
        - /proc
        - /sys
        - /var/run
        - /run
        - /mnt
        - /tmp

storage:
    # Here you can specify the password which is used to encrypt your backups. This is _not_ your Storage Box password.
    # Do not lose this. Otherwise you are not able to restore your backup later.
    encryption_passphrase: "<SUPER SECRET PASSWORD>"

    # As BorgBackup is running on port 23 on the Storage Boxes, we have to overwrite the default ssh command in order to specify a port.
    ssh_command: "ssh -p 23"

# Here you can specify how many backups should be kept at minumim for the specified time frame.
retention:
    keep_daily: 7
    keep_weekly: 4
    keep_monthly: 6
    keep_yearly: 1
 
Step 1.3 – Setup and create the first backup

Before we can create our first backup, we first need to initialize our backup repository.

borgmatic init --encryption repokey --verbosity 1

After successful preparation, we can create our first backup.

borgmatic --verbosity 1

Depending on the size of your server, the first backup may take a while. Future backups will be faster because they are only incremental.

Step 2 – Automation

From systemctl status borgmatic.timer borgmatic.service Use to check if the service and timer already exist.

  • If an error such as Unit borgmatic.XXX could not be found If you did not receive it, you can follow the instructions below.
  • If the units are found and you can view their status, you can skip this step.

We will use a system unit and a timer to automate this. The part below that starts the backup is in /etc/systemd/system/borgmatic.service Copy.

[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

The following section is responsible for starting the backup regularly. It is located in /etc/systemd/system/borgmatic.timer Copy

[Unit]
Description=Daily backup timer

[Timer]
OnCalendar=*-*-* 16:30:00
Persistent=true

[Install]
WantedBy=timers.target

Now we just need to activate the timer:

systemctl enable --now borgmatic.timer

The timer starts a backup every day at 4:30 PM.

Result

With Borgmatic we have a simple yet powerful tool that allows us to back up our systems. We have configured it and set up automatic backups to protect against data loss.

Leave a Reply

Your email address will not be published. Required fields are marked *

You May Also Like