自动快照策略
更新时间:2024-07-02
创建自动快照策略
创建自动快照策略,参考如下代码:
import com.baidubce.BceClientConfiguration;
import com.baidubce.Protocol;
import com.baidubce.auth.DefaultBceCredentials;
import com.baidubce.services.bcc.BccClient;
import com.baidubce.services.bcc.BccClientConfiguration;
import com.baidubce.services.bcc.model.asp.CreateAspRequest;
import com.baidubce.services.bcc.model.asp.CreateAspResponse;
import java.util.ArrayList;
import java.util.List;
public class Main {
public static void main(String[] args) {
// 设置您的ak、sk和要访问的endpoint
String endpoint = "bcc.bj.baidubce.com";
String ak = "ak";
String sk = "sk";
// 设置默认配置
BceClientConfiguration bccClientConfiguration = new BccClientConfiguration()
.withProtocol(Protocol.HTTP)
.withCredentials(new DefaultBceCredentials(ak, sk))
.withEndpoint(endpoint);
// 创建bcc client
BccClient bccClient = new BccClient(bccClientConfiguration);
CreateAspRequest createAspRequest = new CreateAspRequest();
// 设置快照名
createAspRequest.setName("test-asp-name");
// 设置一天中做快照的时间点,取值为0~23,0为午夜12点
// 例如设置做快照的时间点为凌晨2点和下午2点:
List<Integer> timePoints = new ArrayList<Integer>();
timePoints.add(2);
timePoints.add(14);
createAspRequest.setTimePoints(timePoints);
// 设置一周中做快照的时间,取值为0~6,0代表周日,1~6代表周一到周六
// 例如设置做快照的时间为礼拜五:
List<Integer> repeatWeekdays = new ArrayList<Integer>();
repeatWeekdays.add(5);
createAspRequest.setRepeatWeekdays(repeatWeekdays);
// 设置自动快照保留天数,取-1则永久保留
createAspRequest.setRetentionDays("7");
CreateAspResponse response = bccClient.createAsp(createAspRequest);
System.out.println(response);
}
}
绑定自动快照策略
绑定自动快照策略,参考如下代码:
import com.baidubce.BceClientConfiguration;
import com.baidubce.Protocol;
import com.baidubce.auth.DefaultBceCredentials;
import com.baidubce.services.bcc.BccClient;
import com.baidubce.services.bcc.BccClientConfiguration;
import com.baidubce.services.bcc.model.asp.AttachAspRequest;
import java.util.ArrayList;
import java.util.List;
public class Main {
public static void main(String[] args) {
// 设置您的ak、sk和要访问的endpoint
String endpoint = "bcc.bj.baidubce.com";
String ak = "ak";
String sk = "sk";
// 设置默认配置
BceClientConfiguration bccClientConfiguration = new BccClientConfiguration()
.withProtocol(Protocol.HTTP)
.withCredentials(new DefaultBceCredentials(ak, sk))
.withEndpoint(endpoint);
// 创建bcc client
BccClient bccClient = new BccClient(bccClientConfiguration);
AttachAspRequest attachAspRequest = new AttachAspRequest();
// 设置需要绑定的自动快照策略ID
attachAspRequest.setAspId("asp-***");
// 设置需要绑定的磁盘ID
List<String> volumeIds = new ArrayList<String>();
volumeIds.add("v-***");
volumeIds.add("v-***");
attachAspRequest.setVolumeIds(volumeIds);
bccClient.attachAsp(attachAspRequest);
}
}
解绑自动快照策略
解绑自动快照策略,参考如下代码:
import com.baidubce.BceClientConfiguration;
import com.baidubce.Protocol;
import com.baidubce.auth.DefaultBceCredentials;
import com.baidubce.services.bcc.BccClient;
import com.baidubce.services.bcc.BccClientConfiguration;
import com.baidubce.services.bcc.model.asp.DetachAspRequest;
import java.util.ArrayList;
import java.util.List;
public class Main {
public static void main(String[] args) {
// 设置您的ak、sk和要访问的endpoint
String endpoint = "bcc.bj.baidubce.com";
String ak = "ak";
String sk = "sk";
// 设置默认配置
BceClientConfiguration bccClientConfiguration = new BccClientConfiguration()
.withProtocol(Protocol.HTTP)
.withCredentials(new DefaultBceCredentials(ak, sk))
.withEndpoint(endpoint);
// 创建bcc client
BccClient bccClient = new BccClient(bccClientConfiguration);
DetachAspRequest detachAspRequest = new DetachAspRequest();
// 设置需要解绑的自动快照策略ID
detachAspRequest.setAspId("asp-***");
// 设置需要解绑的磁盘ID
List<String> volumeIds = new ArrayList<String>();
volumeIds.add("v-***");
volumeIds.add("v-***");
detachAspRequest.setVolumeIds(volumeIds);
bccClient.detachAsp(detachAspRequest);
}
}
删除自动快照策略
删除自动快照策略,参考如下代码:
import com.baidubce.BceClientConfiguration;
import com.baidubce.Protocol;
import com.baidubce.auth.DefaultBceCredentials;
import com.baidubce.services.bcc.BccClient;
import com.baidubce.services.bcc.BccClientConfiguration;
import com.baidubce.services.bcc.model.asp.DeleteAspRequest;
public class Main {
public static void main(String[] args) {
// 设置您的ak、sk和要访问的endpoint
String endpoint = "bcc.bj.baidubce.com";
String ak = "ak";
String sk = "sk";
// 设置默认配置
BceClientConfiguration bccClientConfiguration = new BccClientConfiguration()
.withProtocol(Protocol.HTTP)
.withCredentials(new DefaultBceCredentials(ak, sk))
.withEndpoint(endpoint);
// 创建bcc client
BccClient bccClient = new BccClient(bccClientConfiguration);
DeleteAspRequest deleteAspRequest = new DeleteAspRequest();
// 设置需要删除的自动快照策略ID
deleteAspRequest.setAspId("asp-***");
bccClient.deleteAsp(deleteAspRequest);
}
}
查询自动快照策略列表
查询自动快照策略列表,参考如下代码:
import com.baidubce.BceClientConfiguration;
import com.baidubce.Protocol;
import com.baidubce.auth.DefaultBceCredentials;
import com.baidubce.services.bcc.BccClient;
import com.baidubce.services.bcc.BccClientConfiguration;
import com.baidubce.services.bcc.model.AutoSnapshotPolicyModel;
import com.baidubce.services.bcc.model.asp.ListAspsRequest;
import com.baidubce.services.bcc.model.asp.ListAspsResponse;
public class Main {
public static void main(String[] args) {
// 设置您的ak、sk和要访问的endpoint
String endpoint = "bcc.bj.baidubce.com";
String ak = "ak";
String sk = "sk";
// 设置默认配置
BceClientConfiguration bccClientConfiguration = new BccClientConfiguration()
.withProtocol(Protocol.HTTP)
.withCredentials(new DefaultBceCredentials(ak, sk))
.withEndpoint(endpoint);
// 创建bcc client
BccClient bccClient = new BccClient(bccClientConfiguration);
ListAspsRequest listAspsRequest = new ListAspsRequest();
// 设置需要查找的自动快照策略名称
listAspsRequest.setAspName("test_stratery");
// 设置需要查找的自动快照策略ID
listAspsRequest.setMarker("asp-***");
// 设置返回数据大小
listAspsRequest.setMaxKeys(10);
ListAspsResponse listAspsResponse = bccClient.listAsps(listAspsRequest);
for (AutoSnapshotPolicyModel asp : listAspsResponse.getAutoSnapshotPolicys()) {
System.out.println(asp);
}
}
}
查询自动快照策略详情
查询自动快照策略详情,参考如下代码:
import com.baidubce.BceClientConfiguration;
import com.baidubce.Protocol;
import com.baidubce.auth.DefaultBceCredentials;
import com.baidubce.services.bcc.BccClient;
import com.baidubce.services.bcc.BccClientConfiguration;
import com.baidubce.services.bcc.model.asp.GetAspRequest;
import com.baidubce.services.bcc.model.asp.GetAspResponse;
public class Main {
public static void main(String[] args) {
// 设置您的ak、sk和要访问的endpoint
String endpoint = "bcc.bj.baidubce.com";
String ak = "ak";
String sk = "sk";
// 设置默认配置
BceClientConfiguration bccClientConfiguration = new BccClientConfiguration()
.withProtocol(Protocol.HTTP)
.withCredentials(new DefaultBceCredentials(ak, sk))
.withEndpoint(endpoint);
// 创建bcc client
BccClient bccClient = new BccClient(bccClientConfiguration);
GetAspRequest getAspRequest = new GetAspRequest();
// 设置需要查找的自动快照策略ID
getAspRequest.setAspId("asp-***");
GetAspResponse getAspResponse = bccClient.getAsp(getAspRequest);
System.out.println(getAspResponse);
}
}
自动快照策略变更
自动快照策略修改,参考如下代码。支持修改的内容:策略名称、创建时间、重复日期、保留时间。
import com.baidubce.BceClientConfiguration;
import com.baidubce.Protocol;
import com.baidubce.auth.DefaultBceCredentials;
import com.baidubce.services.bcc.BccClient;
import com.baidubce.services.bcc.BccClientConfiguration;
import com.baidubce.services.bcc.model.asp.UpdateAspRequest;
import java.util.ArrayList;
import java.util.List;
public class UpdateAsp {
public static void main(String[] args) {
// 设置您的ak、sk和要访问的endpoint
String endpoint = "http://bcc.bj.baidubce.com";
String ak = "ak";
String sk = "sk";
// 设置默认配置
BceClientConfiguration bccClientConfiguration = new BccClientConfiguration()
.withProtocol(Protocol.HTTP)
.withCredentials(new DefaultBceCredentials(ak, sk))
.withEndpoint(endpoint);
// 创建bcc client
BccClient client = new BccClient(bccClientConfiguration);
String aspId = "asp-osTov***";
String name= "changeDown";
List<String> timePoints = new ArrayList<String>(){{add("12"); add("22");}};
List<String> repeatWeekdays = new ArrayList<String>(){{add("1"); add("5");}};
String retentionDays = "5";
UpdateAspRequest updateAspRequest = new UpdateAspRequest();
// 必填,自动策略的id
updateAspRequest.setAspId(aspId);
// 必填,自动快照策略名称,支持大小写字母、数字、中文以及-_ /.特殊字符,必须以字母开头,长度1-65。
updateAspRequest.setName(name);
// 必填,一天中做快照时间点,取值为0~23。
updateAspRequest.setTimePoints(timePoints);
// 必填,一周中做快照的时间,取值为0~6。
updateAspRequest.setRepeatWeekdays(repeatWeekdays);
// 必填,自动快照保留天数,取-1则永久保留。
updateAspRequest.setRetentionDays(retentionDays);
client.updateAsp(updateAspRequest);
}
}