VPS.org API

REST API Documentation

快照 API

管理服务器快照,以便快速恢复到特定时间点。快照会记录服务器的完整状态。

终点 4 endpoints
基本路径 /api/v1/snapshots
得到 /api/v1/snapshots/

列出所有快照

获取服务器上所有快照的列表。

查询参数

Parameter 类型 必需的 Description
server_id integer No 按服务器 ID 筛选快照

示例请求

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

url = "https://admin.vps.org/api/v1/snapshots/"
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/snapshots/?server_id=12345', {
  method: 'GET',
  headers: {
    'Authorization': 'Bearer YOUR_API_TOKEN',
    'Content-Type': 'application/json'
  }
});

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

示例回复

{
  "count": 2,
  "results": [
    {
      "id": 801,
      "server": {
        "id": 12345,
        "name": "web-server-01"
      },
      "name": "pre-migration-snapshot",
      "status": "completed",
      "size_mb": 5120,
      "created_at": "2025-01-15T18:30:00Z",
      "description": "Before major migration"
    },
    {
      "id": 798,
      "server": {
        "id": 12345,
        "name": "web-server-01"
      },
      "name": "weekly-snapshot-2025-01-08",
      "status": "completed",
      "size_mb": 4856,
      "created_at": "2025-01-08T12:00:00Z",
      "description": "Weekly snapshot"
    }
  ]
}

响应状态码

200 已成功检索快照列表
401 未授权 - 身份验证令牌无效或缺失
POST /api/v1/snapshots/

创建快照

Create a snapshot of a server's current state. Snapshots are point-in-time copies of the entire server.

请求体参数

Parameter 类型 必需的 Description
server_id integer 是的 要拍摄快照的服务器 ID
name string 是的 快照名称(字母数字、连字符、下划线)
description string No 快照的可选描述

示例请求

cURL
Python
JavaScript
curl -X POST "https://admin.vps.org/api/v1/snapshots/" \
  -H "Authorization: Bearer YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "server_id": 12345,
    "name": "before-update-snapshot",
    "description": "Snapshot before system update"
  }'
import requests

url = "https://admin.vps.org/api/v1/snapshots/"
headers = {
    "Authorization": "Bearer YOUR_API_TOKEN",
    "Content-Type": "application/json"
}
data = {
    "server_id": 12345,
    "name": "before-update-snapshot",
    "description": "Snapshot before system update"
}

response = requests.post(url, headers=headers, json=data)
print(response.json())
const response = await fetch('https://admin.vps.org/api/v1/snapshots/', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer YOUR_API_TOKEN',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    server_id: 12345,
    name: 'before-update-snapshot',
    description: 'Snapshot before system update'
  })
});

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

示例回复

{
  "id": 802,
  "server": {
    "id": 12345,
    "name": "web-server-01"
  },
  "name": "before-update-snapshot",
  "status": "in_progress",
  "size_mb": null,
  "created_at": "2025-01-16T16:15:00Z",
  "description": "Snapshot before system update",
  "message": "Snapshot is being created. This may take 3-10 minutes depending on server size."
}

响应状态码

201 快照创建已成功启动
400 Bad Request - Invalid parameters or snapshot limit reached
401 未授权 - 身份验证令牌无效或缺失
404 Not Found - Server does not exist
Note: You can have a maximum of 5 snapshots per server. Creating a snapshot while the server is running may result in filesystem inconsistencies. For best results, stop the server before creating a snapshot.
POST /api/v1/snapshots/{snapshot_id}/restore/

从快照恢复

Restore a server to the state captured in a snapshot. This will overwrite all current data on the server.

路径参数

Parameter 类型 必需的 Description
snapshot_id integer 是的 唯一快照 ID

示例请求

cURL
Python
JavaScript
curl -X POST "https://admin.vps.org/api/v1/snapshots/801/restore/" \
  -H "Authorization: Bearer YOUR_API_TOKEN" \
  -H "Content-Type: application/json"
import requests

snapshot_id = 801
url = f"https://admin.vps.org/api/v1/snapshots/{snapshot_id}/restore/"
headers = {
    "Authorization": "Bearer YOUR_API_TOKEN",
    "Content-Type": "application/json"
}

response = requests.post(url, headers=headers)
print(response.json())
const snapshotId = 801;
const response = await fetch(`https://admin.vps.org/api/v1/snapshots/${snapshotId}/restore/`, {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer YOUR_API_TOKEN',
    'Content-Type': 'application/json'
  }
});

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

示例回复

{
  "status": "success",
  "message": "Server is being restored from snapshot. This may take 5-15 minutes.",
  "snapshot": {
    "id": 801,
    "name": "pre-migration-snapshot",
    "created_at": "2025-01-15T18:30:00Z"
  },
  "server": {
    "id": 12345,
    "name": "web-server-01",
    "status": "restoring"
  }
}

响应状态码

200 恢复操作已成功启动
400 Bad Request - Server is not in a valid state for restoration
401 未授权 - 身份验证令牌无效或缺失
404 未找到 - 快照不存在
警告: Restoring from a snapshot will overwrite all current data on the server. This action cannot be undone. The server will be automatically stopped before restoration begins.
删除 /api/v1/snapshots/{snapshot_id}/

删除快照

永久删除快照。此操作无法撤销。

路径参数

Parameter 类型 必需的 Description
snapshot_id integer 是的 唯一快照 ID

示例请求

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

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

response = requests.delete(url, headers=headers)
print(response.status_code)

响应状态码

204 快照已成功删除
401 未授权 - 身份验证令牌无效或缺失
404 未找到 - 快照不存在

Snapshots vs Backups

Understanding when to use snapshots versus backups:

快照 API

  • 目的: Quick point-in-time recovery
  • 速度: Faster to create and restore (3-15 min)
  • 使用案例: Before risky operations (updates, config changes)
  • 贮存: Stored on same infrastructure
  • Limit: 5 snapshots per server
  • 最适合: Short-term rollback capability

备份 API

  • 目的: Long-term data protection
  • 速度: Slower to create and restore (varies)
  • 使用案例: Regular automated data protection
  • 贮存: Separate backup storage
  • Limit: 10 manual + automatic backups
  • 最适合: Disaster recovery and compliance

Best Practices