From 4f98c40b1579937a8c7d1328daf1ba44b4cc35e1 Mon Sep 17 00:00:00 2001 From: Andras Schmelczer Date: Sun, 27 Sep 2026 20:57:02 +0100 Subject: [PATCH] Fix remote repo init --- README.md | 2 +- src/borg-common.sh | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index cd139ee..bd86b4d 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ To adhere to the [3-2-1 backup rule](https://en.wikipedia.org/wiki/Backup) witho 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. -Missing repositories are initialized automatically. An existing local directory, including the `/local-backup` bind mount, is initialized only after confirming that it is empty (including hidden files). Invalid or inaccessible repositories are rejected. +Missing repositories are initialized automatically. Existing directories, both local (including the `/local-backup` bind mount) and over SSH, are initialized only after Borg confirms that they are empty (including hidden files). Invalid or inaccessible repositories are rejected. The backup script first takes `BORG_REPO_0` and the corresponding env vars and sets up the [`BORG_REPO`](https://borgbackup.readthedocs.io/en/stable/usage/general.html#repository-urls), `BORG_REMOTE_PATH`, and `BORG_PASSPHRASE` environment variables for `borg`. Once the backup finished (successfully or otherwise), the script checks whether `BORG_REPO_1` exists, if so, it sets `BORG_REPO` and the other env vars to their expected values and backs up again. The script keeps going to `BORG_REPO_2`, `BORG_REPO_3` and so on as long as these are set. It then checks each repository with the corresponding environment before starting the next backup cycle. diff --git a/src/borg-common.sh b/src/borg-common.sh index f8b6fd6..a148674 100644 --- a/src/borg-common.sh +++ b/src/borg-common.sh @@ -6,8 +6,11 @@ borg_ensure_repository() { local status=0 borg_wait info || status=$? (( status != 0 )) || return 0 - if (( status == 13 )) || (( status == 15 )); then - echo 'Repository is missing or confirmed empty. Initializing Borg...' + # Borg 1.4 reports InvalidRepository over SSH as generic RPC exit code 2, + # even with modern exit codes enabled. Let init validate the destination: + # it accepts missing/empty directories and refuses existing data. + if (( status == 2 || status == 13 || status == 15 )); then + echo 'Repository could not be opened. Attempting Borg initialization...' status=0 borg_wait init --encryption=repokey || status=$? # Another client may have initialized it after the initial check.