# 2nd November 2025 — MongoDB Backup/Restore System [#69](https://github.com/nbarrett/ngx-ramblers/issues/69)
## [build 340](https://github.com/nbarrett/ngx-ramblers/actions/runs/19011520890) — [#69](https://github.com/nbarrett/ngx-ramblers/issues/69) — [commit 4072610](https://github.com/nbarrett/ngx-ramblers/commit/4072610)

Comprehensive MongoDB backup/restore system with S3 integration, unified environment selectors, global settings, and admin-only config security.

**Where to Find It**

- **Admin → Backup/Restore**: Complete backup and restore interface
- **Settings → Global AWS S3 Configuration**: Bucket and region settings
- **History Tab**: Real-time updates with status colors

**Benefits**

- **Robust Backup/Restore**: Works across local filesystem and S3 with consistent UI
- **Global S3 Settings**: Centralized bucket/region configuration with per-environment fallback
- **Security Hardened**: Sensitive config fields redacted for non-admins
- **Organized S3 Structure**: Clear path layout s3://bucket/environment/database/timestamp-env-db/
- **Smart Upload Controls**: Upload checkbox disabled unless S3 is properly configured
- **Real-Time Status**: WebSocket updates with color-coded badges (sunrise/mintcake/sunset)
- **Better UX**: Select all/none, humanized labels, searchable dropdowns

**Technical Details**

Backend - S3 Strategy:
- Prefer global bucket/region from BackupConfig.aws with per-environment fallback
- S3 path layout: s3://global-bucket/environment/database/timestamp-env-db/
- Applies to upload, list, delete, and restore flows
- Consistent timestamp extraction/validation and pagination handling
- Local backups: parity with S3 using consistent shapes and NamedError

Backend - Security:
- GET /api/database/configs redacts sensitive fields for non-admins:
  - apiKey, accessKeyId, secretAccessKey, clientSecret
  - accessToken, refreshToken, password, username, userName
- Admin detection via JWT (memberAdmin/contentAdmin/fileAdmin/walkAdmin/socialAdmin/treasuryAdmin/financeAdmin)
- Non-admins receive redacted values

Frontend - Environment Selector:
- New unified app-environment-select component replaces two separate components
- Multi-select mode: [(selected)] returns EnvironmentInfo[]
  - Select all/none header, chips with native "×" clear
  - Humanized labels, dropdown appendTo body, dropdownPosition=bottom
- Single-select mode: [(selectedName)] returns environment name
- Replaces app-environment-multi-select and app-environment-single-select (removed)

Frontend - Collections & Display:
- Collections multi-select with consistent chip styling and header badge
- Backups sorted by -timestamp, then name (S3 and local)
- S3 badges show Environment/Database/Date
- Dates formatted via DateUtilsService

Frontend - Status & UX:
- Session status badges use app palette (sunrise/mintcake/sunset)
- "Select all" toggles to "Select none" when all selected
- Pluralization via pluraliseWithCount()
- Replaced yellow "warning" text with normal text in non-warning contexts
- Dropdowns append to body and open bottom (no clipping)

Frontend - Global S3 Settings:
- New "Global AWS S3 Configuration" section (Bucket, Region)
- Upload to S3 defaults to on
- Upload checkbox disabled with helper text unless global bucket set or all environments have AWS bucket
- Start Backup prevents submit if uploads enabled but S3 not configured

Code Structure:
- Added: environment-select.ts (unified selector)
- Removed: environment-multi-select.ts, environment-single-select.ts
- Updated: BackupConfig accepts optional aws: { bucket, region }
- Consistent use of array/date utils throughout

Testing Notes:
- Backup tab: select multiple environments, optional collections, Scale Down, Upload to S3
- Restore tab: single-select environment, choose S3 or Local backup, optional collections
- History tab: real-time updates with palette-aligned status colors
- S3 path verification: s3://global-bucket/env/db/timestamp-env-db/
- Configs API: verify redaction without admin JWT, full values with admin JWT