# Fase 2: CWP Migration (Week 3-6)

Target: Migrar 39 vhosts CWP para VM AlmaLinux 8

**CRITICAL:** 7 dias safety net - server.descomplicar.pt intacto

## 2.1 Criar VM AlmaLinux 8 + CWP

```bash
qm create 300 \
  --name cwp-legacy \
  --memory 16384 \
  --cores 6 \
  --net0 virtio,bridge=vmbr0 \
  --scsi0 rpool/vm-disks:150 \
  --ostype l26

# Instalar AlmaLinux 8
# Instalar CWP7
wget http://centos-webpanel.com/cwp-el8-latest
sh cwp-el8-latest
```

## 2.2 Backup CWP Accounts

```bash
# Em server.descomplicar.pt
for account in $(cat /tmp/cwp-accounts.txt); do
  /scripts/pkgacct $account
done

# Transfer backups
rsync -avz /home/backup-*/cpmove-*.tar.gz \
  root@cluster.descomplicar.pt:/mnt/migration/cwp/
```

## 2.3 Migrar Contas (Batch 3-5 contas)

Workflow por conta:

```bash
# 1. Restore backup em VM CWP
scp /mnt/migration/cwp/cpmove-ACCOUNT.tar.gz root@10.10.10.300:/home/

# 2. Restore via CWP
/scripts/restorepkg ACCOUNT

# 3. Validar:
- Site carrega (HTTP 200)
- Database conecta
- Email funciona (send test)
- SSL certificado valido

# 4. DNS cutover (TTL 300s)
A record: site.com -> 10.10.10.300 (via NAT port forward)

# 5. Monitorizar 24h
```

## 2.4 Validation Period (7 dias)

```bash
# Days 1-7 apos migration:
- Server antigo (server.descomplicar.pt) INTACTO
- Rollback instantaneo se problema critical
- Cliente pode reverter DNS manualmente se necessario

# Day 7: Confirmar com Emanuel
# Se tudo OK -> proceder cleanup
# Se problemas -> extend validation ou rollback completo
```

## 2.5 Email Migration

```bash
# Por cada conta CWP:

# 1. Backup mailboxes
tar -czf /tmp/mail-ACCOUNT.tar.gz /home/ACCOUNT/mail/

# 2. Transfer
scp /tmp/mail-ACCOUNT.tar.gz root@10.10.10.300:/tmp/

# 3. Restore
cd /home/ACCOUNT/
tar -xzf /tmp/mail-ACCOUNT.tar.gz

# 4. Fix permissions
chown -R ACCOUNT:ACCOUNT /home/ACCOUNT/mail/

# 5. Testar IMAP/SMTP
telnet localhost 143  # IMAP
telnet localhost 25   # SMTP
```

## 2.6 Rollback Procedure (Fase 2)

```bash
# Disponivel ate Day 7

# 1. Reverter DNS (todos sites)
A records -> IP antigo (server.descomplicar.pt)

# 2. Verificar server antigo online
ping server.descomplicar.pt

# 3. Comunicar clientes

# 4. Analisar causa falha

# 5. Ajustar plan e re-tentar
```
