# Backup and Recovery Strategies

Comprehensive backup and disaster recovery planning.

## Backup Types

### Full Backup

```bash
provisioning backup create --type full --name "full-backup-$(date +%Y-%m-%d)"
```

### Incremental Backup

```bash
provisioning backup create --type incremental --base-backup full-backup-2026-01-01
```

### Point-in-Time Backup

```bash
provisioning backup create --type pitr --timestamp "2026-01-15T12:00:00Z"
```

## Backup Schedule

```nickel
{
  backup = {
    schedule = {
      daily = {
        time = "02:00",
        retention_days = 7
      },
      weekly = {
        day = "sunday",
        time = "03:00",
        retention_days = 30
      },
      monthly = {
        day = 1,
        time = "04:00",
        retention_days = 365
      }
    }
  }
}
```

## Recovery Procedures

### Restore Database

```bash
provisioning backup restore \
  --backup-id backup-12345 \
  --target-database production \
  --point-in-time "2026-01-15T12:00:00Z"
```

### Verify Backup Integrity

```bash
provisioning backup verify --backup-id backup-12345
```

### Test Recovery

```bash
provisioning backup test-restore \
  --backup-id backup-12345 \
  --test-environment staging
```

## Disaster Recovery

### RTO & RPO

```nickel
{
  disaster_recovery = {
    primary_region = "us-east-1",
    secondary_region = "us-west-2",
    rto_minutes = 15,      # Recovery Time Objective
    rpo_minutes = 5        # Recovery Point Objective
  }
}
```

### Failover Procedure

```bash
#!/usr/bin/env nu

def failover-to-secondary [] {
  print "Initiating failover to secondary region..."

  # 1. Verify secondary is ready
  provisioning health check secondary_region

  # 2. Promote secondary database
  provisioning database promote-replica --replica secondary-db

  # 3. Update DNS/routing
  provisioning dns update --record api.example.com --target secondary-lb

  # 4. Monitor switchover
  sleep 60sec
  provisioning test smoke-tests

  print "✓ Failover complete"
}
```

## Related Documentation

- [Disaster Recovery](../guides/disaster-recovery.md)
- [Monitoring](./monitoring.md)
- [Operations Overview](./README.md)
