Snapshot
Create a snapshot
It is used to create snapshots from specific disks, supporting both system disks and CDS disks.
To successfully create a snapshot of a system disk, the instance must be in either the Running or Stopped state.
When creating a snapshot for a CDS disk, the disk must be in the "InUse" or "Available" state for the operation to succeed.
The quota for the number of snapshots that can be created depends on the total number of disks owned by the account, currently capped at 8 times the number of disks:
1import uuid
2from baidubce.auth.bce_credentials import BceCredentials
3from baidubce.bce_client_configuration import BceClientConfiguration
4from baidubce.services.bcc import bcc_client
5if __name__ == '__main__':
6# Set your AK, SK, and the region to be accessed
7 HOST = b'http://bcc.bj.baidubce.com'
8 AK = b'ak'
9 SK = b'sk'
10# Set default configuration
11 config = BceClientConfiguration(credentials=BceCredentials(AK, SK),
12 endpoint=HOST)
13# Create a BCC client
14 client = bcc_client.BccClient(config)
15 client_token = str(uuid.uuid4())
16# Set snapshot name
17 snapshot_name = 'snapshot***'
18# Disk ID for Snapshot Creation
19 volume_id = 'v-***'
20 resp = client.create_snapshot(volume_id, snapshot_name, client_token=client_token)
21 print(resp)
Query the snapshot list
The following code can be used to query all snapshot information, including snapshots of system disks and data disks:
1from baidubce.auth.bce_credentials import BceCredentials
2from baidubce.bce_client_configuration import BceClientConfiguration
3from baidubce.services.bcc import bcc_client
4if __name__ == '__main__':
5# Set your AK, SK, and the region to be accessed
6 HOST = b'http:/bcc.bj.baidubce.com'
7 AK = b'ak'
8 SK = b'sk'
9# Set default configuration
10 config = BceClientConfiguration(credentials=BceCredentials(AK, SK),
11 endpoint=HOST)
12# Create a BCC client
13 client = bcc_client.BccClient(config)
14# Disk ID for Snapshot Creation
15 volume_id = 'v-***'
16# Starting position of the batch list query
17 marker = "your-marker"
18# Maximum number of items included per page
19 max_keys = 100
20 resp = client.list_snapshots(marker=marker, max_keys=max_keys, volume_id=volume_id)
21 print(resp)
Query snapshot details
The following code can be used to query the detailed information of a single snapshot by the user's specified snapshot ID:
1from baidubce.auth.bce_credentials import BceCredentials
2from baidubce.bce_client_configuration import BceClientConfiguration
3from baidubce.services.bcc import bcc_client
4if __name__ == '__main__':
5# Set your AK, SK, and the region to be accessed
6 HOST = b'http://bcc.bj.baidubce.com'
7 AK = b'ak'
8 SK = b'sk'
9# Set default configuration
10 config = BceClientConfiguration(credentials=BceCredentials(AK, SK),
11 endpoint=HOST)
12# Create a BCC client
13 client = bcc_client.BccClient(config)
14# Snapshot ID
15 snapshot_id = 's-***'
16 resp = client.get_snapshot(snapshot_id)
17 print(resp)
Delete a snapshot
The following code can be used to delete snapshot by specified snapshot ID:
This operation can only be completed normally when the snapshot status is CreatedFailed or Available:
1from baidubce.auth.bce_credentials import BceCredentials
2from baidubce.bce_client_configuration import BceClientConfiguration
3from baidubce.services.bcc import bcc_client
4if __name__ == '__main__':
5# Set your AK, SK, and the region to be accessed
6 HOST = b'http://bcc.bj.baidubce.com'
7 AK = b'ak'
8 SK = b'sk'
9# Set default configuration
10 config = BceClientConfiguration(credentials=BceCredentials(AK, SK),
11 endpoint=HOST)
12# Create a BCC client
13 client = bcc_client.BccClient(config)
14# ID of snapshot to be deleted
15 snapshot_id = 's-***'
16 resp = client.delete_snapshot(snapshot_id=snapshot_id)
17 print(resp)
