Rollback Procedures
Rollback Procedures
Section titled “Rollback Procedures”Panduan langkah demi langkah untuk melakukan rollback ketika ada masalah setelah deployment.
Overview
Section titled “Overview”Terdapat 4 level rollback, dari yang termudah sampai yang paling kompleks:
| Level | Method | Time | Data Loss |
|---|---|---|---|
| 1 | Dokploy Redeploy | ~2 min | None |
| 2 | Git Revert | ~5 min | None |
| 3 | Database Restore | ~15-30 min | Last backup |
| 4 | Full Infrastructure | ~1 hour | Varies |
Level 1: Dokploy Redeploy (Fastest)
Section titled “Level 1: Dokploy Redeploy (Fastest)”When to Use
Section titled “When to Use”- Bug di code tanpa perubahan database
- Perlu kembali ke versi sebelumnya dengan cepat
- Tidak ada schema migration yang bermasalah
- Login ke Dokploy dashboard
- Pilih aplikasi → tab Deployments
- Temukan deployment yang sebelumnya berfungsi
- Klik “Redeploy”
[SCREENSHOT: Dokploy → Deployments tab showing previous deployment]- Monitor logs sampai selesai
- Verify dengan health check:
curl https://api.yourdomain.com/api/healthTime Estimate
Section titled “Time Estimate”- ~2 menit
Level 2: Git Revert
Section titled “Level 2: Git Revert”When to Use
Section titled “When to Use”- Commit bermasalah sudah di-push
- Perlu review perubahan sebelum rollback
- Ingin zachh完整的 revert commit
Option A: Revert via CLI
Section titled “Option A: Revert via CLI”# Clone repo jika belum adagit clone https://github.com/Syskita/merq.gitcd merq
# Buat revert commitgit revert HEAD
# Push ke main (trigger auto-deploy)git push origin mainOption B: Revert via GitHub
Section titled “Option B: Revert via GitHub”- Buka GitHub repository
- Pilih commit yang bermasalah
- Klik “Revert”
- Buat Pull Request
- Merge setelah review
Time Estimate
Section titled “Time Estimate”- ~5 menit
Level 3: Database Restore
Section titled “Level 3: Database Restore”When to Use
Section titled “When to Use”- Ada destructive migration yang merusak data -Perlu kembali ke state database sebelumnya
- Level 1 dan 2 tidak menyelesaikan masalah
⚠️ Warning
Section titled “⚠️ Warning”Database restore akan menghapus semua perubahan sejak backup terakhir. Pastikan tidak ada data penting yang perlu diselamatkan!
Prerequisites
Section titled “Prerequisites”- Backup file tersedia di
/backups/ - Tau timestamp backup yang ingin di-restore
1. Backup Current State (Sebelum Restore)
Section titled “1. Backup Current State (Sebelum Restore)”# Backup dulu state saat ini (jika memungkinkan)pg_dump -h $DB_HOST -U $DB_USER $DB_NAME > /backups/pre_restore_$(date +%Y%m%d_%H%M%S).sql2. Stop Application
Section titled “2. Stop Application”# Via Dokploy# Buka dashboard → Stop Application
# Via CLIdocker stop merq-backenddocker stop merq-web3. Identify Available Backups
Section titled “3. Identify Available Backups”ls -la /backups/4. Restore Database
Section titled “4. Restore Database”# Drop dan recreate databasepsql -h $DB_HOST -U $DB_USER -c "DROP DATABASE $DB_NAME"psql -h $DB_HOST -U $DB_USER -c "CREATE DATABASE $DB_NAME"
# Restore dari backuppsql -h $DB_HOST -U $DB_USER $DB_NAME < /backups/merq_YYYYMMDD_HHMMSS.sql5. Redeploy Previous Version
Section titled “5. Redeploy Previous Version”# Kembali ke versi code sebelumnya (Level 1 atau 2)# Kemudian start aplikasidocker start merq-backenddocker start merq-web6. Verify
Section titled “6. Verify”# Check application logsdocker logs -f merq-backend
# Health checkcurl https://api.yourdomain.com/api/health
# Sample querycurl https://api.yourdomain.com/api/office/v1/users?limit=1Time Estimate
Section titled “Time Estimate”- ~15-30 menit
Level 4: Full Infrastructure Rollback
Section titled “Level 4: Full Infrastructure Rollback”When to Use
Section titled “When to Use”- Seluruh infrastruktur corrupted -Perlu provisioning ulang dari awal
- Semua upaya lain gagal
1. Document Current State
Section titled “1. Document Current State”Catat:
- Error messages
- Logs
- Screenshots
- Steps yang menyebabkan masalah
2. Stop All Services
Section titled “2. Stop All Services”# Stop semua containerdocker-compose down
# atau
docker stop merq-backend merq-web merq-postgres merq-redis merq-typesense3. Restore dari Snapshots (Jika Ada)
Section titled “3. Restore dari Snapshots (Jika Ada)”Jika menggunakan DigitalOcean:
- Buka Droplet settings
- Pilih Snapshots
- Restore dari snapshot terakhir yang berfungsi
4. Provision Server Baru
Section titled “4. Provision Server Baru”Jika snapshot tidak tersedia:
- Buat Droplet baru
- Ikuti Manual Deployment dari awal
- Restore database dari backup
5. Update DNS
Section titled “5. Update DNS”# Point domain ke IP baru# A Record: api.yourdomain.com → new_server_ip# A Record: admin.yourdomain.com → new_server_ip6. Verify Everything
Section titled “6. Verify Everything”# All servicesdocker ps
# Health checkscurl https://api.yourdomain.com/api/healthcurl https://admin.yourdomain.comTime Estimate
Section titled “Time Estimate”- ~1 jam atau lebih
Pre-Deployment Checklist
Section titled “Pre-Deployment Checklist”Untuk mencegah kebutuhan rollback:
-
Backup database sebelum deploy:
Terminal window pg_dump -h $DB_HOST -U $DB_USER $DB_NAME > /backups/pre_deploy_$(date +%Y%m%d_%H%M%S).sql -
Test di staging terlebih dahulu
-
Review migration scripts:
- Apakah reversible?
- Apakah ada data loss?
- Apakah ada backup strategy?
-
Deploy di jam off-peak untuk minimize impact
-
Siapkan rollback plan sebelum deploy
Rollback Decision Tree
Section titled “Rollback Decision Tree”Masalah terjadi setelah deploy │ ▼ ┌───────────────┐ │ Severity? │ └───────┬───────┘ │ ┌───────┴───────┐ ▼ ▼┌───────┐ ┌───────┐│ Critical│ │ Minor │└───┬───┘ └───┬───┘ │ │ ▼ ▼┌─────────┐ ┌─────────┐│ Level 1 │ │ Level 1 ││ or 2 │ │ first │└────┬────┘ └───┬────┘ │ │ ▼ ▼┌─────────┐ ┌─────────┐│ Work? │ │ Fix in ││ ✓ │ │ next │└─────────┘ │ release │ └─────────┘Recovery Time Summary
Section titled “Recovery Time Summary”| Level | Method | Typical Time |
|---|---|---|
| 1 | Dokploy Redeploy | 2 menit |
| 2 | Git Revert | 5 menit |
| 3 | Database Restore | 15-30 menit |
| 4 | Full Infrastructure | 1+ jam |