Automatic snapshot policy
Updated at:2025-10-20
Create automatic snapshot policy
The following code is used to create an automatic snapshot policy:
Plain Text
1 from baidubce.auth.bce_credentials import BceCredentials
2 from baidubce.bce_client_configuration import BceClientConfiguration
3 from baidubce.services.bcc import bcc_client, bcc_model
4
5 if __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
16 # Set snapshot name
17 asp_name = 'your-asp-name'
18 # Set time points for snapshots per day, ranging from 0 to 23, where 0 represents midnight 12 o'clock
19 time_points = [0, 22]
20 #Set time points for snapshots per week, ranging from 0 to 6, where 0 represents Sunday
21 repeat_week_days = [0, 5]
22 #Set number of days to retain automatic snapshots. -1 indicates permanent retention
23 retention_days = '-1'
24 resp = client.create_asp(asp_name=asp_name,
25 time_points=time_points,
26 repeat_week_days=repeat_week_days,
27 retention_days=retention_days)
28 print(resp)
Bind automatic snapshot policy
The following code is used to bind an automatic snapshot policy:
Plain Text
1 from baidubce.auth.bce_credentials import BceCredentials
2 from baidubce.bce_client_configuration import BceClientConfiguration
3 from baidubce.services.bcc import bcc_client
4
5 if __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
16# Set ID of snapshot to be bound
17 asp_id = 'asp-hZll9***'
18# Set ID of disk to be bound. Multiple options are available
19 volume_ids = ['v-***', 'v-***']
20
21 client.attach_asp(asp_id=asp_id, volume_ids=volume_ids)
Unbind automatic snapshot policy
The following code is used to unbind an automatic snapshot policy:
Plain Text
1 from baidubce.auth.bce_credentials import BceCredentials
2 from baidubce.bce_client_configuration import BceClientConfiguration
3 from baidubce.services.bcc import bcc_client
4
5 if __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
16# Set ID of snapshot to be unbound
17 asp_id = 'asp-hZll9***'
18# Set ID of disk to be unbound. Multiple options are available
19 volume_ids = ['v-***', 'v-***']
20
21 client.detach_asp(asp_id=asp_id, volume_ids=volume_ids)
Delete automatic snapshot policy
The following code is used to delete an automatic snapshot policy:
Plain Text
1 from baidubce.auth.bce_credentials import BceCredentials
2 from baidubce.bce_client_configuration import BceClientConfiguration
3 from baidubce.services.bcc import bcc_client
4
5 if __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
16# Set ID of snapshot to be deleted
17 asp_id = 'asp-hZll9***'
18
19 client.delete_asp(asp_id=asp_id)
Query the list of automatic snapshot policies
The following code is used to query the list of automatic snapshot policies:
Plain Text
1 from baidubce.auth.bce_credentials import BceCredentials
2 from baidubce.bce_client_configuration import BceClientConfiguration
3 from baidubce.services.bcc import bcc_client
4
5 if __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
16 resp = client.list_asps()
17 print(resp)
Query details of automatic snapshot policy
The following code is used to query the details of automatic snapshot policy:
Plain Text
1 from baidubce.auth.bce_credentials import BceCredentials
2 from baidubce.bce_client_configuration import BceClientConfiguration
3 from baidubce.services.bcc import bcc_client
4
5 if __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
16# Set ID of snapshot to be queried
17 asp_id = 'asp-hZll9***'
18
19 resp = client.get_asp(asp_id=asp_id)
20 print(resp)
Update automatic snapshot policy
You can update an automatic snapshot policy with the following code:
Python
1from baidubce.auth.bce_credentials import BceCredentials
2from baidubce.bce_client_configuration import BceClientConfiguration
3from baidubce.services.bcc import bcc_client, bcc_model
4if __name__ == '__main__':
5# Set your AK, SK, and the region to be accessed
6 HOST = 'http://bcc.bj.baidubce.com'
7 AK = 'ak'
8 SK = '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 resp = client.update_asp(name="changeDone1", # Automatic snapshot policy name, which supports uppercase and lowercase letters, numbers, Chinese characters, and special characters -_ /., starting with a letter and a length of 1-65.
15 asp_id="asp-osTov***", # ID of automatic policy
16 time_points=[1, 2], # Time points for snapshots per day, ranging from 0 to 23
17 repeat_week_days=[1, 2], # Time for snapshots per week, ranging from 0 to 6.
18 retention_days=12) # Number of days to retain automatic snapshots. A value of -1 indicates permanent retention.
19 print(resp)
