Skip to content

Tổng quan OpenStack và Backup System

Giới thiệu

Trong bài này, chúng ta sẽ tìm hiểu về OpenStack và kiến trúc hệ thống backup cloud server trong Portal.


OpenStack là gì?

OpenStack là một nền tảng cloud computing mã nguồn mở, cho phép xây dựng và quản lý hạ tầng cloud (Infrastructure as a Service - IaaS).

Các thành phần chính

1. Nova (Compute)

  • Quản lý virtual machines (VMs)
  • Server lifecycle (create, delete, start, stop, reboot)
  • Server actions (snapshot, backup, rebuild)
  • API endpoint: /compute/v2.1

2. Glance (Image Service)

  • Quản lý images (VM images, snapshots, backups)
  • Image metadata management
  • Image storage và retrieval
  • API endpoint: /image/v2

3. Keystone (Identity Service)

  • Authentication và authorization
  • Token management
  • Service catalog
  • API endpoint: /identity/v3

4. Cinder (Block Storage)

  • Quản lý block storage volumes
  • Volume snapshots
  • Không được sử dụng trực tiếp trong backup system của chúng ta

5. Neutron (Networking)

  • Quản lý network và networking services
  • Không được sử dụng trực tiếp trong backup system

Kiến trúc OpenStack APIs

API Gateway Pattern

Portal Server

OpenStack Gateway (opsgw-staging.000nethost.com)

┌─────────────────────────────────────┐
│  OpenStack Services                 │
├─────────────────────────────────────┤
│  • Keystone (Identity)              │
│  • Nova (Compute)                   │
│  • Glance (Image Service)           │
└─────────────────────────────────────┘

Multi-Location Architecture

Portal Server

Location Router (HCM/HNI)

┌─────────────────┐  ┌─────────────────┐
│  OpenStack HCM  │  │  OpenStack HNI  │
│                 │  │                 │
│  • Keystone HCM │  │  • Keystone HNI │
│  • Nova HCM     │  │  • Nova HNI     │
│  • Glance HCM   │  │  • Glance HNI   │
└─────────────────┘  └─────────────────┘

Kiến trúc Hệ thống Backup trong Portal

High-Level Architecture

┌─────────────────────────────────────────────────────────┐
│  Portal Server (Node.js + Express + TypeScript)        │
├─────────────────────────────────────────────────────────┤
│                                                         │
│  ┌──────────────────────────────────────────────────┐  │
│  │  Backup Scheduler (Cron Job)                    │  │
│  │  • Check due schedules every hour               │  │
│  │  • Queue backup jobs                            │  │
│  └──────────────────────────────────────────────────┘  │
│                        ↓                                │
│  ┌──────────────────────────────────────────────────┐  │
│  │  Backup Queue Manager (BullMQ + Redis)          │  │
│  │  • Queue jobs                                    │  │
│  │  • Worker với concurrency control                │  │
│  │  • Retry logic                                   │  │
│  └──────────────────────────────────────────────────┘  │
│                        ↓                                │
│  ┌──────────────────────────────────────────────────┐  │
│  │  Backup Schedule Service                         │  │
│  │  • Execute backup                                │  │
│  │  • Update schedule status                        │  │
│  └──────────────────────────────────────────────────┘  │
│                        ↓                                │
│  ┌──────────────────────────────────────────────────┐  │
│  │  OpenStack Service                               │  │
│  │  • Authentication (Keystone)                     │  │
│  │  • Create snapshot/backup (Nova)                 │  │
│  │  • Poll image status (Glance)                    │  │
│  └──────────────────────────────────────────────────┘  │
│                        ↓                                │
│  ┌──────────────────────────────────────────────────┐  │
│  │  OpenStack APIs                                  │  │
│  │  • HCM Endpoint                                  │  │
│  │  • HNI Endpoint                                  │  │
│  └──────────────────────────────────────────────────┘  │
└─────────────────────────────────────────────────────────┘

Data Flow

1. Cron Scheduler (every hour)

2. Check due schedules (MongoDB query)

3. Queue backup jobs (BullMQ)

4. Worker picks up job

5. Backup Schedule Service executes backup

6. OpenStack Service:
   a. Get scoped token (Keystone)
   b. Create backup (Nova createBackup)
   c. Poll image status (Glance)
   d. Update metadata (Glance PATCH)

7. Update schedule status (MongoDB)

8. Cleanup old snapshots (if needed)

Stack Công nghệ

Backend Stack

