资源备份恢复

This commit is contained in:
waner
2026-04-20 10:15:25 +08:00
parent 350fa4d89d
commit 2efdc047e3
26 changed files with 1712 additions and 329 deletions
+64
View File
@@ -0,0 +1,64 @@
#!/usr/bin/env bash
set -euo pipefail
MYSQL_PATH="mysql"
HOST=""
PORT=""
USERNAME=""
PASSWORD=""
DB_NAME=""
SQL_FILE=""
while [[ $# -gt 0 ]]; do
case "$1" in
--mysql-path)
MYSQL_PATH="${2:-}"
shift 2
;;
--host)
HOST="${2:-}"
shift 2
;;
--port)
PORT="${2:-}"
shift 2
;;
--username)
USERNAME="${2:-}"
shift 2
;;
--password)
PASSWORD="${2:-}"
shift 2
;;
--db-name)
DB_NAME="${2:-}"
shift 2
;;
--sql-file)
SQL_FILE="${2:-}"
shift 2
;;
*)
echo "[ERROR] unsupported argument: $1" >&2
exit 1
;;
esac
done
if [[ -z "${HOST}" || -z "${PORT}" || -z "${USERNAME}" || -z "${DB_NAME}" || -z "${SQL_FILE}" ]]; then
echo "[ERROR] missing required database restore arguments" >&2
exit 1
fi
if [[ ! -f "${SQL_FILE}" ]]; then
echo "[ERROR] sql file not found: ${SQL_FILE}" >&2
exit 1
fi
"${MYSQL_PATH}" \
--host="${HOST}" \
--port="${PORT}" \
--user="${USERNAME}" \
--password="${PASSWORD}" \
"${DB_NAME}" < "${SQL_FILE}"
+48
View File
@@ -0,0 +1,48 @@
#!/usr/bin/env bash
set -euo pipefail
HANDOFF_FILE=""
while [[ $# -gt 0 ]]; do
case "$1" in
--handoff-file)
HANDOFF_FILE="${2:-}"
shift 2
;;
*)
echo "[ERROR] unsupported argument: $1" >&2
exit 1
;;
esac
done
if [[ -z "${HANDOFF_FILE}" ]]; then
echo "[ERROR] --handoff-file is required" >&2
exit 1
fi
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
SOURCE_ROOT="$(cd "${SCRIPT_DIR}/../.." && pwd)"
APP_HOME="${APP_HOME:-/home/tms}"
CONF_DIR="${CONF_DIR:-${APP_HOME}/config}"
JAVA_BIN="${JAVA_BIN:-java}"
RUNNER_JAR_PATH="${RUNNER_JAR_PATH:-${APP_HOME}/tms-framework.jar}"
RUNNER_LOG_DIR="${RUNNER_LOG_DIR:-${APP_HOME}/logs}"
RUNNER_STDOUT_LOG="${RUNNER_STDOUT_LOG:-${RUNNER_LOG_DIR}/resource-restore-runner.out.log}"
if [[ -f "${SOURCE_ROOT}/target/tms-framework.jar" ]]; then
RUNNER_JAR_PATH="${SOURCE_ROOT}/target/tms-framework.jar"
fi
mkdir -p "${RUNNER_LOG_DIR}"
nohup "${JAVA_BIN}" \
-cp "${RUNNER_JAR_PATH}" \
-Dloader.main=com.cisd.tms.modules.backup.runner.ResourceRestoreRunnerMain \
org.springframework.boot.loader.launch.PropertiesLauncher \
--spring.main.web-application-type=none \
--spring.main.banner-mode=off \
--spring.config.additional-location="optional:file:${CONF_DIR}/" \
--tms.backup.runner-handoff-file="${HANDOFF_FILE}" \
>> "${RUNNER_STDOUT_LOG}" 2>&1 &
echo $!