Skip to content

OpenStack Backup Cloud Server - Documentation

Giới thiệu

Bộ tài liệu chi tiết về implementation hệ thống backup cloud server sử dụng OpenStack APIs trong Node.js + TypeScript + Express.

Tổng quan

Hệ thống backup cloud server cho phép:

  • ✅ Tạo backup/snapshot tự động theo lịch (scheduled backup)
  • ✅ Tạo backup/snapshot thủ công (manual backup)
  • ✅ Quản lý template backup để tái sử dụng cấu hình
  • ✅ Hỗ trợ multi-location (HCM và Hà Nội)
  • ✅ Quản lý queue với BullMQ và Redis
  • ✅ Giới hạn số lượng snapshot để kiểm soát storage
  • ✅ Metadata management cho snapshot/backup

Cấu trúc bài học (9 bài)

🎯 00. Case Study - Executive Summary

TL;DR cho Leaders và Stakeholders

  • Vấn đề kỹ thuật & giải pháp
  • Kiến trúc hệ thống
  • Metrics & ROI
  • Lessons learned
  • Production deployment

Thời gian: 15-20 phút
Level: All levels
Format: Template-based case study


Phần 1: Foundations (Nền tảng)

01. Tổng quan OpenStack và Backup System

  • OpenStack là gì?
  • Kiến trúc OpenStack (Nova, Glance, Keystone)
  • Kiến trúc hệ thống backup trong Portal
  • Flow hoạt động cơ bản
  • Stack công nghệ

Thời gian: 20-30 phút
Level: Beginner
Mục tiêu: Hiểu big picture về OpenStack và hệ thống backup


02. Xác thực OpenStack và Token Management

  • OpenStack Keystone authentication
  • Scoped token (project-scoped)
  • Token lifecycle và refresh
  • Multi-location authentication (HCM/HNI)
  • Environment variables configuration
  • Error handling

Thời gian: 30-40 phút
Level: Beginner → Intermediate
Mục tiêu: Master OpenStack authentication flow


03. Tạo Snapshot và Backup với OpenStack

  • Nova API: createImage action
  • Glance API: image management
  • Snapshot vs Backup trong OpenStack
  • Polling image status
  • Metadata management (OS info, source tracking)
  • Error handling và timeout

Thời gian: 45-60 phút
Level: Intermediate
Mục tiêu: Hiểu và implement tạo snapshot/backup


Phần 2: Scheduling & Queue System

04. Hệ thống Lịch Backup (Schedule System)

  • BackupSchedule model
  • Cron job scheduler (node-cron)
  • Tính toán nextRunAt
  • Timezone handling
  • Location-based scheduling
  • Status tracking (idle, pending, running, completed, failed)

Thời gian: 40-50 phút
Level: Intermediate
Mục tiêu: Hiểu schedule system và cron implementation


05. Quản lý Queue với BullMQ

  • BullMQ và Redis integration
  • Queue configuration (concurrency, retry, limiter)
  • Worker implementation
  • Job processing flow
  • Error handling và retry logic
  • Queue monitoring và health checks
  • Job recovery sau restart

Thời gian: 50-60 phút
Level: Intermediate → Advanced
Mục tiêu: Master queue management với BullMQ


06. Template-Based Backup System

  • BackupScheduleTemplate model
  • Template benefits (DRY, consistency)
  • Find or create pattern
  • Apply template to multiple servers
  • Migration từ old system
  • Template CRUD operations

Thời gian: 35-45 phút
Level: Intermediate
Mục tiêu: Hiểu template system và cách sử dụng


Phần 3: Advanced Topics

07. Multi-Location Support (HCM/HNI)

  • Location-based OpenStack endpoints
  • Environment variables per location
  • Normalize location function
  • Location trong BackupSchedule
  • Endpoint routing logic
  • Testing multi-location

Thời gian: 30-40 phút
Level: Intermediate
Mục tiêu: Hiểu và implement multi-location support


08. Snapshot Limit và Retention Policy

  • Snapshot limit check logic
  • Manual vs Scheduled backup limits
  • Retention policy (retain count)
  • Cleanup old snapshots
  • Filter snapshots by source
  • Error handling khi vượt limit

Thời gian: 35-45 phút
Level: Intermediate
Mục tiêu: Implement snapshot limit và retention


09. Production Best Practices

  • Error handling patterns
  • Logging strategy
  • Monitoring và alerting
  • Graceful shutdown
  • Job recovery
  • Performance optimization
  • Troubleshooting guide

Thời gian: 40-50 phút
Level: Advanced
Mục tiêu: Deploy và maintain production system


Quick Start

Nếu bạn là Leader/Stakeholder

  1. 🎯 Case Study - TL;DR (vấn đề, giải pháp, metrics, ROI)

