{
  "swagger": "2.0",
  "info": {
    "title": "Backup Restore APIs for TiDB Cloud",
    "version": "alpha"
  },
  "tags": [
    {
      "name": "BackupRestoreService"
    }
  ],
  "schemes": ["https"],
  "consumes": ["application/json"],
  "produces": ["application/json"],
  "paths": {
    "/api/v1/serverless/orgs/{org_id}/projects/{project_id}/clusters/{cluster_id}/backup_retention": {
      "get": {
        "summary": "Get the Backup Retention (hours) of a cluster.",
        "operationId": "GetBackupRetention",
        "responses": {
          "200": {
            "description": "A successful response.",
            "schema": {
              "$ref": "#/definitions/GetBackupRetentionResp"
            }
          },
          "default": {
            "description": "An unexpected error response.",
            "schema": {
              "$ref": "#/definitions/Status"
            }
          }
        },
        "parameters": [
          {
            "name": "org_id",
            "description": "Required. The organize ID of the cluster",
            "in": "path",
            "required": true,
            "type": "string"
          },
          {
            "name": "project_id",
            "description": "Required. The project ID of the cluster",
            "in": "path",
            "required": true,
            "type": "string"
          },
          {
            "name": "cluster_id",
            "description": "Required. The cluster ID.",
            "in": "path",
            "required": true,
            "type": "string"
          }
        ],
        "tags": ["BackupRestoreService"]
      }
    },
    "/api/v1/serverless/orgs/{org_id}/projects/{project_id}/clusters/{cluster_id}/backups": {
      "get": {
        "summary": "Provides a list of backups.",
        "operationId": "BackupRestoreService_ListBackups",
        "responses": {
          "200": {
            "description": "A successful response.",
            "schema": {
              "$ref": "#/definitions/ListBackupsResponse"
            }
          },
          "default": {
            "description": "An unexpected error response.",
            "schema": {
              "$ref": "#/definitions/Status"
            }
          }
        },
        "parameters": [
          {
            "name": "org_id",
            "description": "Required. The organize ID of backup",
            "in": "path",
            "required": true,
            "type": "string"
          },
          {
            "name": "project_id",
            "description": "Required. The project ID of backup",
            "in": "path",
            "required": true,
            "type": "string"
          },
          {
            "name": "cluster_id",
            "description": "Required. The cluster ID of backup.",
            "in": "path",
            "required": true,
            "type": "string"
          },
          {
            "name": "page_size",
            "description": "Optional. The maximum number of backups to return.",
            "in": "query",
            "required": false,
            "type": "integer",
            "format": "int32"
          },
          {
            "name": "page_token",
            "description": "Optional. The page token from the previous response for pagination.",
            "in": "query",
            "required": false,
            "type": "string"
          },
          {
            "name": "order_by",
            "description": "Optional. List backups order by, separated by comma, default is ascending. Example: \"backup_time desc\". Supported field: backup_time",
            "in": "query",
            "required": false,
            "type": "string"
          }
        ],
        "tags": ["BackupRestoreService"]
      }
    },
    "/api/v1/serverless/orgs/{org_id}/projects/{project_id}/clusters/{cluster_id}/backups/{backup_id}": {
      "get": {
        "summary": "Retrieves details of a specific backup.",
        "operationId": "BackupRestoreService_GetBackup",
        "responses": {
          "200": {
            "description": "A successful response.",
            "schema": {
              "$ref": "#/definitions/Backup"
            }
          },
          "default": {
            "description": "An unexpected error response.",
            "schema": {
              "$ref": "#/definitions/Status"
            }
          }
        },
        "parameters": [
          {
            "name": "org_id",
            "description": "Required. The organize ID of backup",
            "in": "path",
            "required": true,
            "type": "string"
          },
          {
            "name": "project_id",
            "description": "Required. The project ID of backup",
            "in": "path",
            "required": true,
            "type": "string"
          },
          {
            "name": "cluster_id",
            "description": "Required. The cluster ID of backup.",
            "in": "path",
            "required": true,
            "type": "string"
          },
          {
            "name": "backup_id",
            "description": "Required. The ID of the backup to be retrieved.",
            "in": "path",
            "required": true,
            "type": "string"
          }
        ],
        "tags": ["BackupRestoreService"]
      }
    },
    "/api/v1/serverless/orgs/{org_id}/projects/{project_id}/clusters/{cluster_id}/latest_restore_progress": {
      "get": {
        "summary": "get the progress of the latest restore job",
        "operationId": "BackupRestoreService_GetRestoreProgress",
        "responses": {
          "200": {
            "description": "A successful response.",
            "schema": {
              "$ref": "#/definitions/GetRestoreProgressResponse"
            }
          },
          "default": {
            "description": "An unexpected error response.",
            "schema": {
              "$ref": "#/definitions/Status"
            }
          }
        },
        "parameters": [
          {
            "name": "org_id",
            "description": "Required. The organize ID",
            "in": "path",
            "required": true,
            "type": "string"
          },
          {
            "name": "project_id",
            "description": "Required. The project ID",
            "in": "path",
            "required": true,
            "type": "string"
          },
          {
            "name": "cluster_id",
            "description": "Required. The cluster ID",
            "in": "path",
            "required": true,
            "type": "string"
          }
        ],
        "tags": ["BackupRestoreService"]
      }
    },
    "/api/v1/serverless/orgs/{org_id}/projects/{project_id}/clusters:restore": {
      "post": {
        "operationId": "BackupRestoreService_Restore",
        "responses": {
          "200": {
            "description": "A successful response.",
            "schema": {
              "$ref": "#/definitions/RestoreResponse"
            }
          },
          "default": {
            "description": "An unexpected error response.",
            "schema": {
              "$ref": "#/definitions/Status"
            }
          }
        },
        "parameters": [
          {
            "name": "org_id",
            "description": "Required. The organize ID of backup",
            "in": "path",
            "required": true,
            "type": "string"
          },
          {
            "name": "project_id",
            "description": "Required. The project ID of backup",
            "in": "path",
            "required": true,
            "type": "string"
          },
          {
            "name": "body",
            "in": "body",
            "required": true,
            "schema": {
              "$ref": "#/definitions/BackupRestoreService.RestoreBody"
            }
          }
        ],
        "tags": ["BackupRestoreService"]
      }
    },
    "/api/v1/serverless/orgs/{org_id}/recycledInstances": {
      "get": {
        "summary": "Lists recycled instances in recycle bin.",
        "operationId": "BackupRestoreService_ListRecycledInstances",
        "responses": {
          "200": {
            "description": "A successful response.",
            "schema": {
              "$ref": "#/definitions/ListRecycledInstancesResponse"
            }
          },
          "default": {
            "description": "An unexpected error response.",
            "schema": {
              "$ref": "#/definitions/Status"
            }
          }
        },
        "parameters": [
          {
            "name": "org_id",
            "description": "Required. The organize ID",
            "in": "path",
            "required": true,
            "type": "string"
          },
          {
            "name": "page_size",
            "description": "Optional. The maximum number of recycled instances to return.",
            "in": "query",
            "required": false,
            "type": "integer",
            "format": "int32"
          },
          {
            "name": "page_token",
            "description": "Optional. The page token from the previous response for pagination.",
            "in": "query",
            "required": false,
            "type": "string"
          },
          {
            "name": "order_by",
            "description": "Optional. List recycled instances order by, separated by comma, default is descending. Example: \"delete_time desc\". Supported field: delete_time",
            "in": "query",
            "required": false,
            "type": "string"
          },
          {
            "name": "region_ids",
            "description": "Optional. Filter by region IDs.",
            "in": "query",
            "required": false,
            "type": "array",
            "items": {
              "type": "string"
            },
            "collectionFormat": "multi"
          },
          {
            "name": "project_ids",
            "description": "Optional. Filter by project IDs.",
            "in": "query",
            "required": false,
            "type": "array",
            "items": {
              "type": "string"
            },
            "collectionFormat": "multi"
          },
          {
            "name": "start_time",
            "description": "Optional. Filter recycled instances whose delete time is greater than or equal to this time.",
            "in": "query",
            "required": false,
            "type": "string",
            "format": "date-time"
          },
          {
            "name": "end_time",
            "description": "Optional. Filter recycled instances whose delete time is less than or equal to this time.",
            "in": "query",
            "required": false,
            "type": "string",
            "format": "date-time"
          }
        ],
        "tags": ["BackupRestoreService"]
      }
    },
    "/api/v1/serverless/orgs/{org_id}/recycledInstances/{cluster_id}": {
      "get": {
        "summary": "Retrieves recycled instance details.",
        "operationId": "BackupRestoreService_GetRecycledInstance",
        "responses": {
          "200": {
            "description": "A successful response.",
            "schema": {
              "$ref": "#/definitions/RecycledInstance"
            }
          },
          "default": {
            "description": "An unexpected error response.",
            "schema": {
              "$ref": "#/definitions/Status"
            }
          }
        },
        "parameters": [
          {
            "name": "org_id",
            "description": "Required. The organize ID",
            "in": "path",
            "required": true,
            "type": "string"
          },
          {
            "name": "cluster_id",
            "description": "Required. The cluster ID.",
            "in": "path",
            "required": true,
            "type": "string"
          }
        ],
        "tags": ["BackupRestoreService"]
      }
    },
    "/api/v1/serverless/orgs/{org_id}/recycledInstances/{cluster_id}/backups": {
      "get": {
        "summary": "Lists backups of a recycled instance.",
        "operationId": "BackupRestoreService_ListRecycledInstanceBackups",
        "responses": {
          "200": {
            "description": "A successful response.",
            "schema": {
              "$ref": "#/definitions/ListRecycledInstanceBackupsResponse"
            }
          },
          "default": {
            "description": "An unexpected error response.",
            "schema": {
              "$ref": "#/definitions/Status"
            }
          }
        },
        "parameters": [
          {
            "name": "org_id",
            "description": "Required. The organize ID of backup",
            "in": "path",
            "required": true,
            "type": "string"
          },
          {
            "name": "cluster_id",
            "description": "Required. The source cluster ID.",
            "in": "path",
            "required": true,
            "type": "string"
          },
          {
            "name": "page_size",
            "description": "Optional. The maximum number of backups to return.",
            "in": "query",
            "required": false,
            "type": "integer",
            "format": "int32"
          },
          {
            "name": "page_token",
            "description": "Optional. The page token from the previous response for pagination.",
            "in": "query",
            "required": false,
            "type": "string"
          },
          {
            "name": "order_by",
            "description": "Optional. List backups order by, separated by comma, default is ascending. Example: \"backup_time desc\". Supported field: backup_time",
            "in": "query",
            "required": false,
            "type": "string"
          }
        ],
        "tags": ["BackupRestoreService"]
      }
    },
    "/api/v1/serverless/orgs/{org_id}/recycledInstances/{cluster_id}/backups/{backup_id}": {
      "delete": {
        "summary": "Permanently deletes a recycled backup.",
        "operationId": "BackupRestoreService_DeleteRecycledInstanceBackup",
        "responses": {
          "200": {
            "description": "A successful response.",
            "schema": {
              "$ref": "#/definitions/DeleteRecycledInstanceBackupResponse"
            }
          },
          "default": {
            "description": "An unexpected error response.",
            "schema": {
              "$ref": "#/definitions/Status"
            }
          }
        },
        "parameters": [
          {
            "name": "org_id",
            "description": "Required. The organize ID of backup",
            "in": "path",
            "required": true,
            "type": "string"
          },
          {
            "name": "cluster_id",
            "description": "Required. The source cluster ID.",
            "in": "path",
            "required": true,
            "type": "string"
          },
          {
            "name": "backup_id",
            "description": "Required. The ID of the backup to be deleted.",
            "in": "path",
            "required": true,
            "type": "string"
          }
        ],
        "tags": ["BackupRestoreService"]
      }
    }
  },
  "definitions": {
    "Any": {
      "type": "object",
      "properties": {
        "@type": {
          "type": "string"
        }
      },
      "additionalProperties": {}
    },
    "Backup": {
      "type": "object",
      "properties": {
        "name": {
          "type": "string",
          "description": "Output_only. The unique name of the backup.",
          "readOnly": true
        },
        "backup_id": {
          "type": "string",
          "description": "Output_only. The unique ID of the backup.",
          "readOnly": true
        },
        "cluster_id": {
          "type": "string",
          "description": "Required. The cluster ID that backup belong to."
        },
        "backup_time": {
          "type": "string",
          "format": "date-time",
          "title": "Output_only. Timestamp of the backup time",
          "readOnly": true
        },
        "expire_time": {
          "type": "string",
          "format": "date-time",
          "description": "Output_only. Timestamp when the backup will expire.",
          "readOnly": true
        },
        "state": {
          "$ref": "#/definitions/BackupStateType.Enum",
          "title": "Output_only. The backup state"
        },
        "type": {
          "type": "string",
          "description": "Output_only. The backup type.",
          "readOnly": true
        },
        "create_time": {
          "type": "string",
          "format": "date-time",
          "description": "Output_only. Timestamp when the backup was created.",
          "readOnly": true
        },
        "base_resp": {
          "$ref": "#/definitions/BaseResp"
        }
      },
      "description": "Message for backup resource.",
      "required": ["cluster_id"]
    },
    "BackupRestoreService.RestoreBody": {
      "type": "object",
      "properties": {
        "backup_id": {
          "type": "string"
        },
        "point_in_time": {
          "$ref": "#/definitions/PointInTime"
        },
        "type": {
          "$ref": "#/definitions/RestoreType.Enum",
          "title": "Required. The type of restore"
        },
        "cluster": {
          "$ref": "#/definitions/console.Cluster",
          "title": "Optional. used when restore to new cluster"
        }
      },
      "required": ["type"]
    },
    "BackupStateType.Enum": {
      "type": "string",
      "enum": ["SUCCEEDED", "FAILED"],
      "description": " - SUCCEEDED: The state of the backup is succeed.\n - FAILED: The state of the backup is failed."
    },
    "BaseResp": {
      "type": "object",
      "properties": {
        "tags": {
          "type": "object",
          "additionalProperties": {
            "type": "string"
          },
          "title": "such as: request_id, trace_id"
        },
        "err_code": {
          "type": "string",
          "format": "int64"
        },
        "err_msg": {
          "type": "string"
        }
      }
    },
    "Cluster.AutoScaling": {
      "type": "object",
      "properties": {
        "min_rcu": {
          "type": "integer",
          "format": "int64"
        },
        "max_rcu": {
          "type": "integer",
          "format": "int64"
        }
      }
    },
    "Cluster.SpendingLimit": {
      "type": "object",
      "properties": {
        "monthly": {
          "type": "integer",
          "format": "int32"
        }
      },
      "required": ["monthly"]
    },
    "DeleteRecycledInstanceBackupResponse": {
      "type": "object",
      "properties": {
        "base_resp": {
          "$ref": "#/definitions/BaseResp"
        }
      }
    },
    "GetBackupRetentionResp": {
      "type": "object",
      "properties": {
        "retention_hours": {
          "type": "integer",
          "format": "int32"
        },
        "base_resp": {
          "$ref": "#/definitions/BaseResp"
        }
      }
    },
    "GetRestoreProgressResponse": {
      "type": "object",
      "properties": {
        "percent": {
          "type": "number",
          "format": "float",
          "title": "Output only. The percent of progress",
          "readOnly": true
        },
        "size_bytes": {
          "type": "number",
          "format": "double",
          "title": "Output only. The restored size in bytes\nnot use int64 because the grpc-gateway will convert int64 to string in swagger: https://github.com/grpc-ecosystem/grpc-gateway/issues/219\nuse double because float may occur precision problem in the range of size_bytes: https://stackoverflow.com/questions/3793838/which-is-the-first-integer-that-an-ieee-754-float-is-incapable-of-representing-e",
          "readOnly": true
        },
        "state": {
          "$ref": "#/definitions/RestoreState.Enum",
          "title": "Output only. The state of restore",
          "readOnly": true
        },
        "base_resp": {
          "$ref": "#/definitions/BaseResp"
        }
      }
    },
    "ListBackupsResponse": {
      "type": "object",
      "properties": {
        "backups": {
          "type": "array",
          "items": {
            "type": "object",
            "$ref": "#/definitions/Backup"
          },
          "description": "A list of backups."
        },
        "next_page_token": {
          "type": "string",
          "description": "Token provided to retrieve the next page of results."
        },
        "total_size": {
          "type": "integer",
          "format": "int64",
          "description": "Total number of backups."
        },
        "base_resp": {
          "$ref": "#/definitions/BaseResp"
        }
      }
    },
    "ListRecycledInstanceBackupsResponse": {
      "type": "object",
      "properties": {
        "backups": {
          "type": "array",
          "items": {
            "type": "object",
            "$ref": "#/definitions/Backup"
          },
          "description": "A list of backups."
        },
        "next_page_token": {
          "type": "string",
          "description": "Token provided to retrieve the next page of results."
        },
        "total_size": {
          "type": "integer",
          "format": "int64",
          "description": "Total number of backups."
        },
        "base_resp": {
          "$ref": "#/definitions/BaseResp"
        }
      }
    },
    "ListRecycledInstancesResponse": {
      "type": "object",
      "properties": {
        "items": {
          "type": "array",
          "items": {
            "type": "object",
            "$ref": "#/definitions/RecycledInstance"
          },
          "description": "A list of recycled instances."
        },
        "next_page_token": {
          "type": "string",
          "description": "Token provided to retrieve the next page of results."
        },
        "total_size": {
          "type": "integer",
          "format": "int64",
          "description": "Total number of recycled instances."
        },
        "base_resp": {
          "$ref": "#/definitions/BaseResp"
        }
      }
    },
    "PointInTime": {
      "type": "object",
      "properties": {
        "cluster_id": {
          "type": "string"
        },
        "backup_time": {
          "type": "string",
          "format": "date-time"
        }
      },
      "required": ["cluster_id"]
    },
    "RecycledInstance": {
      "type": "object",
      "properties": {
        "cluster_id": {
          "type": "string",
          "description": "Output_only. The source cluster id.",
          "readOnly": true
        },
        "display_name": {
          "type": "string",
          "description": "Output_only. The source cluster display name.",
          "readOnly": true
        },
        "project_id": {
          "type": "string",
          "description": "Output_only. The source cluster project id.",
          "readOnly": true
        },
        "region": {
          "type": "string",
          "description": "Output_only. The source cluster region.",
          "readOnly": true
        },
        "delete_time": {
          "type": "string",
          "format": "date-time",
          "description": "Output_only. Timestamp when the source cluster was deleted.",
          "readOnly": true
        },
        "enhanced_encryption_enabled": {
          "type": "boolean",
          "description": "Output_only. Enhanced encryption enabled of source cluster backup schedule snapshot.",
          "readOnly": true
        },
        "zone_redundant_enabled": {
          "type": "boolean",
          "description": "Output_only. Zone redundant enabled of source cluster backup schedule snapshot.",
          "readOnly": true
        },
        "provider": {
          "type": "string",
          "description": "Output_only. Source cluster provider.",
          "readOnly": true
        },
        "base_resp": {
          "$ref": "#/definitions/BaseResp"
        }
      },
      "description": "Message for recycled instance resource."
    },
    "RestoreClusterHighAvailabilityType.Enum": {
      "type": "string",
      "enum": ["ZONAL", "REGIONAL"],
      "title": "- ZONAL: High availability within a single zone\n - REGIONAL: High availability across multiple zones within a region"
    },
    "RestoreResponse": {
      "type": "object",
      "properties": {
        "cluster_id": {
          "type": "string"
        },
        "base_resp": {
          "$ref": "#/definitions/BaseResp"
        }
      },
      "required": ["cluster_id"]
    },
    "RestoreState.Enum": {
      "type": "string",
      "enum": ["SUCCEEDED", "FAILED", "RUNNING", "PENDING"],
      "description": " - SUCCEEDED: The state of the restore job is succeeded.\n - FAILED: The state of the restore job is failed.\n - RUNNING: The state of the restore job is running.\n - PENDING: The state of the restore job is pending."
    },
    "RestoreType.Enum": {
      "type": "string",
      "enum": ["INPLACE", "NEW"],
      "title": "- INPLACE: restore in place\n - NEW: restore to new cluster"
    },
    "Status": {
      "type": "object",
      "properties": {
        "code": {
          "type": "integer",
          "format": "int32"
        },
        "message": {
          "type": "string"
        },
        "details": {
          "type": "array",
          "items": {
            "type": "object",
            "$ref": "#/definitions/Any"
          }
        }
      }
    },
    "console.Cluster": {
      "type": "object",
      "properties": {
        "display_name": {
          "type": "string",
          "title": "Required. The display name of the cluster"
        },
        "spending_limit": {
          "$ref": "#/definitions/Cluster.SpendingLimit",
          "title": "Optional. The spending limit of the cluster"
        },
        "auto_scaling": {
          "$ref": "#/definitions/Cluster.AutoScaling",
          "description": "Optional. The auto scaling config for the cluster, only used in alicloud provider."
        },
        "high_availability_type": {
          "$ref": "#/definitions/RestoreClusterHighAvailabilityType.Enum",
          "description": "Optional. The high availability type of the cluster."
        }
      },
      "required": ["display_name"]
    }
  },
  "securityDefinitions": {
    "bearer": {
      "type": "apiKey",
      "description": "Authentication token, prefixed by Bearer: 'Bearer token'",
      "name": "Authorization",
      "in": "header"
    }
  }
}
