The main sweep — ~260 call sites across ~100 files move from string
concatenation on a single root to appDir/storageAppDirs/storageAppConfigs.
On a single-root install the resolved paths are identical, so this is a
no-op until a location is registered.
Enumerators were the interesting half. `for d in "$containers_dir"/*/`
appears in the menus, the registry/artifact scanners and the DNS setup —
and a shell glob cannot list a rootless 751 tree at all, which is the
same bug config_find_file.sh already documents in a comment. Routing them
through storageAppDirs (which enumerates as the owning user) fixes that
alongside the multi-root work.
Three places needed judgement rather than substitution:
db_app_scan.sh deletes database rows and port allocations for apps whose
folder is missing, and reaps "empty" app dirs. With a storage location
unmounted, every app on it looks exactly like that. Each of those
branches now gates on appStorageAvailable first — an app on an unplugged
drive is skipped with a notice, never deleted.
instance_create.sh rewrites cloned hooks so an instance touches its own
directory instead of the base app's. Its sed matched ${containers_dir}<type>,
which this sweep just replaced with $(appDir <type>) — so it would have
silently stopped redirecting, and an instance would have written to the
original's files (the adguard auth adapter case its own comment warns
about). Now matches both appDir forms, verified against bare, quoted,
unrelated-app, legacy and prose cases.
peer_shell/peer_pull streamed and extracted relative to the primary root.
Both now use the app's own root, and peer_shell keeps a single-root
fallback since it runs as a restricted SSH shell with no LibrePortal env.
Also fixes a pre-existing bug found on the way: webui_app_config.sh
tested "$containers_dir/frontend/data/last_update", one level short of the
real tree under the libreportal app dir, so the WebUI refresh trigger
after a config update has never once fired.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
151 lines
4.6 KiB
Bash
151 lines
4.6 KiB
Bash
#!/bin/bash
|
|
|
|
restoreAppStart()
|
|
{
|
|
local app_name="$1"
|
|
local snapshot_arg="$2"
|
|
local location_idx="$3"
|
|
local host_filter="$4"
|
|
local stored_app_name="$app_name"
|
|
|
|
if [[ -z "$app_name" ]]; then
|
|
isError "restoreAppStart called with empty app_name"
|
|
return 1
|
|
fi
|
|
|
|
if [[ -z "$(resticEnabledLocations)" ]]; then
|
|
isError "No backup locations enabled — cannot restore"
|
|
return 1
|
|
fi
|
|
|
|
isHeader "Restoring $stored_app_name"
|
|
|
|
local restore_started_at
|
|
restore_started_at=$(date -Iseconds)
|
|
isNotice "Task started: restore $stored_app_name at $restore_started_at"
|
|
|
|
((menu_number++))
|
|
echo ""
|
|
echo "---- $menu_number. Picking backup"
|
|
echo ""
|
|
local pick
|
|
pick=$(restorePickSnapshot "$stored_app_name" "$location_idx" "$snapshot_arg" "$host_filter")
|
|
if [[ -z "$pick" ]]; then
|
|
isError "No backup to restore from"
|
|
return 1
|
|
fi
|
|
local chosen_idx="${pick%%:*}"
|
|
local chosen_id="${pick##*:}"
|
|
isSuccessful "Using backup ${chosen_id:0:8} from $(resticLocationName "$chosen_idx")"
|
|
|
|
((menu_number++))
|
|
echo ""
|
|
echo "---- $menu_number. Setting up install folder and config for $stored_app_name"
|
|
echo ""
|
|
dockerConfigSetupToContainer "loud" "$stored_app_name" "install"
|
|
initializeAppVariables "$stored_app_name"
|
|
|
|
((menu_number++))
|
|
echo ""
|
|
echo "---- $menu_number. Shutting down container(s) for restoration"
|
|
echo ""
|
|
dockerComposeDown "$stored_app_name"
|
|
|
|
((menu_number++))
|
|
echo ""
|
|
echo "---- $menu_number. Wiping existing app folder"
|
|
echo ""
|
|
if [[ -d "$(appDir "$stored_app_name")" ]]; then
|
|
# Root-owned helper, not runFileOp — restoring over an app that left
|
|
# sub-UID data behind (postgres, www-data, …) needs to actually wipe
|
|
# those dirs before laying the snapshot down.
|
|
runOwnership app-data-remove "$stored_app_name"
|
|
fi
|
|
|
|
((menu_number++))
|
|
echo ""
|
|
echo "---- $menu_number. Running pre-restore hook (if present)"
|
|
echo ""
|
|
restoreAppRunHook "$stored_app_name" pre
|
|
|
|
((menu_number++))
|
|
echo ""
|
|
echo "---- $menu_number. Restoring snapshot ${chosen_id:0:8}"
|
|
echo ""
|
|
local include_path="$(appDir "$stored_app_name")"
|
|
engineRestoreSnapshot "$chosen_idx" "$chosen_id" "/" "$include_path"
|
|
if [[ $? -ne 0 ]]; then
|
|
isError "Restore failed — leaving app in stopped state"
|
|
return 1
|
|
fi
|
|
# NO blanket chown here. The snapshot's ownership is the thing being restored:
|
|
# container-owned data (postgres, mongo, prometheus' store) must come back
|
|
# under the container's uid or the app will not boot. resticRestoreSnapshot
|
|
# now recreates those uids faithfully, and this line could only ever undo
|
|
# that — it used to run as the docker install user, so against a correctly
|
|
# restored tree it just fails file by file, and where it did "work" it was
|
|
# cementing the ownership that broke the app.
|
|
|
|
((menu_number++))
|
|
echo ""
|
|
echo "---- $menu_number. Rehydrating databases + files (pre-start)"
|
|
echo ""
|
|
restoreDbRehydratePreStart "$stored_app_name"
|
|
restoreFilesRehydratePreStart "$stored_app_name"
|
|
|
|
((menu_number++))
|
|
echo ""
|
|
echo "---- $menu_number. Updating docker compose file(s)"
|
|
echo ""
|
|
dockerComposeUpdateAndStartApp "$stored_app_name" install
|
|
|
|
((menu_number++))
|
|
echo ""
|
|
echo "---- $menu_number. Fixing permissions before starting"
|
|
echo ""
|
|
fixPermissionsBeforeStart "$stored_app_name"
|
|
|
|
((menu_number++))
|
|
echo ""
|
|
echo "---- $menu_number. Starting up the $stored_app_name docker service(s)"
|
|
echo ""
|
|
dockerComposeUp "$stored_app_name"
|
|
|
|
((menu_number++))
|
|
echo ""
|
|
echo "---- $menu_number. Running post-restore hook (if present)"
|
|
echo ""
|
|
restoreAppRunHook "$stored_app_name" post
|
|
|
|
((menu_number++))
|
|
echo ""
|
|
echo "---- $menu_number. Loading database dumps (post-start)"
|
|
echo ""
|
|
restoreDbReplayPostStart "$stored_app_name"
|
|
|
|
((menu_number++))
|
|
echo ""
|
|
echo "---- $menu_number. Logging restore into database"
|
|
echo ""
|
|
databaseRestoreInsert "$stored_app_name"
|
|
databaseInstallApp "$stored_app_name"
|
|
|
|
((menu_number++))
|
|
echo ""
|
|
echo "---- $menu_number. Running Headscale setup (if required)"
|
|
echo ""
|
|
setupHeadscale "$stored_app_name"
|
|
|
|
((menu_number++))
|
|
echo ""
|
|
echo "---- $menu_number. Running app-specific updates (if required)"
|
|
echo ""
|
|
appUpdateSpecifics "$stored_app_name"
|
|
|
|
local restore_finished_at
|
|
restore_finished_at=$(date -Iseconds)
|
|
isSuccessful "Task finished: restore $stored_app_name at $restore_finished_at (started $restore_started_at)"
|
|
|
|
menu_number=0
|
|
}
|