Borgmatic Docker

My borgmatic-docker configuration and setup for my NAS. Based on the official borgmatic-docker but with my own setup instructions for my future self.

Initial Setup

Create the required directories for placing our configuration, borgmatic.d and other directories used by borg for caching file hashes, repo configuration, etc. These directories are then reflected in the .env later.

mkdir data/{.borgmatic,.cache,.config,.ssh,borgmatic.d}

Copy the config template and configure and make changes, such as your BorgBase repo into the list of repositories.

cp data/borgmatic.d/config.yaml.template data/borgmatic.d/config.yaml

Copy the .env.template and set required envvars within.

cp .env.template .env

SSH Keys

If you configure custom SSH key for a remote repo place the keys in your VOLUME_SSH directory. You can read about the recommended setup here on BorgBase docs.

ssh-keygen -o -a 100 -t ed25519

Backup Source Directory

It is currently assumed one directory will be backed up using the VOLUME_SOURCE directory.

You can modify this and include multiple directories as subdirectories of the containers /mnt/source directory in docker-compose.yml.

Running Backups

First you must initialize the repositories, you can use docker compose exec borgmatic init --help and go from there following online documentation.

Now, you can leave the container running normally and it will follow your crontab.txt file.

Restoring Backups

You can use the same container to restore backups. But you must give additional permissions and capabilities to the container for it to work. See docker-compose.restore.yml for a working example or reference the original borgmatic-docker repo.

Within the container mount an archive then copy the files you want to restore to the shared restore volume to access them on your machine.

References