deploy-remote: migrate_data_root merges into pre-seeded destinations

mv of a data root onto a non-empty directory fails (Directory not empty).
The romm/copyparty cutover creates Containers/<svc>/ before migrating:
the seed env file lands there first, and the romm anonymous-volume rescue
extracts into it before the /opt move. Merge the old root's entries in
without overwriting existing state (mv -n), warn and leave residue if a
collision kept the new side, and keep the plain rename when the
destination is absent or empty.
This commit is contained in:
Frank
2026-09-01 13:38:31 -07:00
parent 9e904d23a3
commit cdfaf48191
+17 -3
View File
@@ -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"
}