Snapshot
Updated at:2025-10-20
Create a snapshot
Support creating snapshots of system disks and CDS data disks. Refer to the following code:
Java
1import com.baidubce.BceClientConfiguration;
2import com.baidubce.Protocol;
3import com.baidubce.auth.DefaultBceCredentials;
4import com.baidubce.services.bcc.model.snapshot.CreateSnapshotRequest;
5public class CreateSnapshot {
6 public static void main(String[] args) {
7 // Set your AK, SK and the endpoint to be accessed
8 String endpoint = "http://bcc.bj.baidubce.com";
9 String ak = "ak";
10 String sk = "sk";
11 // Set default configuration
12 BceClientConfiguration bccClientConfiguration = new BccClientConfiguration()
13 .withProtocol(Protocol.HTTP)
14 .withCredentials(new DefaultBceCredentials(ak, sk))
15 .withEndpoint(endpoint);
16 // Create a BCC client
17 BccClient client = new BccClient(bccClientConfiguration);
18 CreateSnapshotRequest createSnapshotRequest = new CreateSnapshotRequest();
19 // Specify disk ID
20 createSnapshotRequest.setVolumeId("v-***");
21 // Specify snapshot name
22 createSnapshotRequest.setSnapshotName("snapshotName");
23 // Set snapshot description information
24 createSnapshotRequest.setDesc("desc");
25 // Print returned information
26 System.out.println(client.createSnapshot(createSnapshotRequest));
27 }
28}
Query the snapshot list
You can query the snapshot list with the following code:
Java
1import com.baidubce.BceClientConfiguration;
2import com.baidubce.Protocol;
3import com.baidubce.auth.DefaultBceCredentials;
4import com.baidubce.services.bcc.model.snapshot.ListSnapshotsRequest;
5public class ListSnapshot {
6 public static void main(String[] args) {
7 // Set your AK, SK and the endpoint to be accessed
8 String endpoint = "http://bcc.bj.baidubce.com";
9 String ak = "ak";
10 String sk = "sk";
11 // Set default configuration
12 BceClientConfiguration bccClientConfiguration = new BccClientConfiguration()
13 .withProtocol(Protocol.HTTP)
14 .withCredentials(new DefaultBceCredentials(ak, sk))
15 .withEndpoint(endpoint);
16 // Create a BCC client
17 BccClient client = new BccClient(bccClientConfiguration);
18 ListSnapshotsRequest listSnapshotsRequest = new ListSnapshotsRequest();
19 // Set pagination flag
20 listSnapshotsRequest.setMarker("marker");
21 // Set size of paginated returned data
22 listSnapshotsRequest.setMaxKeys(100);
23 // Filter snapshots queried from specified disk
24 listSnapshotsRequest.setVolumeId("v-***");
25 System.out.println(client.listSnapshots(listSnapshotsRequest));
26 }
27}
Query snapshot details
You query snapshot details with the following code:
Java
1import com.baidubce.BceClientConfiguration;
2import com.baidubce.Protocol;
3import com.baidubce.auth.DefaultBceCredentials;
4public class GetSnapshot {
5 public static void main(String[] args) {
6 // Set your AK, SK and the endpoint to be accessed
7 String endpoint = "http://bcc.bj.baidubce.com";
8 String ak = "ak";
9 String sk = "sk";
10 // Set default configuration
11 BceClientConfiguration bccClientConfiguration = new BccClientConfiguration()
12 .withProtocol(Protocol.HTTP)
13 .withCredentials(new DefaultBceCredentials(ak, sk))
14 .withEndpoint(endpoint);
15 // Create a BCC client
16 BccClient client = new BccClient(bccClientConfiguration);
17 // Snapshot ID
18 String snapshotId = "s-***";
19 System.out.println(client.getSnapshot(snapshotId));
20 }
21}
Delete a snapshot
You can delete a snapshot with the following code:
Java
1import com.baidubce.BceClientConfiguration;
2import com.baidubce.Protocol;
3import com.baidubce.auth.DefaultBceCredentials;
4public class DeleteSnap {
5 public static void main(String[] args) {
6 // Set your AK, SK and the endpoint to be accessed
7 String endpoint = "http://bcc.bj.baidubce.com";
8 String ak = "ak";
9 String sk = "sk";
10 // Set default configuration
11 BceClientConfiguration bccClientConfiguration = new BccClientConfiguration()
12 .withProtocol(Protocol.HTTP)
13 .withCredentials(new DefaultBceCredentials(ak, sk))
14 .withEndpoint(endpoint);
15 // Create a BCC client
16 BccClient client = new BccClient(bccClientConfiguration);
17 // Snapshot ID
18 String snapshotId = "s-***";
19 client.deleteSnapshot(snapshotId);
20 }
21}
Query snapshot chain list
You query the list information of a user's snapshot chains with the following code:
Java
1import com.baidubce.BceClientConfiguration;
2import com.baidubce.Protocol;
3import com.baidubce.auth.DefaultBceCredentials;
4import com.baidubce.services.bcc.model.snapshot.ListSnapchainRequest;
5import com.baidubce.services.bcc.model.snapshot.ListSnapchainResponse;
6public class ListSnapchain {
7 public static void main(String[] args) {
8 // Set your AK, SK and the endpoint to be accessed
9 String endpoint = "http://bcc.bj.baidubce.com";
10 String ak = "ak";
11 String sk = "sk";
12 // Set default configuration
13 BceClientConfiguration bccClientConfiguration = new BccClientConfiguration()
14 .withProtocol(Protocol.HTTP)
15 .withCredentials(new DefaultBceCredentials(ak, sk))
16 .withEndpoint(endpoint);
17 // Create a BCC client
18 BccClient client = new BccClient(bccClientConfiguration);
19 ListSnapchainRequest request = new ListSnapchainRequest();
20 // Sorting attributes, optional: chainId (snapshot chain ID, default), chainSize (snapshot chain size), volumeSize (disk size)
21 request.setOrderBy("chainId");
22 // Sorting method, optional: asc (ascending order, default), desc (descending order)
23 request.setOrder("asc");
24 // Page number, optional: Default value is 1
25 request.setPageNo(1);
26 // Capacity per page, optional: Default value is 1000
27 request.setPageSize(100);
28 // Disk ID, optional: if this field is not empty, only snapshot chain information for this disk will be returned
29 request.setVolumeId("v-***");
30 ListSnapchainResponse response = client.listSnapchain(request);
31 System.out.println(response);
32 }
33}
