|
| 1 | +# Gateway Maintenance Script Documentation |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +The `maintenance.ps1` script performs routine maintenance tasks for the NHS Rubie Gateway installation. It provides automated operations for: |
| 6 | + |
| 7 | +* MWL database backup |
| 8 | +* PACS database backup |
| 9 | +* PACS storage archiving |
| 10 | +* Service log rotation |
| 11 | + |
| 12 | +The script ensures that Gateway services are safely stopped before maintenance activities are performed and restarted afterwards. |
| 13 | + |
| 14 | +--- |
| 15 | + |
| 16 | +# Script Location |
| 17 | + |
| 18 | +```text |
| 19 | +<InstallPath>\current\scripts\powershell\maintenance.ps1 |
| 20 | +``` |
| 21 | + |
| 22 | +Default installation path: |
| 23 | + |
| 24 | +```text |
| 25 | +C:\Program Files\NHS\ManageBreastScreeningGateway |
| 26 | +``` |
| 27 | + |
| 28 | +Scheduled tasks are configured in the Windows Task Scheduler via the `deploy.ps1` script. |
| 29 | +The `deploy.ps1` script is located at: |
| 30 | + |
| 31 | +```text |
| 32 | +<InstallPath>\current\scripts\powershell\deploy.ps1 |
| 33 | +``` |
| 34 | + |
| 35 | +--- |
| 36 | + |
| 37 | +# Parameters |
| 38 | + |
| 39 | +| Parameter | Description | Default | |
| 40 | +| ----------------- | ------------------------------------------------------- | --------------------------------------------------- | |
| 41 | +| `BaseInstallPath` | Root installation directory of the Gateway application. | `C:\Program Files\NHS\ManageBreastScreeningGateway` | |
| 42 | +| `Action` | Maintenance operation to execute. | None | |
| 43 | + |
| 44 | +### Supported Actions |
| 45 | + |
| 46 | +| Action | Description | |
| 47 | +| -------------------- | --------------------------------------------------------------------- | |
| 48 | +| `BackupMWLDatabase` | Creates a backup of the MWL database. | |
| 49 | +| `BackupPACSDatabase` | Creates a backup of the PACS database and archives stored PACS files. | |
| 50 | +| `RotateLogs` | Rotates Gateway service log files. | |
| 51 | + |
| 52 | +### Example |
| 53 | + |
| 54 | +```powershell |
| 55 | +.\maintenance.ps1 -Action BackupMWLDatabase |
| 56 | +``` |
| 57 | + |
| 58 | +--- |
| 59 | + |
| 60 | +# Logging |
| 61 | + |
| 62 | +Maintenance activity is recorded in: |
| 63 | + |
| 64 | +```text |
| 65 | +<InstallPath>\logs\maintenance.log |
| 66 | +``` |
| 67 | + |
| 68 | +Each log entry includes: |
| 69 | + |
| 70 | +* Timestamp |
| 71 | +* Log level |
| 72 | +* Message |
| 73 | + |
| 74 | +Example: |
| 75 | + |
| 76 | +```text |
| 77 | +[2026-01-01 02:00:00.123] [INFO] Starting database backup... |
| 78 | +``` |
| 79 | + |
| 80 | +### Log Levels |
| 81 | + |
| 82 | +| Level | Meaning | |
| 83 | +| ------- | ------------------------------------- | |
| 84 | +| INFO | Informational messages | |
| 85 | +| SUCCESS | Successful completion of an operation | |
| 86 | +| WARNING | Non-critical issue | |
| 87 | +| ERROR | Operation failure | |
| 88 | + |
| 89 | +--- |
| 90 | + |
| 91 | +# Gateway Service Management |
| 92 | + |
| 93 | +The script automatically discovers services matching: |
| 94 | + |
| 95 | +```text |
| 96 | +Gateway-* |
| 97 | +``` |
| 98 | + |
| 99 | +Examples: |
| 100 | + |
| 101 | +```text |
| 102 | +Gateway-MWL |
| 103 | +Gateway-PACS |
| 104 | +Gateway-Relay |
| 105 | +Gateway-Listener |
| 106 | +``` |
| 107 | + |
| 108 | +## Service Stop Process |
| 109 | + |
| 110 | +Before maintenance operations begin: |
| 111 | + |
| 112 | +1. Each running Gateway service is stopped. |
| 113 | +2. Service state is monitored until it reaches `Stopped`. |
| 114 | +3. If a service fails to stop within the configured timeout, an exception is raised and processing stops. |
| 115 | + |
| 116 | +## Service Start Process |
| 117 | + |
| 118 | +After maintenance operations complete: |
| 119 | + |
| 120 | +1. Each Gateway service is started. |
| 121 | +2. Service state is monitored until it reaches `Running`. |
| 122 | +3. Successful startup is logged. |
| 123 | + |
| 124 | +--- |
| 125 | + |
| 126 | +# Database Backup Operations |
| 127 | + |
| 128 | +## Common Backup Configuration |
| 129 | + |
| 130 | +The script sets the following environment variables before invoking the Python backup utility: |
| 131 | + |
| 132 | +| Variable | Value | |
| 133 | +| ------------- | -------------------------------------- | |
| 134 | +| `PYTHONPATH` | `<InstallPath>\current\scripts\python` | |
| 135 | +| `BACKUP_PATH` | `<InstallPath>\data\backups` | |
| 136 | +| `MAX_BACKUPS` | `5` | |
| 137 | + |
| 138 | +The backup process is executed using: |
| 139 | + |
| 140 | +```powershell |
| 141 | +..\python\database.py |
| 142 | +``` |
| 143 | + |
| 144 | +Only the most recent five backups are retained. |
| 145 | + |
| 146 | +--- |
| 147 | + |
| 148 | +## MWL Database Backup |
| 149 | + |
| 150 | +Action: |
| 151 | + |
| 152 | +```powershell |
| 153 | +BackupMWLDatabase |
| 154 | +``` |
| 155 | + |
| 156 | +Database configuration: |
| 157 | + |
| 158 | +| Setting | Value | |
| 159 | +| ------------- | -------------------------------- | |
| 160 | +| Database File | `<InstallPath>\data\worklist.db` | |
| 161 | +| Table Name | `worklist_items` | |
| 162 | + |
| 163 | +Process: |
| 164 | + |
| 165 | +1. Stop Gateway services. |
| 166 | +2. Backup MWL database. |
| 167 | +3. Restart Gateway services. |
| 168 | + |
| 169 | +--- |
| 170 | + |
| 171 | +## PACS Database Backup |
| 172 | + |
| 173 | +Action: |
| 174 | + |
| 175 | +```powershell |
| 176 | +BackupPACSDatabase |
| 177 | +``` |
| 178 | + |
| 179 | +Database configuration: |
| 180 | + |
| 181 | +| Setting | Value | |
| 182 | +| ------------- | ---------------------------- | |
| 183 | +| Database File | `<InstallPath>\data\pacs.db` | |
| 184 | +| Table Name | `stored_instances` | |
| 185 | + |
| 186 | +Process: |
| 187 | + |
| 188 | +1. Stop Gateway services. |
| 189 | +2. Backup PACS database. |
| 190 | +3. Archive PACS storage files. |
| 191 | +4. Restart Gateway services. |
| 192 | + |
| 193 | +--- |
| 194 | + |
| 195 | +# PACS Archive Process |
| 196 | + |
| 197 | +After a successful PACS database backup: |
| 198 | + |
| 199 | +## Source Directory |
| 200 | + |
| 201 | +```text |
| 202 | +<InstallPath>\data\storage |
| 203 | +``` |
| 204 | + |
| 205 | +## Archive Location |
| 206 | + |
| 207 | +```text |
| 208 | +<InstallPath>\data\storage.zip |
| 209 | +``` |
| 210 | + |
| 211 | +## Process |
| 212 | + |
| 213 | +1. All files within the PACS storage directory are compressed into a ZIP archive. |
| 214 | +2. Archive is written to `storage.zip`. |
| 215 | +3. Original storage contents are deleted. |
| 216 | +4. Archive operation is logged. |
| 217 | + |
| 218 | +### Important |
| 219 | + |
| 220 | +The archive operation removes all files from the PACS storage directory after successful compression. |
| 221 | + |
| 222 | +--- |
| 223 | + |
| 224 | +# Log Rotation |
| 225 | + |
| 226 | +Action: |
| 227 | + |
| 228 | +```powershell |
| 229 | +RotateLogs |
| 230 | +``` |
| 231 | + |
| 232 | +The script rotates log files for each Gateway service. |
| 233 | + |
| 234 | +Example: |
| 235 | + |
| 236 | +```text |
| 237 | +Gateway-MWL.log |
| 238 | +``` |
| 239 | + |
| 240 | +becomes: |
| 241 | + |
| 242 | +```text |
| 243 | +Gateway-MWL.log.1 |
| 244 | +``` |
| 245 | + |
| 246 | +Existing rotations are shifted: |
| 247 | + |
| 248 | +```text |
| 249 | +Gateway-MWL.log.1 -> Gateway-MWL.log.2 |
| 250 | +Gateway-MWL.log.2 -> Gateway-MWL.log.3 |
| 251 | +... |
| 252 | +Gateway-MWL.log.5 removed |
| 253 | +``` |
| 254 | + |
| 255 | +## Retention Policy |
| 256 | + |
| 257 | +* Maximum retained log generations: 5 |
| 258 | +* Oldest rotation is deleted before creating a new rotation |
| 259 | + |
| 260 | +Process: |
| 261 | + |
| 262 | +1. Stop Gateway services. |
| 263 | +2. Rotate all service logs. |
| 264 | +3. Restart Gateway services. |
| 265 | + |
| 266 | +--- |
| 267 | + |
| 268 | +# Scheduled Tasks |
| 269 | + |
| 270 | +The script registers three Windows Scheduled Tasks. |
| 271 | + |
| 272 | +## MWL Database Maintenance |
| 273 | + |
| 274 | +| Setting | Value | |
| 275 | +| --------- | ------------------------- | |
| 276 | +| Task Name | `Gateway-MWL-Maintenance` | |
| 277 | +| Schedule | Weekly | |
| 278 | +| Day | Sunday | |
| 279 | +| Time | 02:00 | |
| 280 | +| User | SYSTEM | |
| 281 | +| Run Level | Highest | |
| 282 | + |
| 283 | +Executed command: |
| 284 | + |
| 285 | +```powershell |
| 286 | +powershell.exe -ExecutionPolicy Bypass -File maintenance.ps1 -Action BackupMWLDatabase |
| 287 | +``` |
| 288 | + |
| 289 | +--- |
| 290 | + |
| 291 | +## PACS Database Maintenance |
| 292 | + |
| 293 | +| Setting | Value | |
| 294 | +| --------- | -------------------------- | |
| 295 | +| Task Name | `Gateway-PACS-Maintenance` | |
| 296 | +| Schedule | Weekly | |
| 297 | +| Day | Sunday | |
| 298 | +| Time | 02:15 | |
| 299 | +| User | SYSTEM | |
| 300 | +| Run Level | Highest | |
| 301 | + |
| 302 | +Executed command: |
| 303 | + |
| 304 | +```powershell |
| 305 | +powershell.exe -ExecutionPolicy Bypass -File maintenance.ps1 -Action BackupPACSDatabase |
| 306 | +``` |
| 307 | + |
| 308 | +--- |
| 309 | + |
| 310 | +## Log Rotation Maintenance |
| 311 | + |
| 312 | +| Setting | Value | |
| 313 | +| --------- | -------------------------- | |
| 314 | +| Task Name | `Gateway-Logs-Maintenance` | |
| 315 | +| Schedule | Daily | |
| 316 | +| Time | 02:30 | |
| 317 | +| User | SYSTEM | |
| 318 | +| Run Level | Highest | |
| 319 | + |
| 320 | +Executed command: |
| 321 | + |
| 322 | +```powershell |
| 323 | +powershell.exe -ExecutionPolicy Bypass -File maintenance.ps1 -Action RotateLogs |
| 324 | +``` |
| 325 | + |
| 326 | +--- |
| 327 | + |
| 328 | +# Failure Handling |
| 329 | + |
| 330 | +The script terminates when: |
| 331 | + |
| 332 | +* A Gateway service cannot be stopped within the configured timeout. |
| 333 | +* The database backup utility returns a non-zero exit code. |
| 334 | +* An unhandled PowerShell exception occurs. |
| 335 | + |
| 336 | +Errors are written to: |
| 337 | + |
| 338 | +```text |
| 339 | +<InstallPath>\logs\maintenance.log |
| 340 | +``` |
| 341 | + |
| 342 | +and displayed on the console. |
| 343 | + |
| 344 | +--- |
| 345 | + |
| 346 | +# Maintenance Workflow Summary |
| 347 | + |
| 348 | +## MWL Backup |
| 349 | + |
| 350 | +```text |
| 351 | +Stop Services |
| 352 | + ↓ |
| 353 | +Backup MWL Database |
| 354 | + ↓ |
| 355 | +Start Services |
| 356 | +``` |
| 357 | + |
| 358 | +## PACS Backup |
| 359 | + |
| 360 | +```text |
| 361 | +Stop Services |
| 362 | + ↓ |
| 363 | +Backup PACS Database |
| 364 | + ↓ |
| 365 | +Archive PACS Files |
| 366 | + ↓ |
| 367 | +Start Services |
| 368 | +``` |
| 369 | + |
| 370 | +## Log Rotation |
| 371 | + |
| 372 | +```text |
| 373 | +Stop Services |
| 374 | + ↓ |
| 375 | +Rotate Logs |
| 376 | + ↓ |
| 377 | +Start Services |
| 378 | +``` |
| 379 | + |
0 commit comments