快照
更新时间:2024-07-02
创建快照
支持创建系统盘快照和CDS磁盘快照,参考如下代码:
import com.baidubce.BceClientConfiguration;
import com.baidubce.Protocol;
import com.baidubce.auth.DefaultBceCredentials;
import com.baidubce.services.bcc.model.snapshot.CreateSnapshotRequest;
public class CreateSnapshot {
public static void main(String[] args) {
// 设置您的ak、sk和要访问的endpoint
String endpoint = "http://bcc.bj.baidubce.com";
String ak = "ak";
String sk = "sk";
// 设置默认配置
BceClientConfiguration bccClientConfiguration = new BccClientConfiguration()
.withProtocol(Protocol.HTTP)
.withCredentials(new DefaultBceCredentials(ak, sk))
.withEndpoint(endpoint);
// 创建bcc client
BccClient client = new BccClient(bccClientConfiguration);
CreateSnapshotRequest createSnapshotRequest = new CreateSnapshotRequest();
// 指定磁盘id
createSnapshotRequest.setVolumeId("v-***");
// 指定快照名称
createSnapshotRequest.setSnapshotName("snapshotName");
// 设置快照描述信息
createSnapshotRequest.setDesc("desc");
// 打印返回信息
System.out.println(client.createSnapshot(createSnapshotRequest));
}
}
查询快照列表
如下代码可以查询快照列表:
import com.baidubce.BceClientConfiguration;
import com.baidubce.Protocol;
import com.baidubce.auth.DefaultBceCredentials;
import com.baidubce.services.bcc.model.snapshot.ListSnapshotsRequest;
public class ListSnapshot {
public static void main(String[] args) {
// 设置您的ak、sk和要访问的endpoint
String endpoint = "http://bcc.bj.baidubce.com";
String ak = "ak";
String sk = "sk";
// 设置默认配置
BceClientConfiguration bccClientConfiguration = new BccClientConfiguration()
.withProtocol(Protocol.HTTP)
.withCredentials(new DefaultBceCredentials(ak, sk))
.withEndpoint(endpoint);
// 创建bcc client
BccClient client = new BccClient(bccClientConfiguration);
ListSnapshotsRequest listSnapshotsRequest = new ListSnapshotsRequest();
// 设置分页标志
listSnapshotsRequest.setMarker("marker");
// 设置分页返回数据大小
listSnapshotsRequest.setMaxKeys(100);
// 过滤从指定的磁盘查询快照
listSnapshotsRequest.setVolumeId("v-***");
System.out.println(client.listSnapshots(listSnapshotsRequest));
}
}
查询快照详情
如下代码可以查询快照详情:
import com.baidubce.BceClientConfiguration;
import com.baidubce.Protocol;
import com.baidubce.auth.DefaultBceCredentials;
public class GetSnapshot {
public static void main(String[] args) {
// 设置您的ak、sk和要访问的endpoint
String endpoint = "http://bcc.bj.baidubce.com";
String ak = "ak";
String sk = "sk";
// 设置默认配置
BceClientConfiguration bccClientConfiguration = new BccClientConfiguration()
.withProtocol(Protocol.HTTP)
.withCredentials(new DefaultBceCredentials(ak, sk))
.withEndpoint(endpoint);
// 创建bcc client
BccClient client = new BccClient(bccClientConfiguration);
// 快照id
String snapshotId = "s-***";
System.out.println(client.getSnapshot(snapshotId));
}
}
删除快照
如下代码可以删除一个快照:
import com.baidubce.BceClientConfiguration;
import com.baidubce.Protocol;
import com.baidubce.auth.DefaultBceCredentials;
public class DeleteSnap {
public static void main(String[] args) {
// 设置您的ak、sk和要访问的endpoint
String endpoint = "http://bcc.bj.baidubce.com";
String ak = "ak";
String sk = "sk";
// 设置默认配置
BceClientConfiguration bccClientConfiguration = new BccClientConfiguration()
.withProtocol(Protocol.HTTP)
.withCredentials(new DefaultBceCredentials(ak, sk))
.withEndpoint(endpoint);
// 创建bcc client
BccClient client = new BccClient(bccClientConfiguration);
// 快照id
String snapshotId = "s-***";
client.deleteSnapshot(snapshotId);
}
}
查询快照链列表
如下代码可以用于查询用户的快照链列表信息:
import com.baidubce.BceClientConfiguration;
import com.baidubce.Protocol;
import com.baidubce.auth.DefaultBceCredentials;
import com.baidubce.services.bcc.model.snapshot.ListSnapchainRequest;
import com.baidubce.services.bcc.model.snapshot.ListSnapchainResponse;
public class ListSnapchain {
public static void main(String[] args) {
// 设置您的ak、sk和要访问的endpoint
String endpoint = "http://bcc.bj.baidubce.com";
String ak = "ak";
String sk = "sk";
// 设置默认配置
BceClientConfiguration bccClientConfiguration = new BccClientConfiguration()
.withProtocol(Protocol.HTTP)
.withCredentials(new DefaultBceCredentials(ak, sk))
.withEndpoint(endpoint);
// 创建bcc client
BccClient client = new BccClient(bccClientConfiguration);
ListSnapchainRequest request = new ListSnapchainRequest();
// 排序属性,可选: chainId(快照链id,默认值),chainSize(快照链大小),volumeSize(磁盘大小)
request.setOrderBy("chainId");
// 排序方式,可选:asc(正序,默认值), desc(倒序)
request.setOrder("asc");
// 页数,可选:默认值为1
request.setPageNo(1);
// 每页容量,可选:默认值为1000
request.setPageSize(100);
// 磁盘id,可选:该字段非空则只返回这个磁盘的快照链信息
request.setVolumeId("v-***");
ListSnapchainResponse response = client.listSnapchain(request);
System.out.println(response);
}
}