From 8f7fb11bc7d2fc8c3ead2278d7b3cf33ab1d2525 Mon Sep 17 00:00:00 2001 From: buildplan <170122315+buildplan@users.noreply.github.com> Date: Mon, 2 Feb 2026 17:53:04 +0000 Subject: [PATCH 1/7] restore exact ownership --- restic-backup.sh | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/restic-backup.sh b/restic-backup.sh index 68f6985..1c5f250 100644 --- a/restic-backup.sh +++ b/restic-backup.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # ================================================================= -# Restic Backup Script v0.42 - 2025.12.17 +# Restic Backup Script v0.43 - 2026.02.02 # ================================================================= export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:$PATH @@ -9,7 +9,7 @@ set -euo pipefail umask 077 # --- Script Constants --- -SCRIPT_VERSION="0.42" +SCRIPT_VERSION="0.43" SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) PROG_NAME=$(basename "$0"); readonly PROG_NAME CONFIG_FILE="${SCRIPT_DIR}/restic-backup.conf" @@ -1473,6 +1473,18 @@ run_restore() { fi log_message "WARNING: User confirmed dangerous restore to: $restore_dest" fi + + echo -e "\n${C_YELLOW}Ownership Handling:${C_RESET}" + echo " n) Auto-fix ownership (Best for standard user files in /home)" + echo " y) Preserve exact backup UIDs/GIDs (Required for Docker/Databases)" + read -rp "Preserve exact raw ownership? (y/n) [n]: " preserve_confirm + if [[ "${preserve_confirm,,}" == "y" || "${preserve_confirm,,}" == "yes" ]]; then + SKIP_OWNERSHIP_FIX=true + echo -e "${C_CYAN}ℹ️ Exact ownership will be preserved (no auto-fix).${C_RESET}" + else + SKIP_OWNERSHIP_FIX=false + fi + local include_paths=() read -rp "Optional: Enter specific file(s) to restore, separated by spaces (leave blank for full restore): " -a include_paths local restic_cmd=(restic restore "$snapshot_id" --target "$restore_dest" --verbose) @@ -1535,6 +1547,11 @@ run_restore() { _handle_restore_ownership() { local restore_dest="$1" + if [[ "${SKIP_OWNERSHIP_FIX:-false}" == "true" ]]; then + log_message "Skipping ownership fix (Exact ownership requested)." + return 0 + fi + if [[ "$restore_dest" == /home/* ]]; then local dest_user dest_user=$(stat -c %U "$(dirname "$restore_dest")" 2>/dev/null || echo "${restore_dest#/home/}" | cut -d/ -f1) @@ -1754,6 +1771,7 @@ EOF # 1. Parse flags. VERBOSE_MODE=false +SKIP_OWNERSHIP_FIX=false AUTO_FIX_PERMS=${AUTO_FIX_PERMS:-false} while [[ $# -gt 0 ]]; do case "$1" in @@ -1761,6 +1779,10 @@ while [[ $# -gt 0 ]]; do VERBOSE_MODE=true shift ;; + --exact-ownership) + SKIP_OWNERSHIP_FIX=true + shift + ;; --fix-permissions) if ! [ -t 0 ]; then echo -e "${C_RED}ERROR: The --fix-permissions flag can only be used in an interactive session.${C_RESET}" >&2 From da5fa2dffc3225b318a2a2b3d61caf9b90a8d8d5 Mon Sep 17 00:00:00 2001 From: buildplan <170122315+buildplan@users.noreply.github.com> Date: Mon, 2 Feb 2026 18:00:23 +0000 Subject: [PATCH 2/7] Add --exact-ownership option Added a new option to preserve raw ownership during restore operations. --- restic-backup.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/restic-backup.sh b/restic-backup.sh index 1c5f250..ccb721f 100644 --- a/restic-backup.sh +++ b/restic-backup.sh @@ -63,6 +63,7 @@ display_help() { printf " ${C_GREEN}%-20s${C_RESET} %s\n" "--unlock" "Remove stale repository locks." printf " ${C_GREEN}%-20s${C_RESET} %s\n" "--dump " "Dump a single file from a snapshot to stdout." printf " ${C_GREEN}%-20s${C_RESET} %s\n" "--restore" "Interactive restore wizard." + printf " ${C_GREEN}%-20s${C_RESET} %s\n" "--exact-ownership" "Perserve raw ownership, to use with restore flags." printf " ${C_GREEN}%-20s${C_RESET} %s\n" "--ls " "List files and directories inside a specific snapshot." printf " ${C_GREEN}%-20s${C_RESET} %s\n" "--find " "Search for files/dirs across all snapshots (e.g., --find \"*.log\" -l)." printf " ${C_GREEN}%-20s${C_RESET} %s\n" "--background-restore" "Run a non-interactive restore in the background." From 052fa56b3739a0d3aac7fc879cdb04c0e2b43a6d Mon Sep 17 00:00:00 2001 From: buildplan Date: Mon, 2 Feb 2026 21:57:17 +0000 Subject: [PATCH 3/7] checksum v0.43 --- container-monitor.sh.sha256 | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 container-monitor.sh.sha256 diff --git a/container-monitor.sh.sha256 b/container-monitor.sh.sha256 new file mode 100644 index 0000000..e69de29 From bc6231ca4a63fc2f03d588bbcddff48388fcf873 Mon Sep 17 00:00:00 2001 From: buildplan Date: Mon, 2 Feb 2026 21:58:13 +0000 Subject: [PATCH 4/7] checksum v0.43 --- restic-backup.sh.sha256 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/restic-backup.sh.sha256 b/restic-backup.sh.sha256 index f7f9d4f..facc196 100644 --- a/restic-backup.sh.sha256 +++ b/restic-backup.sh.sha256 @@ -1 +1 @@ -a7206371dd37d9803bd1df98083332c55f570da8bc6be3ac8a7e7538356d6430 restic-backup.sh +4e18685152b207f58c8f8ed0b433c4750737af631811aca8412fb9b626e24161 restic-backup.sh From 26b05a4bbcb805016c5a0680732ce32bcb6a0d4c Mon Sep 17 00:00:00 2001 From: buildplan Date: Mon, 2 Feb 2026 21:59:07 +0000 Subject: [PATCH 5/7] remove --- container-monitor.sh.sha256 | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 container-monitor.sh.sha256 diff --git a/container-monitor.sh.sha256 b/container-monitor.sh.sha256 deleted file mode 100644 index e69de29..0000000 From f7dc52e9ce98e987cd05ed1f1e1a43eace5f1b07 Mon Sep 17 00:00:00 2001 From: buildplan Date: Mon, 2 Feb 2026 22:35:50 +0000 Subject: [PATCH 6/7] smarter restore permissions --- restic-backup.sh | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/restic-backup.sh b/restic-backup.sh index ccb721f..9743e24 100644 --- a/restic-backup.sh +++ b/restic-backup.sh @@ -1485,7 +1485,7 @@ run_restore() { else SKIP_OWNERSHIP_FIX=false fi - + local include_paths=() read -rp "Optional: Enter specific file(s) to restore, separated by spaces (leave blank for full restore): " -a include_paths local restic_cmd=(restic restore "$snapshot_id" --target "$restore_dest" --verbose) @@ -1547,23 +1547,23 @@ run_restore() { _handle_restore_ownership() { local restore_dest="$1" - - if [[ "${SKIP_OWNERSHIP_FIX:-false}" == "true" ]]; then - log_message "Skipping ownership fix (Exact ownership requested)." - return 0 - fi - + local dest_user="" if [[ "$restore_dest" == /home/* ]]; then - local dest_user dest_user=$(stat -c %U "$(dirname "$restore_dest")" 2>/dev/null || echo "${restore_dest#/home/}" | cut -d/ -f1) - - if [[ -n "$dest_user" ]] && id -u "$dest_user" &>/dev/null; then - log_message "Home directory detected. Setting ownership of restored files to '$dest_user'." - if chown -R "${dest_user}:${dest_user}" "$restore_dest"; then - log_message "Successfully changed ownership of $restore_dest to $dest_user" - else - log_message "WARNING: Failed to change ownership of $restore_dest to $dest_user. Please check permissions manually." - fi + fi + if [[ -n "$dest_user" ]] && id -u "$dest_user" &>/dev/null; then + if [ -d "$restore_dest" ]; then + chown "$dest_user:$dest_user" "$restore_dest" + fi + if [[ "${SKIP_OWNERSHIP_FIX:-false}" == "true" ]]; then + log_message "Exact ownership requested: Fixed access to $restore_dest, but preserved raw IDs inside." + return 0 + fi + log_message "Home directory detected. Recursively setting ownership to '$dest_user'." + if chown -R "${dest_user}:${dest_user}" "$restore_dest"; then + log_message "Successfully changed ownership of $restore_dest to $dest_user" + else + log_message "WARNING: Failed to change ownership of $restore_dest. Check permissions." fi fi } From 910ae610e4fbb0f21e9c3f26be2b19f5baf6e25b Mon Sep 17 00:00:00 2001 From: buildplan Date: Mon, 2 Feb 2026 22:36:25 +0000 Subject: [PATCH 7/7] checksum v0.43 --- restic-backup.sh.sha256 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/restic-backup.sh.sha256 b/restic-backup.sh.sha256 index facc196..2e53876 100644 --- a/restic-backup.sh.sha256 +++ b/restic-backup.sh.sha256 @@ -1 +1 @@ -4e18685152b207f58c8f8ed0b433c4750737af631811aca8412fb9b626e24161 restic-backup.sh +260732b0a22a5ed4bde396e09bf803481c72202d9600bf0609e5d6a362951c67 restic-backup.sh