feat(toolkit): upgrade to Phase 1 Site Migration & Backup Toolkit
This commit is contained in:
parent
3ea15f5806
commit
fbbf5d7b4f
20
.github/workflows/deploy-env-migration.yaml
vendored
20
.github/workflows/deploy-env-migration.yaml
vendored
@ -18,7 +18,7 @@ on:
|
||||
source_host:
|
||||
description: "源环境 IP 或域名 (用于导出数据)"
|
||||
required: true
|
||||
default: "install.svc.plus"
|
||||
default: "console.svc.plus"
|
||||
type: string
|
||||
source_domain_base:
|
||||
description: "源环境域名后缀 (例如 svc.plus)"
|
||||
@ -35,6 +35,12 @@ on:
|
||||
required: false
|
||||
default: true
|
||||
type: boolean
|
||||
toolkit_action:
|
||||
description: "Toolkit 执行动作"
|
||||
required: false
|
||||
default: "migrate"
|
||||
type: choice
|
||||
options: [migrate, backup, restore]
|
||||
terraform_action:
|
||||
description: "apply 创建/更新,destroy 销毁"
|
||||
required: false
|
||||
@ -296,14 +302,10 @@ jobs:
|
||||
echo "[migration_target]" >> inventory_migration.ini
|
||||
echo "${TARGET_IP} ansible_user=root ansible_ssh_private_key_file=~/.ssh/id_deploy" >> inventory_migration.ini
|
||||
|
||||
- name: Run Ansible Site Migration Playbook
|
||||
working-directory: ${{ env.PLAYBOOKS_DIR }}
|
||||
- name: Run Toolkit Action (${{ github.event.inputs.toolkit_action }})
|
||||
working-directory: .
|
||||
run: |
|
||||
ansible-playbook \
|
||||
-i ../inventory_migration.ini \
|
||||
migrate_site.yml \
|
||||
-e "target_domain=${{ github.event.inputs.target_domain_base }}" \
|
||||
-e "migration_flow.source.domain_base=${{ github.event.inputs.source_domain_base }}"
|
||||
make ${{ github.event.inputs.toolkit_action }} RUN_ARGS="-e target_domain=${{ github.event.inputs.target_domain_base }} -e migration_flow.source.domain_base=${{ github.event.inputs.source_domain_base }}"
|
||||
|
||||
switch_dns:
|
||||
name: Switch DNS Traffic (Manual Approval)
|
||||
@ -345,4 +347,4 @@ jobs:
|
||||
CLOUDFLARE_DNS_API_TOKEN: ${{ steps.vault.outputs.CLOUDFLARE_DNS_API_TOKEN }}
|
||||
run: |
|
||||
cd infra/playbooks
|
||||
ansible-playbook -i ../../cmdb/inventory update_cloudflare_svc_plus_dns.yml
|
||||
ansible-playbook -i ../../cmdb/inventory update_site_dns.yml -e "target_domain=${{ github.event.inputs.target_domain_base }}" -e "source_domain=${{ github.event.inputs.source_domain_base }}"
|
||||
|
||||
17
Makefile
Normal file
17
Makefile
Normal file
@ -0,0 +1,17 @@
|
||||
.PHONY: help migrate backup restore
|
||||
|
||||
help:
|
||||
@echo "AI Workspace Site Migration & Backup Toolkit"
|
||||
@echo "Usage:"
|
||||
@echo " make migrate - Execute full site migration (Source -> Target)"
|
||||
@echo " make backup - Execute cold backup on the target host"
|
||||
@echo " make restore - Execute offline restore on the target host"
|
||||
|
||||
migrate:
|
||||
@bash scripts/run_toolkit.sh migrate $(RUN_ARGS)
|
||||
|
||||
backup:
|
||||
@bash scripts/run_toolkit.sh backup $(RUN_ARGS)
|
||||
|
||||
restore:
|
||||
@bash scripts/run_toolkit.sh restore $(RUN_ARGS)
|
||||
50
scripts/run_toolkit.sh
Executable file
50
scripts/run_toolkit.sh
Executable file
@ -0,0 +1,50 @@
|
||||
#!/bin/bash
|
||||
set -euo pipefail
|
||||
|
||||
ACTION=$1
|
||||
|
||||
if [[ -z "$ACTION" ]]; then
|
||||
echo "Usage: $0 <migrate|backup|restore>"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
PLAYBOOK_DIR="../playbooks"
|
||||
INVENTORY_DIR="../cmdb"
|
||||
|
||||
if [[ ! -d "$PLAYBOOK_DIR" ]]; then
|
||||
echo "[ERROR] Cannot find playbooks directory at $PLAYBOOK_DIR"
|
||||
echo "Make sure ai-workspace-infra/playbooks is checked out."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ ! -f "$INVENTORY_DIR/inventory" ]] && [[ ! -f "$INVENTORY_DIR/inventory.ini" ]] && [[ ! -f "cmdb/inventory" ]]; then
|
||||
echo "[WARNING] Cannot find cmdb/inventory. Assuming manual inventory or default."
|
||||
fi
|
||||
|
||||
# In GitHub Actions, cmdb is at the root of site-recovery. Locally it might be ../cmdb.
|
||||
INV_PATH="cmdb/inventory"
|
||||
if [[ ! -f "$INV_PATH" ]]; then
|
||||
if [[ -f "../cmdb/inventory" ]]; then
|
||||
INV_PATH="../cmdb/inventory"
|
||||
elif [[ -f "../cmdb/inventory.ini" ]]; then
|
||||
INV_PATH="../cmdb/inventory.ini"
|
||||
fi
|
||||
fi
|
||||
|
||||
PLAYBOOK_FILE="${ACTION}_site.yml"
|
||||
|
||||
echo "[INFO] Starting Toolkit Action: $ACTION"
|
||||
echo "[INFO] Playbook: $PLAYBOOK_DIR/$PLAYBOOK_FILE"
|
||||
|
||||
cd "$PLAYBOOK_DIR"
|
||||
|
||||
if [[ -f "../site-recovery/$INV_PATH" ]]; then
|
||||
ansible-playbook -i "../site-recovery/$INV_PATH" "$PLAYBOOK_FILE" "${@:2}"
|
||||
elif [[ -f "../cmdb/inventory" ]]; then
|
||||
ansible-playbook -i "../cmdb/inventory" "$PLAYBOOK_FILE" "${@:2}"
|
||||
else
|
||||
echo "[WARNING] No inventory found. Running playbook without explicit inventory flag."
|
||||
ansible-playbook "$PLAYBOOK_FILE" "${@:2}"
|
||||
fi
|
||||
|
||||
echo "[INFO] Toolkit Action $ACTION completed."
|
||||
Loading…
Reference in New Issue
Block a user