Automatic Snapshot Policy
Last Updated:2020-07-20
Create an automatic snapshot policy
Create an automatic snapshot policy by using the following codes:
public static void createAsp(BccClient bccClient, String aspName, List<String> time, List<String> week, String days) {
CreateAspRequest createAspRequest = new CreateAspRequest();
// Set a snapshot id name
createAspRequest.setName(aspName);
// Set Time points for snapshot in a day, the value is 0-23, where 0 is midnight.
// For example, set the snapshot time to 2 pm:
// createAspRequest.setTimePoints(14)
createAspRequest.setTimePoints(time);
// Set the snapshot time during the week. The value ranges from 0 to 6, where 0 is Sunday and 1 to 6 is Monday to Saturday
// For example, set the snapshot time to Friday:
// createAspRequest.setRepeatWeekdays(5)
createAspRequest.setRepeatWeekdays(week);
Set automatic snapshot retention days, take -1 for permanent retention
createAspRequest.setRetentionDays(days);
bccClient.createAsp(createAspRequest);
}
Bind an automatic snapshot policy
Bind an automatic snapshot policy by using the following codes:
public static void attachAsp(BccClient bccClient, String aspId, List<String> volumeIds) {
AttachAspRequest attachAspRequest = new AttachAspRequest();
// Set an automatic snapshot policy ID to be bound
attachAspRequest.setAspId(aspId);
// Set a disk ID to be bound
attachAspRequest.setVolumeIds(volumeIds);
bccClient.attachAsp(attachAspRequest);
}
Unbind automatic snapshot policies
Unbind automatic snapshot policies by using the following codes:
public static void detachAsp(BccClient bccClient, String aspId, List<String> volumeIds) {
DetachAspRequest detachAspRequest = new DetachAspRequest();
// Set an automatic snapshot policy ID to be unbound
detachAspRequest.setAspId(aspId);
// Set a disk ID to be unbound
detachAspRequest.setVolumeIds(volumeIds);
bccClient.detachAsp(detachAspRequest);
}
Delete an Automatic Snapshot Policy
Delete an automatic snapshot policy by using the following codes:
public static void deleteAsp(BccClient bccClient, String aspId) {
DeleteAspRequest deleteAspRequest = new DeleteAspRequest();
// Set an automatic snapshot policy ID to be deleted
deleteAspRequest.setAspId(aspId);
bccClient.deleteAsp(deleteAspRequest);
}
Query the automatic snapshot policy list
Query the automatic snapshot policy list by using the following codes:
public static void listAsps(BccClient bccClient, String aspName, String aspId, int maxKeys, String volumeName) {
ListAspsRequest listAspsRequest = new ListAspsRequest();
// Setup a automatic snapshot policy name to be searched
listAspsRequest.setName(aspName);
// Set the start point
listAspsRequest.setMarker(aspId);
// Set the return data size
listAspsRequest.setMaxKeys(maxKeys);
ListAspsResponse listAspsResponse = bccClient.listAsps(listAspsRequest);
}
Query the automatic snapshot policy details
Query the automatic snapshot policy details by using the following codes:
public static void getAsp(BccClient bccClient, String aspId) {
GetAspRequest getAspRequest = new GetAspRequest();
//Set a automatic snapshot policy ID
getAspRequest.setAspId(aspId);
GetAspResponse getAspResponse = bccClient.getAsp(getAspRequest);
}