资源备份流程整理
This commit is contained in:
@@ -30,6 +30,8 @@ FILES_PLAN="${WORK_DIR}/restore-files.tsv"
|
||||
DATABASES_PLAN="${WORK_DIR}/restore-databases.tsv"
|
||||
MQ_PLAN="${WORK_DIR}/restore-mq.tsv"
|
||||
ENV_FILE="${WORK_DIR}/restore-env.sh"
|
||||
STOP_COMMANDS_PLAN="${WORK_DIR}/restore-stop-commands.tsv"
|
||||
START_COMMANDS_PLAN="${WORK_DIR}/restore-start-commands.tsv"
|
||||
|
||||
json_escape() {
|
||||
local value="$1"
|
||||
@@ -131,6 +133,26 @@ replay_mq() {
|
||||
done < "${MQ_PLAN}"
|
||||
}
|
||||
|
||||
run_service_commands() {
|
||||
local plan_file="$1"
|
||||
local phase="$2"
|
||||
[[ -f "${plan_file}" ]] || return 1
|
||||
[[ -s "${plan_file}" ]] || return 1
|
||||
while IFS=$'\t' read -r code required command || [[ -n "${code:-}" ]]; do
|
||||
[[ -n "${code:-}" ]] || continue
|
||||
[[ -n "${command:-}" ]] || fail "service command is empty: ${code}" "${phase}"
|
||||
log "${phase} ${code}: ${command}"
|
||||
if bash -lc "${command}" >> "${LOG_FILE}" 2>&1; then
|
||||
log "${phase} ${code}: success"
|
||||
elif [[ "${required}" == "true" ]]; then
|
||||
fail "${phase} command failed: ${code}" "${phase}"
|
||||
else
|
||||
log "[WARN] ${phase} ${code}: failed but ignored"
|
||||
fi
|
||||
done < "${plan_file}"
|
||||
return 0
|
||||
}
|
||||
|
||||
health_check() {
|
||||
local url="${HEALTH_CHECK_URL:-}"
|
||||
[[ -n "${url}" ]] || {
|
||||
@@ -159,11 +181,19 @@ fi
|
||||
|
||||
[[ -f "${MANIFEST}" ]] || fail "payload manifest not found" "PRECHECK"
|
||||
|
||||
delay_seconds="${RESTORE_APPLY_DELAY_SECONDS:-3}"
|
||||
if [[ "${delay_seconds}" =~ ^[0-9]+$ ]] && [[ "${delay_seconds}" -gt 0 ]]; then
|
||||
write_status "RUNNING" "APPLY_DELAY" "restore apply will start"
|
||||
log "APPLY_DELAY ${delay_seconds}s"
|
||||
sleep "${delay_seconds}"
|
||||
fi
|
||||
|
||||
# 从这里开始进入停机恢复窗口。TMS_SCRIPT_PATH stop/start 允许失败后继续,
|
||||
# 因为某些部署环境可能由 systemd/外部平台接管服务状态,但文件/数据库/MQ 失败必须中断。
|
||||
write_status "RUNNING" "SERVICE_STOP" "stopping services"
|
||||
log "SERVICE_STOP"
|
||||
if [[ -n "${TMS_SCRIPT_PATH:-}" && -x "${TMS_SCRIPT_PATH}" ]]; then
|
||||
if ! run_service_commands "${STOP_COMMANDS_PLAN}" "SERVICE_STOP" \
|
||||
&& [[ -n "${TMS_SCRIPT_PATH:-}" && -x "${TMS_SCRIPT_PATH}" ]]; then
|
||||
"${TMS_SCRIPT_PATH}" stop >> "${LOG_FILE}" 2>&1 || true
|
||||
fi
|
||||
|
||||
@@ -181,7 +211,8 @@ replay_mq
|
||||
|
||||
write_status "RUNNING" "SERVICE_START" "starting services"
|
||||
log "SERVICE_START"
|
||||
if [[ -n "${TMS_SCRIPT_PATH:-}" && -x "${TMS_SCRIPT_PATH}" ]]; then
|
||||
if ! run_service_commands "${START_COMMANDS_PLAN}" "SERVICE_START" \
|
||||
&& [[ -n "${TMS_SCRIPT_PATH:-}" && -x "${TMS_SCRIPT_PATH}" ]]; then
|
||||
"${TMS_SCRIPT_PATH}" start >> "${LOG_FILE}" 2>&1 || true
|
||||
fi
|
||||
|
||||
|
||||
Reference in New Issue
Block a user