Restauração de Backups

Este guia mostra como restaurar dados de backups.

Listar Backups Disponíveis

Por Task

backupally history --target mysql-prod

Saída:

SNAPSHOT                  DATE                 SIZE      STATUS
snap_20260211_020000      2026-02-11 02:00:00  890 MB    OK
snap_20260210_020000      2026-02-10 02:00:00  885 MB    OK
snap_20260209_020000      2026-02-09 02:00:00  882 MB    OK

Todos os Backups

backupally history

Filtrar por Data

backupally history --target mysql-prod --since 2026-02-01 --until 2026-02-10

Restaurar Backup

Sintaxe

backupally restore \
  --target <TASK_ID> \
  --snapshot <SNAPSHOT_ID> \
  --path <DESTINO>

Exemplo Básico

backupally restore \
  --target mysql-prod \
  --snapshot snap_20260211_020000 \
  --path /restore/mysql

Verificar Integridade

Antes de restaurar, verifique o backup:

backupally restore \
  --target mysql-prod \
  --snapshot snap_20260211_020000 \
  --verify

Simulação (Dry Run)

Veja o que seria restaurado sem extrair:

backupally restore \
  --target mysql-prod \
  --snapshot snap_20260211_020000 \
  --path /restore \
  --dry-run

Restaurar com Chave Específica

Se o backup foi feito com outra chave:

backupally restore \
  --target mysql-prod \
  --snapshot snap_20260211_020000 \
  --path /restore \
  --key /etc/backupally/keys/old-key.pem

Restaurar Databases

MySQL

  1. Restaure os arquivos:
backupally restore \
  --target mysql-prod \
  --snapshot snap_20260211_020000 \
  --path /restore/mysql
  1. Importe no MySQL:
# Banco específico
mysql -u root -p myapp < /restore/mysql/myapp.sql

# Todos os bancos
for f in /restore/mysql/*.sql; do
  mysql -u root -p < "$f"
done

PostgreSQL

  1. Restaure os arquivos:
backupally restore \
  --target postgres-prod \
  --snapshot snap_20260211_030000 \
  --path /restore/postgres
  1. Importe no PostgreSQL:
# Criar banco se necessário
createdb -U postgres myapp_restored

# Restaurar globals (roles)
psql -U postgres -f /restore/postgres/globals.sql

# Restaurar banco
psql -U postgres -d myapp_restored -f /restore/postgres/myapp.sql

MongoDB

  1. Restaure os arquivos:
backupally restore \
  --target mongodb-prod \
  --snapshot snap_20260211_020000 \
  --path /restore/mongodb
  1. Importe no MongoDB:
mongorestore /restore/mongodb/

Com opções:

mongorestore --drop --gzip /restore/mongodb/

Restaurar Arquivos

Para Diretório Temporário

backupally restore \
  --target website \
  --snapshot snap_20260211_040000 \
  --path /restore/website

Para Local Original

backupally restore \
  --target website \
  --snapshot snap_20260211_040000 \
  --path /var/www/html

Arquivo Específico

Atualmente, BackupAlly restaura o backup completo. Para extrair arquivo específico:

# Restaure para temp
backupally restore --target website --snapshot snap_xxx --path /tmp/restore

# Copie o arquivo desejado
cp /tmp/restore/var/www/html/config.php /var/www/html/

# Limpe
rm -rf /tmp/restore

Recovery de Chaves

Usando Servidor Central

Se configurado:

backupally keys recover \
  --fingerprint a1b2c3d4e5f6a7b8 \
  --server https://central.backupally.io \
  --api-key your-key \
  --output /etc/backupally/keys/recovered.key

Identificar Chave Necessária

O fingerprint está no header do backup:

backupally inspect snap_20260211_020000.ally

Troubleshooting

Erro: Chave Inválida

Error: Failed to decrypt: Invalid key

O backup foi feito com outra chave. Use --key para especificar.

Erro: Snapshot Não Encontrado

Error: Snapshot not found

Verifique se o snapshot existe:

backupally history --target mysql-prod

Erro: Checksum Inválido

Error: Checksum mismatch

O arquivo pode estar corrompido. Tente outro storage:

backupally restore \
  --target mysql-prod \
  --snapshot snap_xxx \
  --path /restore \
  --storage b2-secondary

Erro: Espaço Insuficiente

Verifique espaço antes de restaurar:

df -h /restore

Boas Práticas

  1. Teste restaurações regularmente: Não espere um desastre
  2. Mantenha chaves seguras: Sem chave, backups são inúteis
  3. Documente fingerprints: Saiba qual chave usar para cada backup
  4. Restaure para local temporário: Verifique antes de sobrescrever
  5. Verifique integridade: Use --verify antes de restaurar
By Borlot.com.br on 11/02/2026