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
| Component | Technology | Version | Purpose |
|---|---|---|---|
| Runtime | Node.js | >= 18.x | JavaScript runtime |
| Framework | Express | 4.x | Web framework |
| Language | TypeScript | >= 5.x | Type-safe JavaScript |
| Database | MongoDB | >= 5.x | Schedule và template storage |
| ODM | Mongoose | 7.x | MongoDB object modeling |
| Queue | BullMQ | 5.x | Job queue với Redis |
| Cache/Queue Store | Redis | >= 6.x | BullMQ storage |
| Scheduler | node-cron | 3.x | Cron job scheduling |
| HTTP Client | Axios | 1.x | HTTP requests |
| Logging | Winston | 3.x | Structured logging |
External Services
| Service | Purpose |
|---|---|
| OpenStack Keystone | Authentication và token management |
| OpenStack Nova | Server actions (createImage, createBackup) |
| OpenStack Glance | Image 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 message2. 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 MongoDBThá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
| Feature | Snapshot | Backup |
|---|---|---|
| Nova Action | createImage | createBackup |
| Metadata Source | portal-manual | portal-auto |
| Rotation | ❌ No | ✅ Yes |
| Use Case | Manual snapshot | Scheduled backup |
Schedule Status States
| Status | Description |
|---|---|
idle | Schedule is waiting for next run |
pending | Schedule is queued |
running | Backup is in progress |
completed | Backup completed successfully |
failed | Backup failed (after retries) |
Template Frequency
| Frequency | Interval Days | Description |
|---|---|---|
daily | 1 | Run every day |
weekly | 7 | Run once per week |
monthly | 30 | Run once per month |
Next Steps
Trong các bài tiếp theo, chúng ta sẽ đi sâu vào:
- Authentication - OpenStack authentication và token management
- Snapshot & Backup - Tạo snapshot và backup
- Schedule System - Cron-based scheduler
- Queue Management - BullMQ integration
Last Updated: 2025-01-25
Next: 02. Authentication