Make Nextcloud NAS backups independent, verified and retryable
This commit is contained in:
1 parent
ffe3c354be
commit
7e94915442
15 files changed
+889
-504
No files matched your search
+37
-13
@@ -10,8 +10,17 @@ CONFIG_DIR="${XDG_CONFIG_HOME:-${HOME}/.config}/${APP_NAME}"
|
||||
STATE_DIR="${XDG_STATE_HOME:-${HOME}/.local/state}/${APP_NAME}"
|
||||
SYSTEMD_USER_DIR="${XDG_CONFIG_HOME:-${HOME}/.config}/systemd/user"
|
||||
|
||||
mkdir -p "$BIN_DIR" "$CONFIG_DIR" "$STATE_DIR/logs" "$SYSTEMD_USER_DIR"
|
||||
for required in python3 borg rclone findmnt flock timeout systemctl; do
|
||||
command -v "$required" >/dev/null || { printf 'Missing dependency: %s\n' "$required" >&2; exit 1; }
|
||||
done
|
||||
[[ "$(borg --version)" == 'borg 1.'* ]] || { printf 'Borg 1.x required\n' >&2; exit 1; }
|
||||
|
||||
EXISTING_CONFIG=false
|
||||
[[ ! -f "$CONFIG_DIR/config" ]] || EXISTING_CONFIG=true
|
||||
|
||||
mkdir -p "${HOME}/.local/libexec" "$BIN_DIR" "$CONFIG_DIR" "$STATE_DIR/logs" "$SYSTEMD_USER_DIR"
|
||||
|
||||
install -m 0750 "$ROOT_DIR/scripts/nextcloud-borg-runner.py" "${HOME}/.local/libexec/nextcloud-borg-runner.py"
|
||||
install -m 0750 "$ROOT_DIR/scripts/nextcloud-borg-backup" "$BIN_DIR/nextcloud-borg-backup"
|
||||
|
||||
if [[ ! -f "$CONFIG_DIR/config" ]]; then
|
||||
@@ -25,23 +34,38 @@ if [[ ! -f "$CONFIG_DIR/excludes" ]]; then
|
||||
install -m 0600 "$ROOT_DIR/etc/excludes.example" "$CONFIG_DIR/excludes"
|
||||
fi
|
||||
|
||||
if [[ ! -f "$CONFIG_DIR/passphrase" ]]; then
|
||||
if command -v openssl >/dev/null 2>&1; then
|
||||
openssl rand -base64 48 > "$CONFIG_DIR/passphrase"
|
||||
else
|
||||
od -An -tx1 -N48 /dev/urandom | tr -d ' \n' > "$CONFIG_DIR/passphrase"
|
||||
printf '\n' >> "$CONFIG_DIR/passphrase"
|
||||
# Respect installations that store the original key at a custom path.
|
||||
KEY_PATH="$(source "$CONFIG_DIR/config"; printf '%s' "${BORG_PASSPHRASE_FILE:-$CONFIG_DIR/passphrase}")"
|
||||
if [[ ! -f "$KEY_PATH" ]]; then
|
||||
if [[ "$EXISTING_CONFIG" == true ]]; then
|
||||
printf 'Existing installation but missing default passphrase. Restore the key or check the configured key path before updating.\n' >&2
|
||||
exit 1
|
||||
fi
|
||||
chmod 0600 "$CONFIG_DIR/passphrase"
|
||||
printf 'Created Borg passphrase file: %s\n' "$CONFIG_DIR/passphrase"
|
||||
# Never replace a missing key for an existing encrypted repository with random data.
|
||||
if [[ -f "$CONFIG_DIR/config" ]]; then
|
||||
source "$CONFIG_DIR/config"
|
||||
if timeout 30 test -f "${REPO_DIR:-/net/thor/volume1/NetBackup/Nextcloud/borg-repo}/config"; then
|
||||
printf 'Existing repository but missing passphrase; restore the original key first.\n' >&2
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
if command -v openssl >/dev/null 2>&1; then
|
||||
openssl rand -base64 48 > "$KEY_PATH"
|
||||
else
|
||||
od -An -tx1 -N48 /dev/urandom | tr -d ' \n' > "$KEY_PATH"
|
||||
printf '\n' >> "$KEY_PATH"
|
||||
fi
|
||||
chmod 0600 "$KEY_PATH"
|
||||
printf 'Created Borg passphrase file: %s\n' "$KEY_PATH"
|
||||
printf 'Store a copy of this passphrase somewhere safe for disaster recovery.\n'
|
||||
fi
|
||||
|
||||
install -m 0644 "$ROOT_DIR/systemd/user/nextcloud-borg-backup.service" "$SYSTEMD_USER_DIR/nextcloud-borg-backup.service"
|
||||
install -m 0644 "$ROOT_DIR/systemd/user/nextcloud-borg-backup.timer" "$SYSTEMD_USER_DIR/nextcloud-borg-backup.timer"
|
||||
|
||||
for unit in nextcloud-borg-backup.service nextcloud-borg-backup.timer nextcloud-borg-health.service nextcloud-borg-health.timer; do
|
||||
install -m 0644 "$ROOT_DIR/systemd/user/$unit" "$SYSTEMD_USER_DIR/$unit"
|
||||
done
|
||||
systemctl --user daemon-reload
|
||||
systemctl --user enable --now nextcloud-borg-backup.timer
|
||||
systemctl --user enable nextcloud-borg-backup.timer nextcloud-borg-health.timer
|
||||
systemctl --user restart nextcloud-borg-backup.timer nextcloud-borg-health.timer
|
||||
|
||||
printf '\nInstalled %s.\n' "$APP_NAME"
|
||||
printf 'Next steps:\n'
|
||||
|
||||
Reference in new issue
Block a user