Add prefix
This commit is contained in:
parent
a57dd2e14d
commit
1b00ad849a
3 changed files with 11 additions and 1 deletions
|
|
@ -23,6 +23,8 @@ Over the past 2 years, this backup setup has enabled me to successfully restore
|
||||||
|
|
||||||
### Multi-target backups
|
### 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.
|
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.
|
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:
|
Thus, the following sets of environment variables are valid for multi-target backups:
|
||||||
|
|
||||||
- ```sh
|
- ```sh
|
||||||
|
- ARCHIVE_PREFIX=my-host-
|
||||||
- BORG_PASSPHRASE=$PASSWORD
|
- BORG_PASSPHRASE=$PASSWORD
|
||||||
- BORG_REPO=/local-backup
|
- 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
|
> This just backs up to a local repository
|
||||||
|
|
||||||
- ```sh
|
- ```sh
|
||||||
|
- ARCHIVE_PREFIX=my-host-
|
||||||
- BORG_PASSPHRASE_0=$PASSWORD
|
- BORG_PASSPHRASE_0=$PASSWORD
|
||||||
- BORG_REPO_0=/local-backup
|
- 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
|
> This just backs up to a local repository
|
||||||
|
|
||||||
- ```sh
|
- ```sh
|
||||||
|
- ARCHIVE_PREFIX=my-host-
|
||||||
- BORG_PASSPHRASE_0=$PASSWORD
|
- BORG_PASSPHRASE_0=$PASSWORD
|
||||||
- BORG_REPO_0=/local-backup
|
- 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
|
> This backs up to two different local repositories
|
||||||
|
|
||||||
- ```sh
|
- ```sh
|
||||||
|
- ARCHIVE_PREFIX=my-host-
|
||||||
- BORG_PASSPHRASE_0=$PASSWORD
|
- BORG_PASSPHRASE_0=$PASSWORD
|
||||||
- BORG_REMOTE_PATH_0=borg1
|
- BORG_REMOTE_PATH_0=borg1
|
||||||
- BORG_REPO_0=my-username@my-username.rsync.net:~/backup
|
- BORG_REPO_0=my-username@my-username.rsync.net:~/backup
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ services:
|
||||||
environment:
|
environment:
|
||||||
- TZ=Europe/London
|
- TZ=Europe/London
|
||||||
- SLEEP_TIME=1h # we will wait an hour between backups
|
- 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
|
# first backup goes to rsync.net
|
||||||
- BORG_PASSPHRASE_0=MY_PASSWORD_CHANGE_THIS
|
- BORG_PASSPHRASE_0=MY_PASSWORD_CHANGE_THIS
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
: "${ARCHIVE_PREFIX:?Set ARCHIVE_PREFIX to a non-empty archive prefix (e.g. my-host-)}"
|
||||||
|
|
||||||
KEEP_DAILY=${KEEP_DAILY:-6}
|
KEEP_DAILY=${KEEP_DAILY:-6}
|
||||||
KEEP_WEEKLY=${KEEP_WEEKLY:-3}
|
KEEP_WEEKLY=${KEEP_WEEKLY:-3}
|
||||||
KEEP_MONTHLY=${KEEP_MONTHLY:-48}
|
KEEP_MONTHLY=${KEEP_MONTHLY:-48}
|
||||||
|
|
@ -71,11 +73,12 @@ borg create --stats \
|
||||||
--filter=AMCE \
|
--filter=AMCE \
|
||||||
--files-cache=ctime,size,inode \
|
--files-cache=ctime,size,inode \
|
||||||
--compression=zstd,12 \
|
--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 -
|
cd -
|
||||||
|
|
||||||
borg prune --list --stats \
|
borg prune --list --stats \
|
||||||
|
--glob-archives="${ARCHIVE_PREFIX}*" \
|
||||||
--keep-daily="$KEEP_DAILY" \
|
--keep-daily="$KEEP_DAILY" \
|
||||||
--keep-weekly="$KEEP_WEEKLY" \
|
--keep-weekly="$KEEP_WEEKLY" \
|
||||||
--keep-monthly="$KEEP_MONTHLY" \
|
--keep-monthly="$KEEP_MONTHLY" \
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue