From 1b00ad849a9e80a466759499ad582694f7af5e9f Mon Sep 17 00:00:00 2001 From: Andras Schmelczer Date: Mon, 21 Sep 2026 20:55:49 +0100 Subject: [PATCH] Add prefix --- README.md | 6 ++++++ docker-compose.yml | 1 + src/backup.sh | 5 ++++- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7ffd082..bf38fe0 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,8 @@ Over the past 2 years, this backup setup has enabled me to successfully restore ### Multi-target backups +Set the required `ARCHIVE_PREFIX` environment variable to a non-empty prefix shared by all backup targets. Include any separator in the value: `ARCHIVE_PREFIX=my-host-` creates archives named `my-host-{now:%Y-%m-%dT%H:%M:%S}`. Pruning uses the glob `${ARCHIVE_PREFIX}*`, so retention rules only apply to matching archives. To continue pruning existing archives, set the prefix to their previous hostname followed by `-`. + To adhere to the [3-2-1 backup rule](https://en.wikipedia.org/wiki/Backup) without disk-level redundancy, you can configure backups to multiple destinations. For example, backups can be sent simultaneously to [rsync.net](rsync.net) and a local HDD. The [`docker-compose.yml`](docker-compose.yml) file demonstrates how to set up multiple backup targets using environment variables such as `BORG_REPO_0`, `BORG_REPO_1`, `BORG_PASSPHRASE_0`, `BORG_PASSPHRASE_1`, and so forth. The backup script sequentially handles each repository defined by the environment variables, ensuring your source volume is backed up across all specified targets. @@ -32,6 +34,7 @@ The backup script first takes `BORG_REPO_0` and the corresponding env vars and s Thus, the following sets of environment variables are valid for multi-target backups: - ```sh + - ARCHIVE_PREFIX=my-host- - BORG_PASSPHRASE=$PASSWORD - BORG_REPO=/local-backup ``` @@ -39,6 +42,7 @@ Thus, the following sets of environment variables are valid for multi-target bac > This just backs up to a local repository - ```sh + - ARCHIVE_PREFIX=my-host- - BORG_PASSPHRASE_0=$PASSWORD - BORG_REPO_0=/local-backup ``` @@ -46,6 +50,7 @@ Thus, the following sets of environment variables are valid for multi-target bac > This just backs up to a local repository - ```sh + - ARCHIVE_PREFIX=my-host- - BORG_PASSPHRASE_0=$PASSWORD - BORG_REPO_0=/local-backup @@ -56,6 +61,7 @@ Thus, the following sets of environment variables are valid for multi-target bac > This backs up to two different local repositories - ```sh + - ARCHIVE_PREFIX=my-host- - BORG_PASSPHRASE_0=$PASSWORD - BORG_REMOTE_PATH_0=borg1 - BORG_REPO_0=my-username@my-username.rsync.net:~/backup diff --git a/docker-compose.yml b/docker-compose.yml index 7c56ea5..4fedfa7 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -6,6 +6,7 @@ services: environment: - TZ=Europe/London - SLEEP_TIME=1h # we will wait an hour between backups + - ARCHIVE_PREFIX=my-host- # required; include any separator before the timestamp # first backup goes to rsync.net - BORG_PASSPHRASE_0=MY_PASSWORD_CHANGE_THIS diff --git a/src/backup.sh b/src/backup.sh index 11a6611..a265356 100755 --- a/src/backup.sh +++ b/src/backup.sh @@ -1,5 +1,7 @@ #!/bin/bash +: "${ARCHIVE_PREFIX:?Set ARCHIVE_PREFIX to a non-empty archive prefix (e.g. my-host-)}" + KEEP_DAILY=${KEEP_DAILY:-6} KEEP_WEEKLY=${KEEP_WEEKLY:-3} KEEP_MONTHLY=${KEEP_MONTHLY:-48} @@ -71,11 +73,12 @@ borg create --stats \ --filter=AMCE \ --files-cache=ctime,size,inode \ --compression=zstd,12 \ - "${EXCLUDE_ARGS[@]}" ::"{hostname}-{now:%Y-%m-%dT%H:%M:%S}" . + "${EXCLUDE_ARGS[@]}" ::"${ARCHIVE_PREFIX}{now:%Y-%m-%dT%H:%M:%S}" . cd - borg prune --list --stats \ + --glob-archives="${ARCHIVE_PREFIX}*" \ --keep-daily="$KEEP_DAILY" \ --keep-weekly="$KEEP_WEEKLY" \ --keep-monthly="$KEEP_MONTHLY" \