Snapshot
Updated at:2025-10-20
Create a snapshot
You can create a snapshot with the following code:
Go
1package main
2import (
3 "fmt"
4 "github.com/baidubce/bce-sdk-go/services/bcc"
5 "github.com/baidubce/bce-sdk-go/services/bcc/api"
6)
7func main() {
8 // Set your AK, SK and the endpoint to be accessed
9 ak := "ak"
10 sk := "sk"
11 endpoint := "http://bcc.bj.baidubce.com"
12 // Create a BCC client
13 bccClient, _ := bcc.NewClient(ak, sk, endpoint)
14 args := &api.CreateSnapshotArgs{
15 // Disk ID
16 VolumeId: "v-***",
17 SnapshotName: "snapshotName",
18 Description: "create by sdk",
19 }
20 result, err := bccClient.CreateSnapshot(args)
21 if err != nil {
22 fmt.Println("create snapshot failed:", err)
23 } else {
24 fmt.Println("create snapshot success: ", result)
25 }
26}
Query the snapshot list
You can query the list of all snapshots under the current account with the following code:
Go
1package main
2import (
3 "fmt"
4 "github.com/baidubce/bce-sdk-go/services/bcc"
5 "github.com/baidubce/bce-sdk-go/services/bcc/api"
6)
7func main() {
8 // Set your AK, SK and the endpoint to be accessed
9 ak := "ak"
10 sk := "sk"
11 endpoint := "http://bcc.bj.baidubce.com"
12 // Create a BCC client
13 bccClient, _ := bcc.NewClient(ak, sk, endpoint)
14 args := &api.ListSnapshotArgs{}
15 result, err := bccClient.ListSnapshot(args)
16 if err != nil {
17 fmt.Println("list all snapshot failed:", err)
18 } else {
19 fmt.Println("list all snapshot success: ", result)
20 }
21}
Query snapshot details
You can query detailed information about a specific snapshot with the following code:
Go
1package main
2import (
3 "fmt"
4 "github.com/baidubce/bce-sdk-go/services/bcc"
5)
6func main() {
7 // Set your AK, SK and the endpoint to be accessed
8 ak := "ak"
9 sk := "sk"
10 endpoint := "http://bcc.bj.baidubce.com"
11 // Create a BCC client
12 bccClient, _ := bcc.NewClient(ak, sk, endpoint)
13 // Snapshot ID
14 snapshotId := "s-***"
15 result, err := bccClient.GetSnapshotDetail(snapshotId)
16 if err != nil {
17 fmt.Println("get snapshot detail failed:", err)
18 } else {
19 fmt.Println("get snapshot detail success: ", result)
20 }
21}
Delete a snapshot
You can delete a snapshot with the following code:
Go
1package main
2import (
3 "fmt"
4 "github.com/baidubce/bce-sdk-go/services/bcc"
5)
6func main() {
7 // Set your AK, SK and the endpoint to be accessed
8 ak := "ak"
9 sk := "sk"
10 endpoint := "http://bcc.bj.baidubce.com"
11 // Create a BCC client
12 bccClient, _ := bcc.NewClient(ak, sk, endpoint)
13 // Snapshot ID
14 snapshotId := "s-***"
15 err := bccClient.DeleteSnapshot(snapshotId)
16 if err != nil {
17 fmt.Println("delete snapshot failed:", err)
18 } else {
19 fmt.Println("delete snapshot success")
20 }
21}
Query snapshot chain list
You can query the snapshot chain list with the following code:
Go
1package main
2import (
3 "fmt"
4 "github.com/baidubce/bce-sdk-go/services/bcc"
5 "github.com/baidubce/bce-sdk-go/services/bcc/api"
6)
7func main() {
8 // Set your AK, SK and the endpoint to be accessed
9 ak := "ak"
10 sk := "sk"
11 endpoint := "http://bcc.bj.baidubce.com"
12 // Create a BCC client
13 bccClient, _ := bcc.NewClient(ak, sk, endpoint)
14 args := &api.ListSnapshotChainArgs{
15 // Set sorting attribute: chainId (snapshot chain ID, default value), chainSize (snapshot chain size), volumeSize (disk size). Optional
16 OrderBy: "your-order-by",
17 // Set sorting method: asc (ascending order, default value), desc (descending order). Optional
18 Order: "your-order",
19 // Set page size, defaulting to 1,000, optional
20 PageSize: 100,
21 // Set page number, defaulting to 1, optional
22 PageNo: 1,
23 // Set disk ID; if this field is not empty, only snapshot chain information for this disk will be returned; optional
24 VolumeId: "v-***",
25 }
26 if res, err := bccClient.ListSnapshotChain(args); err != nil {
27 fmt.Println("get snapshot chain list failed: ", err)
28 } else {
29 fmt.Println("get snapshot chain list success, Snapshots: ", res)
30 }
31}
Bind a tag to a snapshot chain
You can bind a tag to a snapshot chain with the following code:
Go
1package main
2import (
3 "fmt"
4 "github.com/baidubce/bce-sdk-go/services/bcc"
5 "github.com/baidubce/bce-sdk-go/services/bcc/api"
6)
7func main() {
8 // Set your AK, SK and the endpoint to be accessed
9 ak := "ak"
10 sk := "sk"
11 endpoint := "http://bcc.bj.baidubce.com"
12 // Create a BCC client
13 bccClient, _ := bcc.NewClient(ak, sk, endpoint)
14 tagArgs := &api.TagVolumeArgs{
15 ChangeTags: []api.Tag{
16 {
17 TagKey: "Key***",
18 TagValue: "Value***",
19 },
20 },
21 }
22 err := bccClient.TagSnapshotChain("your-chain-id", tagArgs)
23 if err != nil {
24 fmt.Println("tag snapshotChain failed:", err)
25 } else {
26 fmt.Println("tag snapshotChain success")
27 }
28}
Unbind a tag from a snapshot chain
You can bind a tag to a snapshot chain with the following code:
Go
1package main
2import (
3 "fmt"
4 "github.com/baidubce/bce-sdk-go/services/bcc"
5 "github.com/baidubce/bce-sdk-go/services/bcc/api"
6)
7func main() {
8 // Set your AK, SK and the endpoint to be accessed
9 ak := "ak"
10 sk := "sk"
11 endpoint := "http://bcc.bj.baidubce.com"
12 // Create a BCC client
13 bccClient, _ := bcc.NewClient(ak, sk, endpoint)
14 tagArgs := &api.TagVolumeArgs{
15 ChangeTags: []api.Tag{
16 {
17 TagKey: "Key***",
18 TagValue: "Value***",
19 },
20 },
21 }
22 err := bccClient.UntagSnapshotChain("your-chain-id", tagArgs)
23 if err != nil {
24 fmt.Println("untag snapshotChain failed:", err)
25 } else {
26 fmt.Println("untag snapshotChain success")
27 }
28}
Replicate a snapshot across regions
You can replicate a disk snapshot from one region to another with the following code:
Go
1package main
2import (
3 "fmt"
4 "github.com/baidubce/bce-sdk-go/services/bcc"
5 "github.com/baidubce/bce-sdk-go/services/bcc/api"
6)
7func main() {
8 // Set your AK, SK and the endpoint to be accessed
9 ak := "ak"
10 sk := "sk"
11 endpoint := "bcc.bj.baidubce.com"
12 // Create a BCC client
13 bccClient, _ := bcc.NewClient(ak, sk, endpoint)
14
15 // Snapshot ID
16 snapshotId := "s-***"
17 args := &api.RemoteCopySnapshotArgs{
18 DestRegionInfos: []api.DestRegionInfo{
19 {
20 // Snapshot name
21 Name: "your_snap_name_for_hkg",
22 // Destination region
23 DestRegion: "hkg",
24 },
25 {
26 // Snapshot name
27 Name: "your_snap_name_for_fwh",
28 // Destination region
29 DestRegion: "fwh",
30 },
31 },
32 }
33 // Request to replicate a snapshot across regions
34 result, err := bccClient.CreateRemoteCopySnapshot(snapshotId, args)
35 fmt.Println(err)
36 fmt.Println(result)
37}
