feat(ai-workspace): add backup/restore/migration role and playbook

This commit is contained in:
Haitao Pan 2026-06-17 13:59:37 +08:00
parent b36a1c44e5
commit 1ac560e482
4 changed files with 77 additions and 0 deletions

View File

@ -0,0 +1,11 @@
---
# Backup/Restore/Migration Defaults
migrate_source_host: "{{ ansible_host | default('localhost') }}"
migrate_source_user: "ubuntu"
migrate_litellm_db: "litellm"
migrate_litellm_db_user: "litellm"
migrate_litellm_db_host: "127.0.0.1"
# Migration paths
openclaw_data_dir: "~/.openclaw"
xworkspace_state_dir: "~/.local/state/xworkspace"

View File

@ -0,0 +1,7 @@
---
dependencies:
- role: roles/agent_skills
- role: roles/vhosts/gateway_openclaw
- role: roles/vhosts/xworkmate_bridge
- role: roles/vhosts/acp_server_hermes
- role: roles/vhosts/qmd

View File

@ -0,0 +1,48 @@
---
- name: Ensure local data directories exist
ansible.builtin.file:
path: "{{ item }}"
state: directory
mode: '0755'
loop:
- "{{ openclaw_data_dir }}/plugin-skills"
- "{{ openclaw_data_dir }}/skill-workshop"
- "{{ openclaw_data_dir }}/agents/main/sessions"
- name: Sync skills and plugins
ansible.posix.synchronize:
src: "{{ migrate_source_user }}@{{ migrate_source_host }}:{{ item }}"
dest: "{{ item | dirname }}/"
mode: pull
archive: yes
checksum: yes
use_ssh_args: yes
loop:
- "{{ openclaw_data_dir }}/plugin-skills/"
- "{{ openclaw_data_dir }}/skill-workshop/"
- name: Sync temporary sessions
ansible.posix.synchronize:
src: "{{ migrate_source_user }}@{{ migrate_source_host }}:{{ openclaw_data_dir }}/agents/main/sessions/"
dest: "{{ openclaw_data_dir }}/agents/main/sessions/"
mode: pull
archive: yes
checksum: yes
use_ssh_args: yes
- name: Migrate QMD memory (merge)
ansible.builtin.command: >
qmd sync --host {{ migrate_source_user }}@{{ migrate_source_host }}
--remote-qmd-user {{ migrate_source_user }} --update --embed
register: qmd_sync_result
changed_when: "'Sync completed' in qmd_sync_result.stdout or qmd_sync_result.rc == 0"
ignore_errors: yes
- name: Migrate LiteLLM database
ansible.builtin.shell: >
ssh -o StrictHostKeyChecking=no {{ migrate_source_user }}@{{ migrate_source_host }}
"pg_dump -U {{ migrate_litellm_db_user }} -h {{ migrate_litellm_db_host }} -Fc {{ migrate_litellm_db }}" |
pg_restore -U {{ migrate_litellm_db_user }} -h {{ migrate_litellm_db_host }} -d {{ migrate_litellm_db }} -1 --clean
register: pg_migrate_result
changed_when: pg_migrate_result.rc == 0
ignore_errors: yes

View File

@ -0,0 +1,11 @@
---
- name: Migrate AI Workspace Data
hosts: localhost
connection: local
become: no
gather_facts: false
tasks:
- name: Run AI Workspace Migration Tasks
ansible.builtin.include_role:
name: roles/vhosts/ai-workspace
tasks_from: migrate.yml