diff --git a/scripts/deploy-remote.sh b/scripts/deploy-remote.sh index a29f0e0..7ea83b2 100755 --- a/scripts/deploy-remote.sh +++ b/scripts/deploy-remote.sh @@ -534,10 +534,24 @@ wait_container_healthy() { # the unit; re-running the handler on an already-active unit restarts only the # selected unit. -migrate_data_root() { # $1 = old /opt path, $2 = new data-root path (same fs: rename) - local from="$1" to="$2" +migrate_data_root() { # $1 = old /opt path, $2 = new data-root path (same fs: rename/merge) + local from="$1" to="$2" entry [[ -d "$from" ]] || return 0 - mv -- "$from" "$to" + if [[ -d "$to" && -n "$(ls -A "$to" 2>/dev/null)" ]]; then + # The destination already holds seeded state (env file, rescued + # anonymous-volume data). Merge the old root into it without ever + # overwriting an existing entry, then drop the emptied source. + shopt -s dotglob + for entry in "$from"/*; do + [[ -e "$entry" ]] || continue + mv -n -- "$entry" "$to/" + done + shopt -u dotglob + rmdir -- "$from" 2>/dev/null || \ + echo "WARN: $from not empty after merge (collisions kept old side); left in place" >&2 + else + mv -- "$from" "$to" + fi chown -R "$(id -u):$(id -g)" "$to" }