ComponentTechnologyVersionPurpose
RuntimeNode.js>= 18.xJavaScript runtime
FrameworkExpress4.xWeb framework
LanguageTypeScript>= 5.xType-safe JavaScript
DatabaseMongoDB>= 5.xSchedule và template storage
ODMMongoose7.xMongoDB object modeling
QueueBullMQ5.xJob queue với Redis
Cache/Queue StoreRedis>= 6.xBullMQ storage
Schedulernode-cron3.xCron job scheduling
HTTP ClientAxios1.xHTTP requests
LoggingWinston3.xStructured logging

External Services

ServicePurpose
OpenStack KeystoneAuthentication và token management
OpenStack NovaServer actions (createImage, createBackup)
OpenStack GlanceImage management và status polling

Flow Hoạt động Cơ bản

1. Manual Backup (User Initiated)

User clicks "Create Backup"

Frontend calls API: POST /api/v1/cloud-server/:id/snapshot

Backend: Check snapshot limit

Backend: OpenStackService.createServerSnapshotOpenStack()

  a. Get scoped token
  b. Nova: POST /servers/{id}/action { createImage: {...} }
  c. Get image ID from Location header
  d. Glance: Poll GET /v2/images/{id} until status = 'active'
  e. Glance: PATCH /v2/images/{id} (update metadata)

Backend: Return image ID và details

Frontend: Show success message

2. Scheduled Backup (Automated)

Cron job runs every hour at minute 5

BackupScheduler: Check due schedules

For each due schedule:
   a. Update status = 'pending'
   b. Calculate nextRunAt
   c. Queue job: backupQueueManager.addBackupJob()

BullMQ Worker picks up job

BackupScheduleService.runSingleBackup()

  a. Get server details
  b. Generate backup name
  c. OpenStackService.createServerBackupOpenStack()
     - Get scoped token
     - Nova: POST /servers/{id}/action { createBackup: {...} }
     - Poll image status
     - Update metadata
  d. Create/update SnapshotMeta
  e. Cleanup old snapshots (if exceed retain)

Update schedule status = 'completed'

3. Template-Based Configuration

User creates/updates backup schedule

Frontend calls API with templateId

Backend: BackupScheduleTemplateService.findOrCreateTemplate()

Backend: BackupScheduleService.upsertBackupSchedule()

  - Link schedule to template
  - Copy template config (frequency, startHour, rotate)
  - Calculate nextRunAt

Save to MongoDB

Thách thức Kỹ thuật

1. OpenStack API Complexity

Vấn đề:

  • APIs khác nhau cho từng service
  • Authentication phức tạp (scoped tokens)
  • Error responses không consistent

Giải pháp:

  • Wrapper service (OpenStackService.ts)
  • Centralized authentication (getScopedToken())
  • Standardized error handling

2. Async Image Creation

Vấn đề:

  • Image creation là async process
  • Cần polling status
  • Timeout handling

Giải pháp:

  • Polling loop với timeout (30 phút)
  • Exponential backoff trong retry
  • Status tracking

3. Multi-Location Support

Vấn đề:

  • HCM và HNI có endpoints khác nhau
  • Environment variables khác nhau
  • Routing logic phức tạp

Giải pháp:

  • Location normalization function
  • Environment variables per location
  • Centralized configuration (getOpenStackEnv())

4. Schedule System Reliability

Vấn đề:

  • Cron jobs có thể miss
  • Timezone handling
  • Status tracking

Giải pháp:

  • Hourly cron check
  • Timezone-aware calculation (moment-timezone)
  • Status states (idle, pending, running, completed, failed)

5. Queue Job Management

Vấn đề:

  • Thousands of jobs
  • Concurrency control
  • Retry logic
  • Job recovery

Giải pháp:

  • BullMQ với Redis
  • Configurable concurrency (7 jobs)
  • Exponential backoff retry
  • Job recovery mechanism

Key Concepts

Snapshot vs Backup

FeatureSnapshotBackup
Nova ActioncreateImagecreateBackup
Metadata Sourceportal-manualportal-auto
Rotation❌ No✅ Yes
Use CaseManual snapshotScheduled backup

Schedule Status States

StatusDescription
idleSchedule is waiting for next run
pendingSchedule is queued
runningBackup is in progress
completedBackup completed successfully
failedBackup failed (after retries)

Template Frequency

FrequencyInterval DaysDescription
daily1Run every day
weekly7Run once per week
monthly30Run once per month

Next Steps

Trong các bài tiếp theo, chúng ta sẽ đi sâu vào:

  1. Authentication - OpenStack authentication và token management
  2. Snapshot & Backup - Tạo snapshot và backup
  3. Schedule System - Cron-based scheduler
  4. Queue Management - BullMQ integration

Last Updated: 2025-01-25
Next: 02. Authentication

Internal documentation for iNET Portal