- Implemented a Python script using Paramiko to connect to an SFTP server. - Added functionality to list files in the current directory and check for the existence of a '/backups' directory. - Included error handling for directory listing and creation. - Implemented a test upload feature to verify file upload capabilities. - Added cleanup for uploaded test files and ensured proper connection closure.
89 lines
2.9 KiB
Markdown
89 lines
2.9 KiB
Markdown
# Sikker Test Plan for Backup Restore
|
|
|
|
## ✅ SAFETY CHECKLIST
|
|
|
|
### Før test:
|
|
- [x] **Emergency backup oprettet**: `/manual_backup_*/emergency_backup_before_restore_test.dump`
|
|
- [x] **DRY_RUN mode aktiveret**: `BACKUP_RESTORE_DRY_RUN=true` (default)
|
|
- [ ] **Test på ikke-kritisk data**: Slet eller ændr noget test-data først
|
|
|
|
### Test Fase 1: DRY-RUN (Sikker - ingen ændringer)
|
|
```bash
|
|
# 1. Kør restore i DRY-RUN mode (gør INGENTING - kun logger)
|
|
curl -X POST http://localhost:8001/api/v1/backups/restore/17 \
|
|
-H "Content-Type: application/json" \
|
|
-d '{"confirmation": true}'
|
|
|
|
# Forventet: "DRY RUN MODE: Would restore..." i logs
|
|
docker-compose logs api --tail 20 | grep "DRY RUN"
|
|
```
|
|
|
|
### Test Fase 2: Recovery Test (Valgfri)
|
|
```bash
|
|
# 2. Lav en lille test-ændring i databasen
|
|
docker-compose exec postgres psql -U bmc_hub -d bmc_hub -c \
|
|
"INSERT INTO backup_jobs (job_type, status, backup_format, started_at)
|
|
VALUES ('database', 'completed', 'dump', NOW());"
|
|
|
|
# 3. Tjek at test-data findes
|
|
docker-compose exec postgres psql -U bmc_hub -d bmc_hub -c \
|
|
"SELECT COUNT(*) FROM backup_jobs;"
|
|
|
|
# 4. Restore fra backup (DISABLED indtil du er klar)
|
|
# echo "BACKUP_RESTORE_DRY_RUN=false" >> .env
|
|
# docker-compose restart api
|
|
# curl -X POST http://localhost:8001/api/v1/backups/restore/16 -H "Content-Type: application/json" -d '{"confirmation": true}'
|
|
|
|
# 5. Verificer at test-data er væk (restore virkede)
|
|
docker-compose exec postgres psql -U bmc_hub -d bmc_hub -c \
|
|
"SELECT COUNT(*) FROM backup_jobs;"
|
|
```
|
|
|
|
### Emergency Recovery (hvis noget går galt)
|
|
```bash
|
|
# Restore fra emergency backup
|
|
docker-compose exec postgres dropdb -U bmc_hub --if-exists bmc_hub
|
|
docker-compose exec postgres createdb -U bmc_hub bmc_hub
|
|
docker-compose exec postgres pg_restore -U bmc_hub -d bmc_hub -Fc < \
|
|
manual_backup_*/emergency_backup_before_restore_test.dump
|
|
|
|
# Genstart API
|
|
docker-compose restart api
|
|
```
|
|
|
|
## 🛡️ SAFETY FEATURES I KODEN
|
|
|
|
1. **BACKUP_RESTORE_DRY_RUN=true** (default) - blokerer alle restores
|
|
2. **BACKUP_READ_ONLY=true** - blokerer restores hvis sat
|
|
3. **Checksum verification** - verificerer fil integritet før restore
|
|
4. **File lock** - forhindrer concurrent restores
|
|
5. **Maintenance mode** - sætter system i maintenance under restore
|
|
|
|
## ⚠️ VIGTIG ADVARSEL
|
|
|
|
**RESTORE OVERSKRIVER AL DATA I DATABASEN!**
|
|
|
|
Før du deaktiverer DRY-RUN mode:
|
|
1. Tag ALTID en emergency backup først (allerede gjort ✅)
|
|
2. Test på en development/staging server først
|
|
3. Sørg for at backup filen er den rigtige
|
|
4. Kommuniker med brugere hvis på produktion
|
|
|
|
## 🚀 Når du er klar til rigtig restore:
|
|
|
|
1. Tilføj i `.env`:
|
|
```
|
|
BACKUP_RESTORE_DRY_RUN=false
|
|
```
|
|
|
|
2. Genstart API:
|
|
```bash
|
|
docker-compose restart api
|
|
```
|
|
|
|
3. Test restore via UI eller curl
|
|
|
|
---
|
|
**Oprettet**: 2. januar 2026
|
|
**Emergency Backup**: manual_backup_20260102_103605/emergency_backup_before_restore_test.dump (2.8MB)
|