feat(v1.5.2): Execute database migrations and complete setup
- Execute all 6 migrations on Desk CRM production database - Create missing tables: cr_lsps, cr_agent_lsps, cr_lsp_usage - Create archive tables: cr_*_usage_archive (4 tables) - Create system tables: cr_migrations, cr_maintenance_log - Make all scripts executable (chmod +x) - Total cr_* tables: 38 Migration files: - 001_initial_schema.sql - 002_add_lsps.sql - 003_add_relationships.sql - 004_add_telemetry.sql - 005_add_archive_tables.sql - 006_add_maintenance_log.sql Scripts: - session-init.sh, session-end.sh - inject-context.sh, inject-agent-context.sh - record-usage.sh, db-backup.sh, sync-to-mysql.sh Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
225
commands/db-backup.md
Normal file
225
commands/db-backup.md
Normal file
@@ -0,0 +1,225 @@
|
||||
---
|
||||
name: db-backup
|
||||
description: >
|
||||
Backup selectivo das tabelas cr_* da infraestrutura.
|
||||
Exporta estrutura e dados para restauro.
|
||||
argument-hint: "[--tables=X,Y] [--data-only] [--schema-only] [--output=path]"
|
||||
---
|
||||
|
||||
# /descomplicar:db-backup
|
||||
|
||||
Backup selectivo das tabelas cr_* (Claude Resources) da infraestrutura.
|
||||
|
||||
## Objectivo
|
||||
|
||||
Criar backup das tabelas cr_* para permitir restauro em caso de problemas ou migração.
|
||||
|
||||
## Sintaxe
|
||||
|
||||
```
|
||||
/descomplicar:db-backup [options]
|
||||
```
|
||||
|
||||
| Opção | Descrição | Default |
|
||||
|-------|-----------|---------|
|
||||
| `--tables=X,Y` | Backup apenas tabelas específicas | todas cr_* |
|
||||
| `--data-only` | Apenas dados (sem schema) | false |
|
||||
| `--schema-only` | Apenas schema (sem dados) | false |
|
||||
| `--output=path` | Directório de output | ./backups/ |
|
||||
| `--compress` | Comprimir backup (gzip) | false |
|
||||
| `--include-archive` | Incluir tabelas *_archive | false |
|
||||
|
||||
## Output Esperado
|
||||
|
||||
```
|
||||
╔════════════════════════════════════════════════════════════╗
|
||||
║ DB BACKUP ║
|
||||
╠════════════════════════════════════════════════════════════╣
|
||||
║ Backup ID: cr_backup_20260204_163500 ║
|
||||
║ Output: ./backups/cr_backup_20260204_163500/ ║
|
||||
╠════════════════════════════════════════════════════════════╣
|
||||
║ Exporting: 25 tabelas | 1.847 registos | 1.2 MB ║
|
||||
║ Checksum: abc123def456... ║
|
||||
║ Status: ✓ SUCCESS ║
|
||||
╚════════════════════════════════════════════════════════════╝
|
||||
```
|
||||
|
||||
## Tabelas Incluídas por Defeito
|
||||
|
||||
### Core (sempre incluídas)
|
||||
- cr_agents, cr_skills, cr_mcps, cr_lsps, cr_sdks
|
||||
- cr_mcp_tools, cr_plugins, cr_hooks
|
||||
|
||||
### Relacionamentos (sempre incluídas)
|
||||
- cr_agent_mcps, cr_agent_lsps, cr_agent_skills
|
||||
- cr_skill_mcps, cr_sdk_agents, cr_sdk_skills, cr_sdk_mcps
|
||||
- cr_agent_collaborations
|
||||
|
||||
### Telemetria (sempre incluídas)
|
||||
- cr_agent_usage, cr_skill_usage
|
||||
- cr_mcp_tool_usage, cr_lsp_usage
|
||||
|
||||
### Intelligence (sempre incluídas)
|
||||
- cr_decision_trees, cr_recommendations
|
||||
- cr_component_issues, cr_reflections
|
||||
|
||||
### System (sempre incluídas)
|
||||
- cr_migrations, cr_maintenance_log
|
||||
|
||||
### Archive (apenas com --include-archive)
|
||||
- cr_agent_usage_archive, cr_skill_usage_archive
|
||||
- cr_mcp_tool_usage_archive, cr_lsp_usage_archive
|
||||
|
||||
## Estrutura de Backup
|
||||
|
||||
```
|
||||
backups/
|
||||
└── cr_backup_YYYYMMDD_HHMMSS/
|
||||
├── manifest.json # Metadata do backup
|
||||
├── schema/
|
||||
│ ├── cr_agents.sql
|
||||
│ ├── cr_skills.sql
|
||||
│ └── ...
|
||||
├── data/
|
||||
│ ├── cr_agents.sql
|
||||
│ ├── cr_skills.sql
|
||||
│ └── ...
|
||||
└── checksums.md5 # Verificação integridade
|
||||
```
|
||||
|
||||
### manifest.json
|
||||
|
||||
```json
|
||||
{
|
||||
"backup_id": "cr_backup_20260204_163500",
|
||||
"created_at": "2026-02-04T16:35:00Z",
|
||||
"created_by": "descomplicar-meta-plugin",
|
||||
"version": "1.5.0",
|
||||
"database": "perfex_crm",
|
||||
"tables": {
|
||||
"total": 25,
|
||||
"core": 8,
|
||||
"relationships": 8,
|
||||
"telemetry": 4,
|
||||
"intelligence": 4,
|
||||
"system": 2
|
||||
},
|
||||
"rows": {
|
||||
"cr_agents": 46,
|
||||
"cr_skills": 54,
|
||||
"cr_mcps": 33,
|
||||
"...": "..."
|
||||
},
|
||||
"size_bytes": 1234567,
|
||||
"checksum": "abc123...",
|
||||
"options": {
|
||||
"data_only": false,
|
||||
"schema_only": false,
|
||||
"compressed": false,
|
||||
"include_archive": false
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Exemplos
|
||||
|
||||
### Backup completo
|
||||
```bash
|
||||
/descomplicar:db-backup
|
||||
```
|
||||
|
||||
Output:
|
||||
```
|
||||
╔════════════════════════════════════════════════════════════════╗
|
||||
║ DB BACKUP ║
|
||||
╠════════════════════════════════════════════════════════════════╣
|
||||
║ Backup ID: cr_backup_20260204_163500 ║
|
||||
║ Output: ./backups/cr_backup_20260204_163500/ ║
|
||||
╠════════════════════════════════════════════════════════════════╣
|
||||
║ Exporting schema... ║
|
||||
║ cr_agents ✓ ║
|
||||
║ cr_skills ✓ ║
|
||||
║ cr_mcps ✓ ║
|
||||
║ ... (25 tabelas) ✓ ║
|
||||
║ ║
|
||||
║ Exporting data... ║
|
||||
║ cr_agents 46 rows ✓ ║
|
||||
║ cr_skills 54 rows ✓ ║
|
||||
║ cr_mcps 33 rows ✓ ║
|
||||
║ cr_agent_mcps 483 rows ✓ ║
|
||||
║ ... (25 tabelas) ✓ ║
|
||||
╠════════════════════════════════════════════════════════════════╣
|
||||
║ Total: 25 tabelas | 1.847 registos | 1.2 MB ║
|
||||
║ Checksum: abc123def456... ║
|
||||
║ Status: ✓ SUCCESS ║
|
||||
╚════════════════════════════════════════════════════════════════╝
|
||||
```
|
||||
|
||||
### Backup comprimido
|
||||
```bash
|
||||
/descomplicar:db-backup --compress
|
||||
```
|
||||
|
||||
Output:
|
||||
```
|
||||
╔════════════════════════════════════════════════════════════════╗
|
||||
║ DB BACKUP (Compressed) ║
|
||||
╠════════════════════════════════════════════════════════════════╣
|
||||
║ Output: ./backups/cr_backup_20260204_163500.tar.gz ║
|
||||
║ Original size: 1.2 MB ║
|
||||
║ Compressed size: 245 KB (80% reduction) ║
|
||||
║ Status: ✓ SUCCESS ║
|
||||
╚════════════════════════════════════════════════════════════════╝
|
||||
```
|
||||
|
||||
### Apenas tabelas core
|
||||
```bash
|
||||
/descomplicar:db-backup --tables=cr_agents,cr_skills,cr_mcps
|
||||
```
|
||||
|
||||
### Schema only (para migrations)
|
||||
```bash
|
||||
/descomplicar:db-backup --schema-only --output=./migrations/reference/
|
||||
```
|
||||
|
||||
### Incluir archives
|
||||
```bash
|
||||
/descomplicar:db-backup --include-archive --compress
|
||||
```
|
||||
|
||||
## Restore
|
||||
|
||||
Para restaurar um backup:
|
||||
|
||||
```bash
|
||||
# Ver backups disponíveis
|
||||
ls -la ./backups/
|
||||
|
||||
# Restaurar (via desk-crm-v3 MCP ou mysql client)
|
||||
mysql perfex_crm < ./backups/cr_backup_XXXXX/data/cr_agents.sql
|
||||
```
|
||||
|
||||
**Nota**: Restore completo requer script separado ou uso manual do mysql client.
|
||||
|
||||
## Retenção Sugerida
|
||||
|
||||
| Tipo | Retenção | Automação |
|
||||
|------|----------|-----------|
|
||||
| Diário | 7 dias | Hook SessionStart |
|
||||
| Semanal | 4 semanas | Cron domingo |
|
||||
| Mensal | 12 meses | Cron dia 1 |
|
||||
|
||||
## Integração
|
||||
|
||||
- **Skill**: db-maintenance-manager
|
||||
- **MCP**: desk-crm-v3
|
||||
- **Relacionado**:
|
||||
- /descomplicar:db-migrate (backup antes de migrations)
|
||||
- /descomplicar:db-cleanup (backup antes de limpeza)
|
||||
|
||||
## Segurança
|
||||
|
||||
- Backups não incluem credenciais
|
||||
- Checksums MD5 para verificação
|
||||
- Ficheiros com permissões 600
|
||||
- Não incluir em repositórios git (.gitignore)
|
||||
Reference in New Issue
Block a user