mirror of
https://github.com/hpd840321/starRiverProperty.git
synced 2026-06-09 08:20:31 +08:00
Initial commit: reorganized source tree
- backend/: 13 Maven modules (cw-elevator-application, cloudwalk-cloud, intelligent-cwoscomponent, ninca-crk, etc.) - frontend/: 4 Vue projects (elevator-front, cwos-portal, alarm-front, front_acs) + decompiled + scripts - scripts/: build, test-env, tools (Docker Compose, service templates, API parity) - docs/: AGENTS.md, superpowers specs, architecture docs - .gitignore: standard Java/Maven exclusions Moved from legacy maven-*/ root layout to backend/ organized structure.
This commit is contained in:
Executable
+91
@@ -0,0 +1,91 @@
|
||||
#!/bin/bash
|
||||
# prepare-db.sh — 恢复 11 个数据库 SQL 备份到 MySQL
|
||||
source "$(dirname "${BASH_SOURCE[0]}")/config/env.sh"
|
||||
|
||||
log_info "Phase 2: Database preparation"
|
||||
log_info "Target: $MYSQL_HOST:$MYSQL_PORT (user: $MYSQL_USER)"
|
||||
|
||||
MYSQL_CMD="mysql -h $MYSQL_HOST -P $MYSQL_PORT -u $MYSQL_USER -p${MYSQL_PASS}"
|
||||
|
||||
# Check MySQL connectivity
|
||||
if ! $MYSQL_CMD -e "SELECT 1" &>/dev/null; then
|
||||
log_error "Cannot connect to MySQL at $MYSQL_HOST:$MYSQL_PORT"
|
||||
exit 1
|
||||
fi
|
||||
log_ok "MySQL connection OK"
|
||||
|
||||
# DB name → backup file mapping
|
||||
declare -A DB_MAP=(
|
||||
["$DB_ELEVATOR"]="12_2026_04_23_17_28_33.sql.gz"
|
||||
["$DB_ALARM"]="alarm_deploy_2026_04_23_17_28_33.sql.gz"
|
||||
["$DB_MANAGER"]="cwos_manager_2026_04_23_17_28_33.sql.gz"
|
||||
["$DB_PORTAL"]="cwos_portal_2026_04_23_17_28_33.sql.gz"
|
||||
["$DB_COMMON"]="ninca_common_2026_04_23_17_28_33.sql.gz"
|
||||
["$DB_COMPONENT_ORG"]="component-organization_2026_04_23_17_28_33.sql.gz"
|
||||
["$DB_ODS"]="ods_2026_04_23_17_28_33.sql.gz"
|
||||
["$DB_THIRDPARTY"]="cloudwalk_device_thirdparty_2026_04_23_17_28_33.sql.gz"
|
||||
["$DB_G"]="g_2026_04_23_17_28_33.sql.gz"
|
||||
["$DB_P"]="p_2026_04_23_17_28_33.sql.gz"
|
||||
)
|
||||
|
||||
# Check if DB exists and has tables — skip restore if already populated
|
||||
db_has_tables() {
|
||||
local db="$1"
|
||||
local count
|
||||
count=$($MYSQL_CMD -N -e "SELECT COUNT(*) FROM information_schema.tables WHERE table_schema='$db'" 2>/dev/null || echo "0")
|
||||
[[ "$count" -gt 0 ]]
|
||||
}
|
||||
|
||||
for db_name in "${!DB_MAP[@]}"; do
|
||||
backup_file="${DB_MAP[$db_name]}"
|
||||
backup_path="$DATA_BACKUP/$backup_file"
|
||||
|
||||
if [[ ! -f "$backup_path" ]]; then
|
||||
log_warn "Backup not found: $backup_path — skipping $db_name"
|
||||
continue
|
||||
fi
|
||||
|
||||
# Idempotency: skip if DB already has data
|
||||
if db_has_tables "$db_name"; then
|
||||
log_ok " $db_name already exists ($(du -h "$backup_path" | cut -f1) backup skipped)"
|
||||
continue
|
||||
fi
|
||||
|
||||
log_info "Restoring $db_name from $backup_file ($(du -h "$backup_path" | cut -f1))..."
|
||||
|
||||
# Create DB if not exists
|
||||
$MYSQL_CMD -e "CREATE DATABASE IF NOT EXISTS \`$db_name\` DEFAULT CHARACTER SET utf8mb4;"
|
||||
|
||||
# Import (strip multi-line GTID_PURGED to avoid MySQL error 1840)
|
||||
zcat "$backup_path" | sed '/SET @@GLOBAL.GTID_PURGED=/,/;/d' | $MYSQL_CMD "$db_name" 2>&1 | tail -1
|
||||
|
||||
if [[ ${PIPESTATUS[0]} -eq 0 ]]; then
|
||||
log_ok " $db_name restored successfully"
|
||||
else
|
||||
log_error " $db_name restore FAILED"
|
||||
fi
|
||||
done
|
||||
|
||||
# Elevator app also needs second backup (34_*.sql.gz) — skip if DB already populated
|
||||
if [[ -f "$DATA_BACKUP/34_2026_04_23_17_28_33.sql.gz" ]]; then
|
||||
if db_has_tables "$DB_ELEVATOR"; then
|
||||
log_ok " $DB_ELEVATOR partition 34 skipped (DB already populated)"
|
||||
else
|
||||
log_info "Restoring elevator DB partition 34..."
|
||||
zcat "$DATA_BACKUP/34_2026_04_23_17_28_33.sql.gz" | sed '/SET @@GLOBAL.GTID_PURGED=/,/;/d' | $MYSQL_CMD "$DB_ELEVATOR"
|
||||
log_ok " $DB_ELEVATOR partition 34 restored"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Apply V2.0.7 DDL (tenant_visitor_floor_policy) — skip if table exists
|
||||
log_info "Checking V2.0.7 DDL (tenant_visitor_floor_policy)..."
|
||||
TABLE_EXISTS=$($MYSQL_CMD -N -e "SELECT COUNT(*) FROM information_schema.tables WHERE table_schema='$DB_ELEVATOR' AND table_name='tenant_visitor_floor_policy'" 2>/dev/null || echo "0")
|
||||
if [[ "$TABLE_EXISTS" -gt 0 ]]; then
|
||||
log_ok " tenant_visitor_floor_policy already exists — DDL skipped"
|
||||
else
|
||||
log_info "Applying V2.0.7 DDL..."
|
||||
$MYSQL_CMD "$DB_ELEVATOR" < "$REPO_ROOT/docs/sql/tenant_visitor_floor_policy.sql"
|
||||
log_ok " V2 DDL applied"
|
||||
fi
|
||||
|
||||
log_info "Database preparation complete"
|
||||
Reference in New Issue
Block a user