chore(ops): test-data cleanup script and runbook

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-14 11:14:57 +08:00
co-authored by Claude Sonnet 5.5
parent 1b84ed8625
commit 10f22b5cd5
3 changed files with 92 additions and 4 deletions
+24
View File
@@ -0,0 +1,24 @@
# Cleanup: delete test incidents and non-admin users
Owner go-ahead required before step 4. Never run during business hours without telling HSE.
1. **Backup** (on the server, `ssh -p 9321 setia@175.136.239.121`):
```bash
D=$(date +%Y%m%d-%H%M)
pg_dump -p 5433 -Fc ims > /srv/apps/ims/backups/ims-pre-cleanup-$D.dump
tar -czf /srv/apps/ims/backups/evidence-pre-cleanup-$D.tgz /var/lib/ims-evidence
ls -lh /srv/apps/ims/backups/*pre-cleanup-$D*
```
Create `/srv/apps/ims/backups` first if missing. Both files must be non-empty.
2. **Upload** `db/ops/cleanup-test-data.sql` to `/srv/apps/ims/backups/` (not into `app/`).
3. **Dry run** as the DB owner:
```bash
psql -p 5433 -d ims -v mode=dryrun -f /srv/apps/ims/backups/cleanup-test-data.sql
```
Send the admins list and the row counts to the owner. Stop here until they confirm.
4. **Run** after explicit confirmation:
```bash
psql -p 5433 -d ims -v ON_ERROR_STOP=1 -v mode=run -f /srv/apps/ims/backups/cleanup-test-data.sql
```
5. **Verify**: `systemctl is-active ims` is `active`; log in as an admin at https://ims.setia.com.my/login; Incidents page is empty; Users page lists only admins.
6. **Rollback** (only if wrong): `pg_restore -p 5433 -d ims --clean --if-exists <dump>`; evidence files were never touched.