# samirdash4u/dr_dc_switchover architecture

> Architecture diagram of the GitHub repository samirdash4u/dr_dc_switchover, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/samirdash4u/dr_dc_switchover
- Repository: https://github.com/samirdash4u/dr_dc_switchover

## Overview

#### Purpose and operating model
This is a shell-script automation repository for Appsone/HEAL DC-to-DR switchover. It supports isolated environments through an offline artifact boundary: DC exports state, an operator securely transfers a tarball, and DR restores or validates that state. DNS switching remains external/manual.

Primary entry points are the ordered DC and DR scripts, with a likely top-level coordinator at `orchestrator.sh`. Certificate import is separately invoked through `importcert.sh`.

#### Configuration and shared runtime
The scripts are configuration-driven and intended to use the same configuration in both sites:
- `config/config.sh` supplies database, backup/restore, and environment parameters.
- `config/dcnomadjoblist.txt` and `config/drnomadjoblist.txt` define expected Nomad workloads per site.
- `config/workerentry.sh` defines connector database endpoint updates.
- `common/logger.sh` and `common/utils.sh` provide shared script behavior.

The runtime is Bash/shell on hosts with access to local DC or DR infrastructure and command-line clients for the platform services.

#### DC readiness gate
The DC pipeline begins with prerequisite validation in `dc/01_prerequisites.sh`. This is the safety boundary before producing a switchover bundle: it checks availability/readiness of Consul, Nomad, MySQL, OpenSearch, disk capacity, and required Nomad jobs, using configured expected job lists such as `config/dcnomadjoblist.txt`.

Failure here should prevent downstream export stages from producing a potentially incomplete recovery artifact.

#### DC export pipeline
DC state is collected in explicit ordered stages:
- Database backup: `dc/02_db_dump.sh`
- Consul KV export: `dc/03_consul_export.sh`
- Nomad job/image definition export: `dc/04_nomad_export.sh`
- Bundle construction: `dc/05_package_artifacts.sh`

These stages transform live platform state into portable files, then package them as a timestamped `switchover_bundle_<timestamp>.tar.gz`. The tarball is the repository’s principal cross-environment contract; no direct DC-to-DR network flow is required or assumed.

#### Transfer boundary
Artifact movement is intentionally outside automation. An operator transfers the generated bundle to DR through an approved secure mechanism. This separates DC credentials and live service access from DR application, and allows the two sites to execute independently.

#### DR application and reconciliation pipeline
DR processing is also ordered:
- DR readiness validation: `dr/01_prerequisites.sh`
- Artifact extraction: `dr/02_unpack.sh`
- Database restore: `dr/03_db_restore.sh`
- Connector receiver endpoint rewrite: `dr/04_update_entry.sh`
- Consul comparison/reconciliation reporting: `dr/05_consul_match.sh`
- Nomad image/version comparison reporting: `dr/06_nomad_match.sh`

`dr/03_db_restore.sh` applies the database portion of the transferred state. The later Consul and Nomad stages are described as identifying missing keys and job image mismatches, making them validation/reconciliation boundaries rather than an assumed blind overwrite of DR runtime configuration.

#### Endpoint and certificate operations
Connector endpoint updates are data-level DR adaptations controlled by `config/workerentry.sh` and applied by `dr/04_update_entry.sh`. They support a default endpoint or database-specific overrides while preserving protocol/path behavior.

Certificate handling is an adjacent operational capability: `importcert.sh` uses certificate definitions in `config/certs.sh` to fetch/import certificates, skip existing aliases, or overwrite them. It is independent of the artifact pipeline but may be required for service connectivity after switchover.

