diff --git a/scripts/release-portal-runtime-prod.sh b/scripts/release-portal-runtime-prod.sh index e0f95f5..35b7359 100755 --- a/scripts/release-portal-runtime-prod.sh +++ b/scripts/release-portal-runtime-prod.sh @@ -406,6 +406,37 @@ say "校验产物完整性" cd "${INCOMING_DIR}" shasum -a 256 -c "$(basename "${SHA_FILE}")" +copy_persisted_item() { + local src="$1" + local dest_root="$2" + local item="$3" + mkdir -p "${dest_root}" + if [[ -d "${src}" ]]; then + local pipe_status tar_status extract_status + set +e + ( + cd "${APP_DIR}" + COPYFILE_DISABLE=1 tar --exclude='*.sock' -cf - "${item}" + ) | ( + cd "${dest_root}" + COPYFILE_DISABLE=1 tar -xf - + ) + pipe_status=("${PIPESTATUS[@]}") + tar_status=${pipe_status[0]:-0} + extract_status=${pipe_status[1]:-0} + set -e + if [[ "${extract_status}" -ne 0 ]]; then + echo "failed to extract persisted item ${item}" >&2 + exit "${extract_status}" + fi + if [[ "${tar_status}" -ne 0 ]]; then + echo "warning: persisted item ${item} changed during copy; continuing with partial snapshot" >&2 + fi + else + cp -a "${src}" "${dest_root}/" + fi +} + say "备份当前 live 全目录" COPYFILE_DISABLE=1 tar --exclude='Memind/.tailscale/*.sock' \ -czf "${FULL_BACKUP_TAR}" -C "$(dirname "${APP_DIR}")" "$(basename "${APP_DIR}")" @@ -425,7 +456,7 @@ for item in "${PERSISTED_ITEMS[@]}"; do tar -xf - ) else - cp -a "${APP_DIR}/${item}" "${tmp_persist_dir}/$(dirname "${item}")/" + copy_persisted_item "${APP_DIR}/${item}" "${tmp_persist_dir}" "${item}" fi fi done @@ -458,7 +489,7 @@ for item in "${PERSISTED_ITEMS[@]}"; do tar -xf - ) else - cp -a "${APP_DIR}/${item}" "$(dirname "${RUNTIME_DIR}/${item}")/" + copy_persisted_item "${APP_DIR}/${item}" "${RUNTIME_DIR}" "${item}" fi fi done