⏱️ 4 giờ
🏗️ Architecture
🔌 REST API
🛡️ RBAC
🎓 Kết Quả Học Tập
- ✅ Sử dụng Veeam Enterprise Manager để quản lý tập trung nhiều sites
- ✅ Cấu hình RBAC — phân quyền đúng theo nguyên tắc least privilege
- ✅ Gọi Veeam REST API: authenticate, list jobs, trigger job
- ✅ Viết PowerShell script giám sát và gửi alert tự động
- ✅ Hiểu multi-hypervisor support: VMware, Hyper-V, KVM, Nutanix
- ✅ Thiết kế RBAC matrix cho enterprise nhiều team
Lý Thuyết: Veeam Enterprise Manager
Enterprise Manager là gì?
Veeam Enterprise Manager (VEM) là web-based portal để quản lý tập trung nhiều Veeam Backup & Replication instances từ một giao diện duy nhất. Phù hợp cho tổ chức có nhiều datacenter hoặc nhiều team backup riêng biệt.
Tính năng chính:
- 📊 Self-service portal: end-user tự restore file không cần admin
- 📈 Centralized reporting: backup status tất cả sites
- 🔑 License management: phân bổ VUL instances
- 🔗 REST API gateway: một endpoint cho toàn bộ infrastructure
- 👥 Role delegation: RBAC áp dụng cross-site
Enterprise Manager Topology:
┌─────────────────────────────────┐
│ Enterprise Manager Portal │
│ https://vem.company.com:9443 │
│ (Central web UI + API) │
└──────────┬──────────────────────┘
│ manages
┌──────┴──────┐
│ │
▼ ▼
┌───────────┐ ┌───────────┐
│ VBR - HCM │ │ VBR - HN │
│ Site A │ │ Site B │
│ 150 VMs │ │ 30 VMs │
└───────────┘ └───────────┘
│
▼
┌───────────┐
│ VBR - DN │
│ Site C │
│ 20 VMs │
└───────────┘
Admin login to VEM → sees ALL sites
Helpdesk login → sees only assigned VMs
Lý Thuyết: RBAC (Role-Based Access Control)
Built-in Roles trong Veeam
Role │ Full │ Jobs │ Repo │ Restore │ Tape │ Self-svc ───────────────────────────┼──────┼──────┼──────┼─────────┼──────┼───────── Veeam Administrators │ ✓ │ ✓ │ ✓ │ ✓ │ ✓ │ ✓ Veeam Backup Admins │ - │ ✓ │ ✓ │ ✓ │ - │ - Veeam Restore Operators │ - │ - │ - │ ✓ │ - │ - Veeam VM Admins │ - │ - │ - │ Own VMs│ - │ ✓ Veeam Tape Operators │ - │ - │ - │ - │ ✓ │ -
Principle of Least Privilege
Chỉ cấp quyền tối thiểu cần thiết để thực hiện công việc. Helpdesk chỉ restore — không cần quyền tạo job hay xóa repo. Giảm attack surface nếu tài khoản bị compromise.
Scope Restriction
Kết hợp Role + Scope để giới hạn phạm vi. Ví dụ: Restore Operator chỉ thấy VMs trong folder "Team-Dev" — không thể restore VM production của team khác.
LAB 13A: RBAC Configuration
Steps: Cấu Hình 3 Users với Roles Khác Nhau
- 1. Vào
Menu → Users and Roles → Add... - 2. Tạo user
[email protected]:- • Role:
Veeam Backup Administrators - • Có thể tạo/sửa jobs, quản lý repos, chạy restores
- • Không thể đổi Veeam Server settings
- • Role:
- 3. Tạo user
[email protected]:- • Role:
Veeam Restore Operators - • Chỉ thấy Restore menu, không thấy Jobs/Repos
- • Role:
- 4. Tạo user
[email protected]:- • Role:
Veeam VM Administrators - • Scope: chỉ VMs trong folder
Dev-VMs
- • Role:
- 5. Test: Login với
restore-ops→ Verify chỉ thấy Restore options trong menu - 6. Test quyền từ chối: Với
restore-ops, thửDelete Backup Job→ phải nhận Access Denied
Test Result — restore-ops account: Menu visible: [Home] [Inventory] [Restore] [History] Menu hidden: [Jobs] [Backup Infrastructure] [Configuration] Action test: Restore VM (Dev-01) → SUCCESS ✓ Delete backup job → ACCESS DENIED ✓ Add backup repo → ACCESS DENIED ✓ View Job logs → SUCCESS ✓ (read-only) RBAC working correctly.
LAB 13B: Veeam REST API
Giới Thiệu Veeam REST API v1
Base URL
https://veeam-server:9419/api/v1/
Auth
OAuth2 Bearer Token (TTL: 30 min)
Format
JSON request / JSON response
Step 1: Enable REST API Server
- 1.
Menu → General Options → REST API - 2. Enable REST API Server:
✓| Port:9419 - 3. TLS Certificate: chọn certificate hoặc dùng self-signed
- 4. Click OK, khởi động lại Veeam service
Step 2: Authentication — Lấy Bearer Token
# Lấy access token (OAuth2 password grant)
curl -k -X POST https://veeam-server:9419/api/oauth2/token \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "grant_type=password&username=admin&password=P@ssw0rd123&use_short_term_refresh=true"
# Response:
{
"access_token": "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9...",
"token_type": "Bearer",
"expires_in": 1800,
"refresh_token": "eyJhbGciOiJSUzI1NiJ9..."
}
# Lưu token vào biến (Linux/macOS):
TOKEN=$(curl -sk -X POST https://veeam-server:9419/api/oauth2/token \
-d "grant_type=password&username=admin&password=P@ssw0rd123" \
| python3 -c "import sys,json; print(json.load(sys.stdin)['access_token'])")
Bảo mật: Không hard-code credentials trong script. Dùng environment variables hoặc vault (HashiCorp Vault, Azure Key Vault). Token TTL 30 phút — implement refresh logic cho scripts chạy dài.
Step 3: List All Backup Jobs
# GET /api/v1/jobs — danh sách tất cả backup jobs
curl -k -X GET https://veeam-server:9419/api/v1/jobs \
-H "Authorization: Bearer $TOKEN" \
-H "Accept: application/json" | python3 -m json.tool
# Response (rút gọn):
{
"data": [
{
"id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
"name": "DB-Critical-HCM",
"type": "Backup",
"isEnabled": true,
"isScheduleEnabled": true,
"lastRun": "2024-01-22T02:00:00Z",
"lastResult": "Success",
"nextRun": "2024-01-22T06:00:00Z"
},
{
"id": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
"name": "App-Prod-HCM",
"type": "Backup",
"isEnabled": true,
"lastResult": "Warning",
"lastResultMessage": "2 VMs skipped (snapshots)"
}
],
"pagination": { "total": 6, "count": 6 }
}
Step 4: Trigger Job via API
# POST /api/v1/jobs/{jobId}/start — khởi động job thủ công
JOB_ID="a1b2c3d4-e5f6-7890-abcd-ef1234567890"
curl -k -X POST \
"https://veeam-server:9419/api/v1/jobs/${JOB_ID}/start" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{}'
# Response:
{
"id": "session-uuid-here",
"name": "DB-Critical-HCM",
"activityId": "c3d4e5f6-...",
"sessionType": "Backup",
"state": "Starting",
"result": "None",
"startTime": "2024-01-22T14:30:00Z"
}
# Poll session status:
curl -k -X GET \
"https://veeam-server:9419/api/v1/sessions/${SESSION_ID}" \
-H "Authorization: Bearer $TOKEN"
Use case thực tế: CI/CD pipeline (Jenkins/GitLab) trigger backup job trước khi deploy production release — đảm bảo có điểm restore nếu release thất bại.
LAB 13C: PowerShell Automation
Veeam PowerShell Snap-in
Veeam cài sẵn PowerShell snap-in VeeamPSSnapIn trên Backup Server. Cung cấp 500+ cmdlets để quản lý toàn bộ Veeam infrastructure qua script.
Steps: PowerShell Monitoring Script
- 1. Mở PowerShell ISE (Run as Administrator)
- 2. Import snap-in:
Add-PSSnapin VeeamPSSnapIn - 3. Connect tới Veeam Server
- 4. Chạy từng command, ghi chép output vào lab report
# ============================================================
# Veeam Monitoring Script — Lab 13C
# ============================================================
# Import snap-in và connect
Add-PSSnapin VeeamPSSnapIn -ErrorAction SilentlyContinue
Connect-VBRServer -Server "veeam-server.vna.local" -Credential (Get-Credential)
# ----- 1. Xem tất cả backup jobs -----
Write-Host "=== BACKUP JOBS ===" -ForegroundColor Cyan
Get-VBRJob | Select-Object Name, JobType, IsScheduleEnabled, LastRun |
Format-Table -AutoSize
# Output mẫu:
# Name JobType IsScheduleEnabled LastRun
# ---- ------- ----------------- -------
# DB-Critical-HCM Backup True 22/01/2024 02:00
# App-Prod-HCM Backup True 22/01/2024 03:00
# ----- 2. Tìm jobs thất bại trong 24h qua -----
Write-Host "`n=== FAILED JOBS (last 24h) ===" -ForegroundColor Red
$failedSessions = Get-VBRBackupSession |
Where-Object {
$_.Result -eq "Failed" -and
$_.EndTime -gt (Get-Date).AddHours(-24)
}
if ($failedSessions) {
$failedSessions | Select-Object JobName, EndTime, Result, Reason |
Format-Table -AutoSize -Wrap
} else {
Write-Host "No failed jobs in last 24 hours. All clear!" -ForegroundColor Green
}
# ----- 3. Tìm VMs chưa được backup (unprotected) -----
Write-Host "`n=== UNPROTECTED VMs ===" -ForegroundColor Yellow
$allVMs = Find-VBRViEntity -VMsandTemplates | Where-Object {$_.Type -eq "VM"}
$protected = Get-VBRJob | Get-VBRJobObject | Select-Object -ExpandProperty Name
$unprotected = $allVMs | Where-Object { $_.Name -notin $protected }
$unprotected | Select-Object Name, Path | Format-Table -AutoSize
# ----- 4. Kiểm tra dung lượng repositories -----
Write-Host "`n=== REPOSITORY CAPACITY ===" -ForegroundColor Magenta
Get-VBRBackupRepository | ForEach-Object {
$usedGB = [math]::Round($_.Info.UsedSize / 1GB, 1)
$totalGB = [math]::Round($_.Info.CachedTotalSpace / 1GB, 1)
$pct = if ($totalGB -gt 0) { [math]::Round($usedGB/$totalGB*100, 1) } else { 0 }
$color = if ($pct -ge 85) { "Red" } elseif ($pct -ge 70) { "Yellow" } else { "Green" }
Write-Host ("[{0}] {1}/{2} GB ({3}%)" -f $_.Name, $usedGB, $totalGB, $pct) -ForegroundColor $color
}
# ----- 5. Gửi email alert nếu có failures -----
if ($failedSessions) {
$body = $failedSessions |
Select-Object JobName, EndTime, Reason |
ConvertTo-Html -Fragment |
Out-String
Send-MailMessage `
-To "[email protected]" `
-From "[email protected]" `
-Subject "VEEAM ALERT: $($failedSessions.Count) job(s) failed — $(Get-Date -Format 'yyyy-MM-dd')" `
-Body "Failed Backup Jobs
$body" `
-BodyAsHtml `
-SmtpServer "smtp.company.com"
Write-Host "Alert email sent." -ForegroundColor Red
}
Disconnect-VBRServer
Write-Host "`nDone." -ForegroundColor Cyan
Step 3: Tự Động Hóa Với Task Scheduler
- 1. Lưu script thành
C:\Scripts\veeam-monitor.ps1 - 2. Mở Task Scheduler → Create Basic Task
- 3. Trigger: Daily, 07:00 AM (sau backup window)
- 4. Action:
powershell.exe -NonInteractive -File "C:\Scripts\veeam-monitor.ps1" - 5. Run as: Service account với quyền Veeam Backup Admin
- 6. Test run: click "Run" → kiểm tra email nhận được
Lý Thuyết: Multi-Hypervisor & Multi-Platform
| Platform | Backup Method | Agent? | CBT Support | Ghi Chú |
|---|---|---|---|---|
| VMware vSphere | Agentless (VADP) | Không cần | ✅ Native CBT | Tốt nhất — zero-impact backup |
| Microsoft Hyper-V | Agentless (VSS) | Không cần | ✅ RCT (Resilient Change Tracking) | Tích hợp Windows natively |
| Nutanix AHV | Agentless | Không cần | ✅ Nutanix CBT API | Veeam v12+ native support |
| Linux KVM / oVirt | Agent-based | Cần agent | ⚠️ Limited | Veeam Agent for Linux |
| AWS EC2 | Agent / Snapshot | Optional | ✅ EBS snapshots | Veeam Backup for AWS |
| Physical Servers | Agent-based | Bắt buộc | ✅ CBT via driver | Veeam Agent for Windows/Linux |
Agentless vs Agent-based — Khi Nào Dùng?
Agentless (ưu tiên):
- ✅ Không cần cài software lên từng VM
- ✅ Backup không ảnh hưởng performance VM
- ✅ Quản lý tập trung từ Veeam server
- ✅ Phù hợp VMware, Hyper-V, Nutanix
Agent-based (khi buộc phải dùng):
- ⚠️ Physical servers (không có hypervisor)
- ⚠️ Cloud VMs (AWS/Azure IaaS)
- ⚠️ KVM/oVirt chưa có agentless support
- ⚠️ Cần application-aware backup chi tiết
Bài Tập Thực Hành
BT1: RBAC Matrix cho Enterprise 5 Teams
Công ty có 5 team: Storage, Network, Backup, Helpdesk, Security. Thiết kế RBAC matrix hoàn chỉnh.
Điền vào bảng:
| Team | Veeam Role | Scope | Lý do |
|---|---|---|---|
| Storage | [?] | [?] | [?] |
| Network | [?] | [?] | [?] |
| Backup Team | [?] | [?] | [?] |
| Helpdesk | [?] | [?] | [?] |
| Security | [?] | [?] | [?] |
BT2: PowerShell Weekly Backup Report Script
Viết PowerShell script tạo báo cáo tuần với các thông tin:
- • Tổng số jobs: thành công / cảnh báo / thất bại
- • Success rate (%)
- • Tổng dung lượng backup trong tuần (GB)
- • Job có thời gian chạy lâu nhất (duration)
- • VMs chưa được backup (unprotected)
- • Export kết quả ra file HTML report
Gợi ý: dùng Get-VBRBackupSession -Hours 168 (7 ngày × 24h), ConvertTo-Html để tạo HTML, Out-File để lưu.
BT3: API Automation — Slack Notification Webhook
Thiết kế giải pháp tự động gửi Slack notification khi backup job thất bại, sử dụng Veeam REST API.
Mô tả kiến trúc:
Flow thiết kế:
Veeam Event (job failed)
│
▼
Veeam REST API Webhook
│ POST /api/v1/webhooks (configure in Veeam)
▼
Webhook Receiver (Python/Node.js script on server)
│ parse JSON payload
▼
Slack Incoming Webhook URL
│ POST message
▼
#backup-alerts channel ← "🚨 Job DB-Critical-HCM FAILED at 02:45"
Viết pseudocode hoặc code thực cho webhook receiver. Gợi ý: Python Flask + requests.post(slack_webhook_url, json=payload)