Persist Borg security state to prevent unencrypted backups failing after reboot
Problem and user impact
Unencrypted backup jobs can fail after an Unraid reboot because Borg's local repository security state is stored in the volatile root filesystem. Previously successful scheduled backups then abort with exit code 2 until the affected repository is acknowledged again.
A user reported that four previously successful weekly, unencrypted backups failed after a reboot, while an encrypted Hetzner Storage Box backup succeeded. The maintainer reproduced the complete failure and workaround on Unraid on 2026-09-08.
Warning: Attempting to access a previously unknown unencrypted repository!
Do you want to continue? [yN] Aborting.
Cache initialization aborted
terminating with error status, rc 2
ERROR: Borg create failed (exit 2)
This specific confirmation prompt concerns unencrypted repositories. The security directory itself also contains state for encrypted repositories and must be preserved for both. The error does not mean that the existing backup archives have disappeared.
Confirmed reproduction
- Before reboot, the maintainer listed
/root/.config/borg/securityand found security records for 14 repositories, includingmanifest-timestamp,key-type, andlocation. - Immediately after reboot, before a repository information refresh, the same command returned
No such file or directory:find /root/.config/borg/security -maxdepth 2 -type f -printf '%P\n' - An unencrypted backup job then failed with the exact prompt above at 14:16:59 on 2026-09-08.
- The maintainer refreshed Borg information for the affected repository in the UI. The next backup succeeded.
An isolated local reproduction with the bundled Borg 1.4.5 also confirmed:
- Creating an archive with existing security state succeeds.
- Keeping the same repository and persistent cache but using an empty security directory reproduces the prompt and exit code 2.
- Running
borg infowith the repository-scoped acknowledgement for an explicitly unencrypted repository recreates the state; a subsequent backup succeeds without that automatic answer.
The local test simulated missing security state; the maintainer's separate test confirmed an actual Unraid reboot.
Cause and code findings
- Borg 1.x defaults to
$BORG_CONFIG_DIR/security, normally/root/.config/borg/securityfor the root user. Unraid's root filesystem is loaded into RAM. api/wizard_runner.pyconfigures a persistentBORG_CACHE_DIR, but does not configure a persistentBORG_SECURITY_DIR. Keeping the cache does not prevent this confirmation prompt when security state is missing.api/borg_key_store.pyconfigures persistentBORG_KEYS_DIRstorage. That is a different directory and does not preserve Borg's security records.api/repositories_api.py::_repo_env()setsBORG_UNKNOWN_UNENCRYPTED_REPO_ACCESS_IS_OK=yesonly when the managed repository is explicitly configured with encryptionnone. The backup runner does not apply this acknowledgement.- As a result, a repository information refresh can restore the missing state before a backup and hide the problem. Unattended scheduled backups after reboot can fail instead.
These behaviors also exist on main; they were not introduced by the job-ID work in #486/#495.
References:
Verified temporary workaround
After each reboot, refresh Borg information in the repository management page for each affected unencrypted repository before running its backup. This recreates the missing local security records, and the backup can then succeed.
The workaround must be repeated after another reboot until the fix is installed. It does not require reinitializing repositories or recreating backup archives.
Requested fix and scope
- Store Borg's security state persistently below the configured plugin configuration root:
borg-security, normally/boot/config/borg-backup/borg-security. The maintainer explicitly approved the flash location; derive it fromBACKUP_SCRIPTS_DIR(including the legacyscriptssuffix), not from the runtime array/cache directory. - Use the same canonical
BORG_SECURITY_DIRconsistently for the plugin's Borg invocations, including backup execution, repository operations, maintenance, browsing/restoration, and restore tests. - Preserve existing security records for both unencrypted and encrypted repositories when adopting the persistent location, including nonce and manifest state where present. Make the transition idempotent and auditable under the existing migration rules; do not overwrite newer destination records with older state or silently discard conflicting records.
- Handle installations already affected by a reboot, where the old security directory no longer exists. Already configured unencrypted repositories must recover without requiring a manual UI refresh, while retaining existing repository and encryption validation. Any necessary acknowledgement must remain scoped to a managed repository explicitly configured as unencrypted.
- Preserve private access permissions and existing storage-availability checks. Do not silently fall back to volatile storage if the configured persistent location is unavailable.
- Add a user-facing release note describing the failure, the durable fix, and the temporary workaround.
Implement this focused fix in the existing open PR #530 together with #529, as requested by the maintainer. No new network-share audit, global permission changes, or additional security-management subsystem. No job-ID changes, archive-format changes, repository reinitialization, blanket disabling of Borg safety checks, or broad refactoring. Existing Borg key storage remains separate.
Acceptance criteria and validation
- A previously successful unencrypted job succeeds after an Unraid reboot without first opening repository information or archive browsing.
- The same scenario succeeds for an installation whose old volatile security directory is already missing.
- Backup and repository operations resolve the same persistent security directory; encrypted repository operations remain functional.
- Existing security records survive the transition and repeated starts. Cover existing destination state, conflicting records, and unavailable storage with focused tests.
- An unknown repository without the required managed, explicitly unencrypted configuration is not automatically trusted through an inherited global acknowledgement.
- Add an integration test with real Borg 1.4.5 that retains the repository/cache while simulating the disappearance of volatile security state.
- Repeat the actual Unraid reboot test with the fixed test-channel candidate. Record the exact Unraid and plugin versions, state before/after reboot, and the first backup result before any repository refresh.
- Publish and verify a test-channel candidate before stable release, following the repository workflow.