VPS.org API

Tài liệu API REST

API sao lưu

Quản lý sao lưu máy chủ bằng lập trình. Liệt kê, tạo, khôi phục và xóa các bản sao lưu cho máy chủ của bạn.

Điểm cuối 3 endpoints
Đường cơ sở /api/v1/backups
LẤY /api/v1/backups/

Liệt kê tất cả các bản sao lưu

Truy xuất danh sách tất cả các bản sao lưu trên các máy chủ của bạn.

Tham số truy vấn

Tham số Kiểu Yêu cầu Sự miêu tả
server_id integer KHÔNG Lọc các bản sao lưu theo ID máy chủ
backup_type string KHÔNG Lọc theo loại: manual , automatic

Ví dụ về yêu cầu

cURL
Python
JavaScript
curl -X GET "https://admin.vps.org/api/v1/backups/?server_id=12345" \
  -H "Authorization: Bearer YOUR_API_TOKEN" \
  -H "Content-Type: application/json"
import requests

url = "https://admin.vps.org/api/v1/backups/"
headers = {
    "Authorization": "Bearer YOUR_API_TOKEN",
    "Content-Type": "application/json"
}
params = {"server_id": 12345}

response = requests.get(url, headers=headers, params=params)
print(response.json())
const response = await fetch('https://admin.vps.org/api/v1/backups/?server_id=12345', {
  method: 'GET',
  headers: {
    'Authorization': 'Bearer YOUR_API_TOKEN',
    'Content-Type': 'application/json'
  }
});

const backups = await response.json();
console.log(backups);

Ví dụ về câu trả lời

{
  "count": 3,
  "results": [
    {
      "id": 501,
      "server": {
        "id": 12345,
        "name": "web-server-01"
      },
      "backup_type": "automatic",
      "status": "completed",
      "size_mb": 4523,
      "created_at": "2025-01-16T03:00:00Z",
      "expires_at": "2025-02-16T03:00:00Z",
      "description": "Automatic daily backup"
    },
    {
      "id": 499,
      "server": {
        "id": 12345,
        "name": "web-server-01"
      },
      "backup_type": "manual",
      "status": "completed",
      "size_mb": 4456,
      "created_at": "2025-01-14T10:30:00Z",
      "expires_at": null,
      "description": "Pre-update backup"
    },
    {
      "id": 495,
      "server": {
        "id": 12345,
        "name": "web-server-01"
      },
      "backup_type": "automatic",
      "status": "completed",
      "size_mb": 4389,
      "created_at": "2025-01-15T03:00:00Z",
      "expires_at": "2025-02-15T03:00:00Z",
      "description": "Automatic daily backup"
    }
  ]
}

Mã trạng thái phản hồi

200 Đã khôi phục danh sách sao lưu thành công
401 Không được phép - Mã xác thực không hợp lệ hoặc bị thiếu.
BƯU KIỆN /api/v1/backups/

Tạo bản sao lưu thủ công

Tạo bản sao lưu thủ công cho máy chủ. Các bản sao lưu thủ công không tự động hết hạn.

Các tham số thân yêu cầu

Tham số Kiểu Yêu cầu Sự miêu tả
server_id integer Đúng ID của máy chủ cần sao lưu
description string KHÔNG Mô tả tùy chọn cho bản sao lưu

Ví dụ về yêu cầu

cURL
Python
JavaScript
PHP
curl -X POST "https://admin.vps.org/api/v1/backups/" \
  -H "Authorization: Bearer YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "server_id": 12345,
    "description": "Pre-deployment backup"
  }'
import requests

url = "https://admin.vps.org/api/v1/backups/"
headers = {
    "Authorization": "Bearer YOUR_API_TOKEN",
    "Content-Type": "application/json"
}
data = {
    "server_id": 12345,
    "description": "Pre-deployment backup"
}

response = requests.post(url, headers=headers, json=data)
print(response.json())
const response = await fetch('https://admin.vps.org/api/v1/backups/', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer YOUR_API_TOKEN',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    server_id: 12345,
    description: 'Pre-deployment backup'
  })
});

const backup = await response.json();
console.log(backup);
$data = [
    'server_id' => 12345,
    'description' => 'Pre-deployment backup'
];

$ch = curl_init('https://admin.vps.org/api/v1/backups/');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    'Authorization: Bearer YOUR_API_TOKEN',
    'Content-Type: application/json'
]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$response = curl_exec($ch);
$backup = json_decode($response, true);
curl_close($ch);

Ví dụ về câu trả lời

{
  "id": 502,
  "server": {
    "id": 12345,
    "name": "web-server-01"
  },
  "backup_type": "manual",
  "status": "in_progress",
  "size_mb": null,
  "created_at": "2025-01-16T15:45:00Z",
  "expires_at": null,
  "description": "Pre-deployment backup",
  "message": "Backup is being created. This may take several minutes depending on server size."
}

Mã trạng thái phản hồi

201 Quá trình tạo bản sao lưu đã bắt đầu thành công.
400 Yêu cầu không hợp lệ - Tham số không hợp lệ hoặc yêu cầu không đúng định dạng
401 Không được phép - Mã xác thực không hợp lệ hoặc bị thiếu.
404 Không tìm thấy - Máy chủ không tồn tại
Ghi chú: Bạn có thể thực hiện tối đa 10 bản sao lưu thủ công cho mỗi máy chủ. Các bản sao lưu tự động được lưu giữ dựa trên chính sách lưu giữ bản sao lưu của gói dịch vụ bạn chọn (thường là 7-30 ngày).
XÓA BỎ /api/v1/backups/{backup_id}/

Xóa bản sao lưu

Xóa vĩnh viễn bản sao lưu. Thao tác này không thể hoàn tác.

Tham số đường dẫn

Tham số Kiểu Yêu cầu Sự miêu tả
backup_id integer Đúng ID sao lưu duy nhất

Ví dụ về yêu cầu

cURL
Python
JavaScript
curl -X DELETE "https://admin.vps.org/api/v1/backups/501/" \
  -H "Authorization: Bearer YOUR_API_TOKEN" \
  -H "Content-Type: application/json"
import requests

backup_id = 501
url = f"https://admin.vps.org/api/v1/backups/{backup_id}/"
headers = {
    "Authorization": "Bearer YOUR_API_TOKEN",
    "Content-Type": "application/json"
}

response = requests.delete(url, headers=headers)
print(response.status_code)
const backupId = 501;
const response = await fetch(`https://admin.vps.org/api/v1/backups/${backupId}/`, {
  method: 'DELETE',
  headers: {
    'Authorization': 'Bearer YOUR_API_TOKEN',
    'Content-Type': 'application/json'
  }
});

console.log(response.status);

Mã trạng thái phản hồi

204 Bản sao lưu đã được xóa thành công
401 Không được phép - Mã xác thực không hợp lệ hoặc bị thiếu.
404 Không tìm thấy - Bản sao lưu không tồn tại
Cảnh báo: Việc xóa bản sao lưu là vĩnh viễn và không thể hoàn tác. Hãy chắc chắn rằng bạn không còn cần bản sao lưu này trước khi xóa nó.

Khôi phục từ bản sao lưu

Để khôi phục máy chủ từ bản sao lưu, hãy sử dụng điểm cuối khôi phục API Máy chủ :

POST /api/v1/servers/{server_id}/restore/
{
  "backup_id": 501
}

Để biết thông tin chi tiết về việc khôi phục máy chủ, vui lòng xem phần [liên kết đến tài liệu hướng dẫn]. Tài liệu API máy chủ.

Thực tiễn tốt nhất về sao lưu