Main entry points: [`dc/01_prerequisites.sh`](https://github.com/samirdash4u/dr_dc_switchover/blob/main/dc/01_prerequisites.sh) (DC readiness gate), [`dr/01_prerequisites.sh`](https://github.com/samirdash4u/dr_dc_switchover/blob/main/dr/01_prerequisites.sh) (DR readiness gate), [`dr/02_unpack.sh`](https://github.com/samirdash4u/dr_dc_switchover/blob/main/dr/02_unpack.sh) (Extract bundle), [`dr/04_update_entry.sh`](https://github.com/samirdash4u/dr_dc_switchover/blob/main/dr/04_update_entry.sh) (Rewrite connector endpoints)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_shared["Shared runtime"]
  node_config["Shared configuration<br/>shell config<br/>[config.sh]"]
  node_dc_jobs["DC expected jobs<br/>Nomad job list<br/>[dcnomadjoblist.txt]"]
  node_dr_jobs["DR expected jobs<br/>Nomad job list<br/>[drnomadjoblist.txt]"]
  node_shared_runtime["Shared shell runtime<br/>shell libraries<br/>[logger.sh]"]
end

subgraph group_dc["DC export"]
  node_dc_prereq{{"DC readiness gate<br/>shell stage"}}
  node_db_dump["Database backup<br/>shell stage<br/>[02_db_dump.sh]"]
  node_consul_export["Consul KV export<br/>shell stage"]
  node_nomad_export["Nomad definitions export<br/>shell stage<br/>[04_nomad_export.sh]"]
  node_package["Bundle artifacts<br/>shell stage"]
end

subgraph group_transfer["Offline transfer"]
  node_bundle["Switchover bundle<br/>tar.gz artifact"]
  node_operator{{"Secure operator transfer<br/>manual boundary"}}
end

subgraph group_dr["DR restore and reconciliation"]
  node_dr_prereq{{"DR readiness gate<br/>shell stage"}}
  node_unpack["Extract bundle<br/>shell stage<br/>[02_unpack.sh]"]
  node_db_restore["Database restore<br/>shell stage<br/>[03_db_restore.sh]"]
  node_worker_config["Connector endpoint rules<br/>shell config<br/>[workerentry.sh]"]
  node_update_entry["Rewrite connector endpoints<br/>shell stage<br/>[04_update_entry.sh]"]
  node_consul_match["Consul reconciliation report<br/>shell stage<br/>[05_consul_match.sh]"]
  node_nomad_match["Nomad version report<br/>shell stage<br/>[06_nomad_match.sh]"]
end

subgraph group_certs["Certificate operations"]
  node_cert_config["Certificate definitions<br/>shell config<br/>[certs.sh]"]
  node_cert_import["Certificate import<br/>shell operation<br/>[importcert.sh]"]
end

node_config -.->|"configures"| node_dc_prereq
node_dc_jobs -.->|"expected workloads"| node_dc_prereq
node_shared_runtime -.->|"shared behavior"| node_dc_prereq
node_dc_prereq -->|"gate passes"| node_db_dump
node_db_dump -->|"then"| node_consul_export
node_consul_export -->|"then"| node_nomad_export
node_nomad_export -->|"then"| node_package
node_package -->|"produces"| node_bundle
node_bundle -->|"handed to"| node_operator
node_operator -->|"delivers at DR"| node_unpack
node_config -.->|"configures"| node_dr_prereq
node_dr_jobs -.->|"expected workloads"| node_dr_prereq
node_shared_runtime -.->|"shared behavior"| node_dr_prereq
node_dr_prereq -->|"gate passes"| node_unpack
node_unpack -->|"database artifact"| node_db_restore
node_db_restore -->|"then"| node_update_entry
node_worker_config -.->|"endpoint rules"| node_update_entry
node_update_entry -->|"then"| node_consul_match
node_consul_match -->|"then"| node_nomad_match
node_cert_config -.->|"certificate definitions"| node_cert_import

click node_config "https://github.com/samirdash4u/dr_dc_switchover/blob/main/config/config.sh"
click node_dc_jobs "https://github.com/samirdash4u/dr_dc_switchover/blob/main/config/dcnomadjoblist.txt"
click node_dr_jobs "https://github.com/samirdash4u/dr_dc_switchover/blob/main/config/drnomadjoblist.txt"
click node_shared_runtime "https://github.com/samirdash4u/dr_dc_switchover/blob/main/common/logger.sh"
click node_dc_prereq "https://github.com/samirdash4u/dr_dc_switchover/blob/main/dc/01_prerequisites.sh"
click node_db_dump "https://github.com/samirdash4u/dr_dc_switchover/blob/main/dc/02_db_dump.sh"
click node_consul_export "https://github.com/samirdash4u/dr_dc_switchover/blob/main/dc/03_consul_export.sh"
click node_nomad_export "https://github.com/samirdash4u/dr_dc_switchover/blob/main/dc/04_nomad_export.sh"
click node_package "https://github.com/samirdash4u/dr_dc_switchover/blob/main/dc/05_package_artifacts.sh"
click node_dr_prereq "https://github.com/samirdash4u/dr_dc_switchover/blob/main/dr/01_prerequisites.sh"
click node_unpack "https://github.com/samirdash4u/dr_dc_switchover/blob/main/dr/02_unpack.sh"
click node_db_restore "https://github.com/samirdash4u/dr_dc_switchover/blob/main/dr/03_db_restore.sh"
click node_worker_config "https://github.com/samirdash4u/dr_dc_switchover/blob/main/config/workerentry.sh"
click node_update_entry "https://github.com/samirdash4u/dr_dc_switchover/blob/main/dr/04_update_entry.sh"
click node_consul_match "https://github.com/samirdash4u/dr_dc_switchover/blob/main/dr/05_consul_match.sh"
click node_nomad_match "https://github.com/samirdash4u/dr_dc_switchover/blob/main/dr/06_nomad_match.sh"
click node_cert_config "https://github.com/samirdash4u/dr_dc_switchover/blob/main/config/certs.sh"
click node_cert_import "https://github.com/samirdash4u/dr_dc_switchover/blob/main/importcert.sh"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_config,node_dc_jobs,node_dr_jobs,node_shared_runtime toneBlue
class node_dc_prereq,node_db_dump,node_consul_export,node_nomad_export,node_package toneAmber
class node_bundle,node_operator toneMint
class node_dr_prereq,node_unpack,node_db_restore,node_worker_config,node_update_entry,node_consul_match,node_nomad_match toneRose
class node_cert_config,node_cert_import toneIndigo
```

## Components

### Shared runtime

- [Shared configuration](https://github.com/samirdash4u/dr_dc_switchover/blob/main/config/config.sh): shell config · Database, backup, restore, and environment parameters. · `config/config.sh`
- [DC expected jobs](https://github.com/samirdash4u/dr_dc_switchover/blob/main/config/dcnomadjoblist.txt): Nomad job list · `config/dcnomadjoblist.txt`
- [DR expected jobs](https://github.com/samirdash4u/dr_dc_switchover/blob/main/config/drnomadjoblist.txt): Nomad job list · `config/drnomadjoblist.txt`
- [Shared shell runtime](https://github.com/samirdash4u/dr_dc_switchover/blob/main/common/logger.sh): shell libraries · Logging and utility behavior used by automation scripts. · `common/logger.sh`

### DC export

- [DC readiness gate](https://github.com/samirdash4u/dr_dc_switchover/blob/main/dc/01_prerequisites.sh): shell stage · Blocks export unless platform services, capacity, and expected jobs are ready. · `dc/01_prerequisites.sh`
- [Database backup](https://github.com/samirdash4u/dr_dc_switchover/blob/main/dc/02_db_dump.sh): shell stage · `dc/02_db_dump.sh`
- [Consul KV export](https://github.com/samirdash4u/dr_dc_switchover/blob/main/dc/03_consul_export.sh): shell stage · `dc/03_consul_export.sh`
- [Nomad definitions export](https://github.com/samirdash4u/dr_dc_switchover/blob/main/dc/04_nomad_export.sh): shell stage · `dc/04_nomad_export.sh`
- [Bundle artifacts](https://github.com/samirdash4u/dr_dc_switchover/blob/main/dc/05_package_artifacts.sh): shell stage · Creates the timestamped switchover tarball. · `dc/05_package_artifacts.sh`

### Offline transfer

- **Switchover bundle**: tar.gz artifact · Portable DC state contract for DR.
- **Secure operator transfer**: manual boundary · Approved offline movement between sites.

### DR restore and reconciliation

- [DR readiness gate](https://github.com/samirdash4u/dr_dc_switchover/blob/main/dr/01_prerequisites.sh): shell stage · `dr/01_prerequisites.sh`
- [Extract bundle](https://github.com/samirdash4u/dr_dc_switchover/blob/main/dr/02_unpack.sh): shell stage · `dr/02_unpack.sh`
- [Database restore](https://github.com/samirdash4u/dr_dc_switchover/blob/main/dr/03_db_restore.sh): shell stage · Applies the transferred database state. · `dr/03_db_restore.sh`
- [Connector endpoint rules](https://github.com/samirdash4u/dr_dc_switchover/blob/main/config/workerentry.sh): shell config · Default and database-specific DR endpoint updates. · `config/workerentry.sh`
- [Rewrite connector endpoints](https://github.com/samirdash4u/dr_dc_switchover/blob/main/dr/04_update_entry.sh): shell stage · `dr/04_update_entry.sh`
- [Consul reconciliation report](https://github.com/samirdash4u/dr_dc_switchover/blob/main/dr/05_consul_match.sh): shell stage · Identifies missing keys without assuming blind overwrite. · `dr/05_consul_match.sh`
- [Nomad version report](https://github.com/samirdash4u/dr_dc_switchover/blob/main/dr/06_nomad_match.sh): shell stage · Identifies job image and version mismatches. · `dr/06_nomad_match.sh`

### Certificate operations

- [Certificate definitions](https://github.com/samirdash4u/dr_dc_switchover/blob/main/config/certs.sh): shell config · `config/certs.sh`
- [Certificate import](https://github.com/samirdash4u/dr_dc_switchover/blob/main/importcert.sh): shell operation · Imports, skips, or overwrites certificate aliases independently of switchover. · `importcert.sh`

## Connections

- Shared configuration → DC readiness gate: configures
- DC expected jobs → DC readiness gate: expected workloads
- Shared shell runtime → DC readiness gate: shared behavior
- DC readiness gate → Database backup: gate passes
- Database backup → Consul KV export: then
- Consul KV export → Nomad definitions export: then
- Nomad definitions export → Bundle artifacts: then
- Bundle artifacts → Switchover bundle: produces
- Switchover bundle → Secure operator transfer: handed to
- Secure operator transfer → Extract bundle: delivers at DR
- Shared configuration → DR readiness gate: configures
- DR expected jobs → DR readiness gate: expected workloads
- Shared shell runtime → DR readiness gate: shared behavior
- DR readiness gate → Extract bundle: gate passes
- Extract bundle → Database restore: database artifact
- Database restore → Rewrite connector endpoints: then
- Connector endpoint rules → Rewrite connector endpoints: endpoint rules
- Rewrite connector endpoints → Consul reconciliation report: then
- Consul reconciliation report → Nomad version report: then
- Certificate definitions → Certificate import: certificate definitions
