====== Runbook: Config Backup ======
**Duration:** ~5 minutes \\
**Role:** Sysadmin \\
**Frequency:** After every change, weekly
Backup of Gateway configuration and certificates.
----
===== Workflow =====
flowchart TD
A[Start] --> B[Identify files]
B --> C[Create archive]
C --> D[Copy to backup storage]
D --> E[Verify integrity]
E --> F{OK?}
F -->|Yes| G[Document]
F -->|No| H[Backup again]
style G fill:#e8f5e9
style H fill:#ffebee
----
===== 1. Files to Backup =====
| File/Folder | Description | Critical |
|-------------|-------------|----------|
| ''appsettings.json'' | Main configuration | Yes |
| ''appsettings.Production.json'' | Production override | Yes |
| ''certs/'' | TLS certificates | Yes |
| ''data/*.db'' | SQLite databases | Yes |
| ''.env'' | Environment variables (if present) | Yes |
----
===== 2. Manual Backup =====
**Linux:**
#!/bin/bash
# backup-gateway.sh
GATEWAY_DIR="/opt/data-gateway"
BACKUP_DIR="/backup/gateway"
DATE=$(date +%Y%m%d_%H%M%S)
BACKUP_FILE="gateway-config-${DATE}.tar.gz"
# Create archive
tar -czvf "${BACKUP_DIR}/${BACKUP_FILE}" \
-C "${GATEWAY_DIR}" \
appsettings.json \
appsettings.Production.json \
certs/ \
data/
# Create checksum
sha256sum "${BACKUP_DIR}/${BACKUP_FILE}" > "${BACKUP_DIR}/${BACKUP_FILE}.sha256"
# Delete old backups (older than 30 days)
find "${BACKUP_DIR}" -name "gateway-config-*.tar.gz" -mtime +30 -delete
echo "Backup created: ${BACKUP_FILE}"
**Windows (PowerShell):**
# backup-gateway.ps1
$GatewayDir = "%GATEWAY_ROOT%"
$BackupDir = "D:\Backup\Gateway"
$Date = Get-Date -Format "yyyyMMdd_HHmmss"
$BackupFile = "gateway-config-$Date.zip"
# Create archive
Compress-Archive -Path @(
"$GatewayDir\appsettings.json",
"$GatewayDir\appsettings.Production.json",
"$GatewayDir\certs",
"$GatewayDir\data"
) -DestinationPath "$BackupDir\$BackupFile"
# Checksum
Get-FileHash "$BackupDir\$BackupFile" -Algorithm SHA256 |
Select-Object Hash |
Out-File "$BackupDir\$BackupFile.sha256"
# Delete old backups (older than 30 days)
Get-ChildItem "$BackupDir\gateway-config-*.zip" |
Where-Object { $_.LastWriteTime -lt (Get-Date).AddDays(-30) } |
Remove-Item
Write-Host "Backup created: $BackupFile"
----
===== 3. Automated Backup =====
**Linux (Cron):**
# /etc/cron.d/gateway-backup
0 2 * * * root /opt/scripts/backup-gateway.sh >> /var/log/gateway-backup.log 2>&1
**Windows (Task Scheduler):**
# Create task
$Action = New-ScheduledTaskAction -Execute "PowerShell.exe" `
-Argument "-File %SCRIPTS_PATH%\backup-gateway.ps1"
$Trigger = New-ScheduledTaskTrigger -Daily -At 2:00AM
$Principal = New-ScheduledTaskPrincipal -UserId "SYSTEM" -RunLevel Highest
Register-ScheduledTask -TaskName "Gateway Backup" `
-Action $Action -Trigger $Trigger -Principal $Principal
----
===== 4. Backup to Remote Storage =====
**Rsync (Linux -> NAS):**
rsync -avz --delete \
/backup/gateway/ \
user@nas.example.com:/volume1/backups/gateway/
**AWS S3:**
aws s3 cp /backup/gateway/gateway-config-*.tar.gz \
s3://my-backups/gateway/ \
--storage-class STANDARD_IA
**Azure Blob:**
az storage blob upload \
--account-name mybackups \
--container-name gateway \
--file /backup/gateway/gateway-config-*.tar.gz \
--name gateway-config-$(date +%Y%m%d).tar.gz
----
===== 5. Restore =====
# Linux
cd /opt/data-gateway
tar -xzvf /backup/gateway/gateway-config-20241215.tar.gz
# Restore permissions
chown -R datagateway:datagateway /opt/data-gateway
chmod 600 /opt/data-gateway/certs/*
# Restart Gateway
sudo systemctl restart data-gateway
# Windows
Expand-Archive -Path "D:\Backup\Gateway\gateway-config-20241215.zip" `
-DestinationPath "%GATEWAY_ROOT%" -Force
Restart-Service -Name "DataGateway"
----
===== 6. Checklist =====
| # | Check | Done |
|---|-------|------|
| 1 | appsettings.json backed up | [ ] |
| 2 | Certificates backed up | [ ] |
| 3 | SQLite DBs backed up | [ ] |
| 4 | Checksum created | [ ] |
| 5 | Copied to remote storage | [ ] |
| 6 | Restore tested | [ ] |
----
===== Troubleshooting =====
| Problem | Cause | Solution |
|---------|-------|----------|
| ''Permission denied'' | Missing permissions | Run as root/Admin |
| ''No space left'' | Storage full | Delete old backups |
| ''Checksum mismatch'' | Corrupt archive | Backup again |
| Restore failed | Wrong permissions | Run chown/chmod |
----
===== Best Practices =====
**3-2-1 Backup Rule:**
* **3** copies of data
* **2** different media (local + cloud)
* **1** copy offsite
----
===== Related Runbooks =====
* [[.:dsn-export|DSN Export]] - Backup DSN definitions
* [[..:sicherheit:zertifikat-erneuern|Renew Certificate]] - Backup before renewal
* [[..:tagesgeschaeft:server-starten|Start Server]] - After restore
----
<< [[.:start|<- Backup]] | [[.:dsn-export|-> DSN Export]] >>
----
//Wolfgang van der Stille @ EMSR DATA d.o.o. - Data Gateway Professional//
{{tag>operator runbook backup restore config}}