Bỏ qua, đến nội dung

Tham chiếu API — Backups

Tổng quan Resources

ResourceMô tảQuyền
backupsQuản lý backup filesAdmin
backupScheduleCấu hình lịch trình tự độngAdmin
backupDestinationsCấu hình nơi lưu trữ (S3, local)Admin

Tạo backup thủ công

typescript
await agent.resource('backups').create({
  values: {
    type: 'full',               // 'full' | 'database'
    description: 'Backup trước khi cập nhật phiên bản',
  },
});

Lấy danh sách backups

typescript
const response = await agent.resource('backups').list({
  sort: ['-createdAt'],
  pageSize: 20,
});
// response.body.data = [{ id, type, status, size, description, createdAt, ... }]

Tải backup

typescript
// Download file backup (stream response)
const file = await agent.resource('backups').download({
  filterByTk: backupId,
});

Restore từ backup

typescript
await agent.resource('backups').restore({
  filterByTk: backupId,
  values: {
    confirm: true,  // Bắt buộc xác nhận
  },
});
// ⚠️ Server sẽ restart sau khi restore hoàn tất

Xoá backup

typescript
await agent.resource('backups').destroy({
  filterByTk: backupId,
});
// Xoá file backup khỏi storage (local + cloud)

Cấu hình lịch trình tự động

typescript
await agent.resource('backupSchedule').update({
  values: {
    enabled: true,
    cron: '0 2 * * *',         // 2h sáng mỗi ngày
    type: 'full',               // 'full' | 'database'
    retention: 30,              // Giữ backup 30 ngày
    maxBackups: 10,             // Tối đa 10 backups
    notifyOnFailure: true,      // Thông báo khi lỗi
  },
});

Cấu hình destination (nơi lưu trữ)

Thêm S3 destination

typescript
await agent.resource('backupDestinations').create({
  values: {
    type: 's3',
    name: 'AWS S3 Production',
    config: {
      bucket: 'my-backups',
      region: 'ap-southeast-1',
      accessKeyId: 'AKIA...',
      secretAccessKey: '...',
      prefix: 'digiforce/backups/',
    },
  },
});

Thêm Local destination

typescript
await agent.resource('backupDestinations').create({
  values: {
    type: 'local',
    name: 'Server Local',
    config: {
      directory: './storage/backups',
      maxBackups: 10,
    },
  },
});

Backup Object

TrườngKiểuMô tả
idbigintID backup
typestringfull hoặc database
statusstringpending, running, completed, failed
sizebigintKích thước file (bytes)
descriptionstringMô tả do user nhập
checksumstringSHA-256 hash để xác minh tính toàn vẹn
encryptedbooleanFile có được mã hoá không
destinationsjsonDanh sách nơi đã lưu
createdAtdatetimeThời gian tạo
completedAtdatetimeThời gian hoàn tất
errortextThông báo lỗi (nếu failed)

Database Collections

BảngMô tả
backupsMetadata backup (timestamp, size, checksum, status)
backupSchedulesLịch trình backup (cron expression, type, retention)
backupDestinationsCấu hình đích lưu trữ (type, credentials, bucket)

Giới hạn kỹ thuật

Tham sốGiá trịGhi chú
Đồng thời1 backup/restore tại một thời điểmTránh xung đột database
Mã hoáAES-256Tự động khi upload lên cloud
NéngzipGiảm 60–80% kích thước
RestoreGhi đè toàn bộ databaseCần xác nhận confirm: true
S3 uploadMultipart cho file > 5MBTự động