自动快照策略
更新时间:2024-07-02
创建自动快照策略
以下代码用于创建自动快照策略:
from baidubce.auth.bce_credentials import BceCredentials
from baidubce.bce_client_configuration import BceClientConfiguration
from baidubce.services.bcc import bcc_client, bcc_model
if __name__ == '__main__':
# 设置您的ak、sk和要访问的地域
HOST = b'http://bcc.bj.baidubce.com'
AK = b'ak'
SK = b'sk'
# 设置默认配置
config = BceClientConfiguration(credentials=BceCredentials(AK, SK),
endpoint=HOST)
# 创建bcc client
client = bcc_client.BccClient(config)
#设置快照名称
asp_name = 'your-asp-name'
#设置一天中做快照的时间点,取值为0~23,0为午夜12点
time_points = [0, 22]
#设置一周中做快照的时间点,取值为0~6,0为周日
repeat_week_days = [0, 5]
#设置自动快照保留天数,-1为永久保留
retention_days = '-1'
resp = client.create_asp(asp_name=asp_name,
time_points=time_points,
repeat_week_days=repeat_week_days,
retention_days=retention_days)
print(resp)
绑定自动快照策略
以下代码用于绑定自动快照策略:
from baidubce.auth.bce_credentials import BceCredentials
from baidubce.bce_client_configuration import BceClientConfiguration
from baidubce.services.bcc import bcc_client
if __name__ == '__main__':
# 设置您的ak、sk和要访问的地域
HOST = b'http://bcc.bj.baidubce.com'
AK = b'ak'
SK = b'sk'
# 设置默认配置
config = BceClientConfiguration(credentials=BceCredentials(AK, SK),
endpoint=HOST)
# 创建bcc client
client = bcc_client.BccClient(config)
# 设置需要绑定的快照id
asp_id = 'asp-hZll9***'
# 设置需要绑定的磁盘id,可多选
volume_ids = ['v-***', 'v-***']
client.attach_asp(asp_id=asp_id, volume_ids=volume_ids)
解绑自动快照策略
以下代码用于解绑自动快照策略:
from baidubce.auth.bce_credentials import BceCredentials
from baidubce.bce_client_configuration import BceClientConfiguration
from baidubce.services.bcc import bcc_client
if __name__ == '__main__':
# 设置您的ak、sk和要访问的地域
HOST = b'http://bcc.bj.baidubce.com'
AK = b'ak'
SK = b'sk'
# 设置默认配置
config = BceClientConfiguration(credentials=BceCredentials(AK, SK),
endpoint=HOST)
# 创建bcc client
client = bcc_client.BccClient(config)
# 设置需要解绑的快照id
asp_id = 'asp-hZll9***'
# 设置需要解绑的磁盘id,可多选
volume_ids = ['v-***', 'v-***']
client.detach_asp(asp_id=asp_id, volume_ids=volume_ids)
删除自动快照策略
以下代码用于删除自动快照策略:
from baidubce.auth.bce_credentials import BceCredentials
from baidubce.bce_client_configuration import BceClientConfiguration
from baidubce.services.bcc import bcc_client
if __name__ == '__main__':
# 设置您的ak、sk和要访问的地域
HOST = b'http://bcc.bj.baidubce.com'
AK = b'ak'
SK = b'sk'
# 设置默认配置
config = BceClientConfiguration(credentials=BceCredentials(AK, SK),
endpoint=HOST)
# 创建bcc client
client = bcc_client.BccClient(config)
# 设置需要删除的快照id
asp_id = 'asp-hZll9***'
client.delete_asp(asp_id=asp_id)
查询自动快照策略列表
以下代码用于查询自动快照策略列表:
from baidubce.auth.bce_credentials import BceCredentials
from baidubce.bce_client_configuration import BceClientConfiguration
from baidubce.services.bcc import bcc_client
if __name__ == '__main__':
# 设置您的ak、sk和要访问的地域
HOST = b'http://bcc.bj.baidubce.com'
AK = b'ak'
SK = b'sk'
# 设置默认配置
config = BceClientConfiguration(credentials=BceCredentials(AK, SK),
endpoint=HOST)
# 创建bcc client
client = bcc_client.BccClient(config)
resp = client.list_asps()
print(resp)
查询自动快照策略详情
以下代码用于查询自动快照策略详情:
from baidubce.auth.bce_credentials import BceCredentials
from baidubce.bce_client_configuration import BceClientConfiguration
from baidubce.services.bcc import bcc_client
if __name__ == '__main__':
# 设置您的ak、sk和要访问的地域
HOST = b'http://bcc.bj.baidubce.com'
AK = b'ak'
SK = b'sk'
# 设置默认配置
config = BceClientConfiguration(credentials=BceCredentials(AK, SK),
endpoint=HOST)
# 创建bcc client
client = bcc_client.BccClient(config)
# 设置需要查询的快照id
asp_id = 'asp-hZll9***'
resp = client.get_asp(asp_id=asp_id)
print(resp)
自动快照策略变更
以下代码可以更新一个自动快照策略:
from baidubce.auth.bce_credentials import BceCredentials
from baidubce.bce_client_configuration import BceClientConfiguration
from baidubce.services.bcc import bcc_client, bcc_model
if __name__ == '__main__':
# 设置您的ak、sk和要访问的地域
HOST = 'http://bcc.bj.baidubce.com'
AK = 'ak'
SK = 'sk'
# 设置默认配置
config = BceClientConfiguration(credentials=BceCredentials(AK, SK),
endpoint=HOST)
# 创建bcc client
client = bcc_client.BccClient(config)
resp = client.update_asp(name="changeDone1", # 自动快照策略名称,支持大小写字母、数字、中文以及-_ /.特殊字符,必须以字母开头,长度1-65。
asp_id="asp-osTov***", # 自动策略的id
time_points=[1, 2], # 一天中做快照时间点,取值为0~23。
repeat_week_days=[1, 2], # 一周中做快照的时间,取值为0~6。
retention_days=12) # 自动快照保留天数,取-1则永久保留。
print(resp)