Nếu bạn mới bắt đầu

  1. Tổng quan OpenStack - Hiểu bức tranh tổng thể
  2. Xác thực OpenStack - Hiểu authentication flow
  3. Tạo Snapshot/Backup - Implement tạo backup

Nếu bạn đang triển khai

  1. Schedule System - Thiết lập lịch backup
  2. Queue Management - Quản lý queue
  3. Template System - Sử dụng template
  4. Multi-Location - Hỗ trợ nhiều location

Nếu bạn cần optimize

  1. Snapshot Limits - Giới hạn và cleanup
  2. Production Practices - Best practices

Prerequisites

Kiến thức cần có

  • Node.js: Async/await, Promises, Event loop
  • TypeScript: Interfaces, types, generics
  • Express: Middleware, routes, controllers
  • MongoDB: Mongoose ODM, queries
  • ⚠️ Redis: Cơ bản về Redis (hữu ích cho BullMQ)
  • ⚠️ OpenStack: Hiểu biết cơ bản về Nova/Glance (hữu ích)

Môi trường

bash
Node.js: >= 18.x
npm: >= 9.x
TypeScript: >= 5.x
MongoDB: >= 5.x
Redis: >= 6.x (cho BullMQ)

Key Takeaways

✅ Điểm mạnh

  1. OpenStack Integration: Hỗ trợ đầy đủ Nova và Glance APIs
  2. Template System: Dễ dàng quản lý backup configuration
  3. Queue System: Xử lý backup jobs hiệu quả với BullMQ
  4. Multi-Location: Hỗ trợ HCM và Hà Nội cùng lúc

⚠️ Điểm cần lưu ý

  1. Token Management: Token có thời hạn, cần refresh đúng cách
  2. Polling Logic: Image status polling cần timeout hợp lý
  3. Error Handling: Cần xử lý lỗi từ nhiều nguồn (OpenStack, MongoDB, Redis)
  4. Location Routing: Đảm bảo gọi đúng endpoint theo location

🎯 Best Practices

typescript
// ✅ DO: Always normalize location
const normalizedLocation = location && location !== '' ? (location === 'HNI' ? 'HNI' : 'HCM') : 'HCM';

// ❌ DON'T: Assume location
if (location === 'HNI') { ... } // Missing default case
typescript
// ✅ DO: Poll with timeout
const timeoutMs = 30 * 60 * 1000; // 30 minutes
while (Date.now() - startedAt < timeoutMs) {
  // poll status
}

// ❌ DON'T: Poll forever
while (true) {
  // poll status - could hang forever
}
typescript
// ✅ DO: Use template pattern
const template = await findOrCreateDefaultTemplate(customerEmail);
await upsertBackupSchedule({ ...template, scheduleTemplateId: template._id });

// ❌ DON'T: Hardcode configuration
await upsertBackupSchedule({ startHour: 2, intervalDays: 7, retain: 1 });

Tham khảo nhanh xử lý sự cố

Vấn đềGiải phápLiên kết
Token expiredRefresh token#02
Backup timeoutKiểm tra timeout settings#03
Queue không hoạt độngKiểm tra Redis connection#05
Template không applyKiểm tra template ID#06
Wrong location endpointKiểm tra normalize location#07
Snapshot limit exceededKiểm tra retain policy#08
Jobs bị stuckCheck job recovery#09

Kho lưu trữ ví dụ code

Tất cả ví dụ trong docs đều dựa trên code thực tế từ:

Backend:

  • portal-server/src/services/client/OpenStackService.ts
  • portal-server/src/services/client/BackupScheduleService.ts
  • portal-server/src/services/client/BackupScheduleTemplateService.ts
  • portal-server/src/services/shared/BackupScheduler.ts
  • portal-server/src/services/shared/BackupQueueManager.ts
  • portal-server/src/utils/OpenStackVars.ts
  • portal-server/src/models/BackupSchedule.ts
  • portal-server/src/models/BackupScheduleTemplate.ts

Phản hồi & Đóng góp

Tài liệu này được viết dựa trên kinh nghiệm thực tế khi triển khai OpenStack backup system.

Nếu bạn:

  • ❓ Có câu hỏi
  • 🐛 Tìm thấy lỗi
  • 💡 Có ý tưởng cải thiện
  • ✅ Muốn bổ sung

→ Liên hệ team hoặc tạo issue.

Giấy phép

Tài liệu nội bộ cho dự án portal iNET.


Happy coding! 🚀

Documentation này được viết dựa trên kinh nghiệm thực tế khi implement OpenStack backup system.

Last Updated: 2025-01-25
Version: 1.0.0
Status: ✅ Production Ready

Internal documentation for iNET Portal