VBS Java SDK Demo
Creating a VBS Backup
You can create a VBS backup using OpenStack4j based on the following code. After the VBS backup is created, it will be displayed in the VBS list on the VBS console.
public static void createBackup() {
AsyncVolumeBackupCreate vbc = Builders.asyncVolumeBackupCreate()
.name(backupName)
.volumeId(volume.getId())
.build();
AsyncVolumeBackupJob job = osclient.blockStorage().asyncBackups().create(vbc);
Assert.assertNotNull(job.getId());
backupJobId = job.getId();
}
|
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
|
backup |
Yes |
dict |
Specifies the backup to be created. |
|
volume_id |
Yes |
string |
Specifies the ID of the disk to be backed up. |
|
snapshot_id |
No |
string |
Specifies the snapshot ID of the disk to be backed up. |
|
name |
Yes |
string |
Specifies the backup name. The value is a string of 1 to 64 characters consisting of digits, letters, underscores (_), and hyphens (-). |
|
description |
No |
string |
Provides supplementary information about the backup. The value is a string of 1 to 64 characters and cannot contain the less-than sign (<) or greater-than sign (>). |
Querying VBS Backup Details
You can query the backup list and obtain the backup details using OpenStack4j based on the following code:
public static void queryNativeBackupsDetail(){
// Without specifying the search criteria
List<? extends VolumeBackup> list = osclient.blockStorage().backups().list(true);
Assert.assertNotEquals(list.size(), 0);
// With the search criteria specified
HashMap<String, String> filter = new HashMap<>();
filter.put("name", backupName);
List<? extends VolumeBackup> list2 = osclient.blockStorage().backups().list(true, filter);
for (VolumeBackup backup: list2) {
Assert.assertEquals(backup.getName(), backupName);
}
}
|
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
|
name |
No |
string |
Specifies the name of the backup to be queried. This parameter is used to query the backups whose names are specified character strings. |
|
status |
No |
string |
Specifies the status of the backup to be queried. This parameter is used to query the backups in a specified state. The value can be available, error, restoring, creating, deleting, or error_deleting. |
|
offset |
No |
int |
Specifies the offset of the queried details. |
|
limit |
No |
int |
Specifies the maximum number of query results that can be returned. |
|
volume_id |
No |
string |
Specifies the disk ID of the backup to be queried. This parameter is used to query the backups for specific disks. |
Restoring a Disk Using a VBS Backup
You can restore a disk from a VBS backup using OpenStack4j based on the following code:
public static void restoreBackup() {
AsyncVolumeBackupJob job = osclient.blockStorage()
.asyncBackups()
.restore(backupId, volume.getId());
Assert.assertNotNull(job.getId());
}
|
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
|
restore |
Yes |
dict |
Specifies the operation of restoring the disk using a backup. |
|
backup_id |
Yes |
string |
Specifies the ID of the backup used to restore a disk. |
|
volume_id |
Yes |
string |
Specifies the ID of the disk to be restored. |
Deleting a Backup
You can delete a backup using OpenStack4j based on the following code:
1 2 3 4 5 |
public static void deleteNativeBackup()
{
ActionResponse delete = osclient.blockStorage().backups().delete(backupId);
Assert.assertEquals(delete.isSuccess(), true);
}
|
|
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
|
tenant_id |
Yes |
string |
Specifies the ID of the tenant. |
|
backup_id |
Yes |
string |
Specifies the ID of the backup used to restore a disk. |
Creating a Backup Policy
You can create a backup policy using OpenStack4j based on the following code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
public static void createPolicy()
{
// Create a scheduled policy first.
VBSVolumeBackupScheduledPolicy scheduledPolicy = VBSVolumeBackupScheduledPolicy.builder()
.frequency(10)
.maxBackupAmount(10)
.retainFirstBackupOfCurrentMonth(true)
.startTime("01:00")
.status(VolumeBackupPolicy.VolumeBackupPolicyStatus.OFF)
.build();
Assert.assertNotNull(scheduledPolicy);
// Create a backup policy object.
VolumeBackupPolicy create = VBSVolumeBackupPolicy.builder()
.name(policyName)
.scheduledPolicy(scheduledPolicy)
.build();
VolumeBackupPolicy policy = osclient.blockStorage().policies().create(create);
Assert.assertNotNull(policy.getId());
|
|
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
|
backup_policy_name |
Yes |
string |
Specifies the backup policy name. The name is a string of 1 to 64 characters consisting of letters, digits, underscores (_), and hyphens (-). It cannot start with default. |
|
scheduled_policy |
Yes |
dict |
Specifies details about the scheduling policy. |
|
start_time |
Yes |
string |
Specifies the backup start time, which needs to be converted into the local UTC time (on the hour only). The value is in HH:mm format. |
|
frequency |
No |
integer |
Specifies the backup interval (1 to 14 days). Select either this parameter or week_frequency. If you select both, this parameter is used. |
|
week_frequency |
No |
list<dict> |
Specifies on which days of each week backup jobs are executed. The value can be one or more of the following: SUN, MON, TUE, WED, THU, FRI, SAT |
|
rentention_num |
No |
integer |
Specifies the retained number (minimum: 2) of backups. Select either this parameter or rentention_day. If you select both, this parameter is used. |
|
rentention_day |
No |
integer |
Specifies how many days backups are retained. |
|
remain_first_backup_of_curMonth |
Yes |
string |
Specifies whether to retain the first backup in the current month. The value can be Y or N. |
|
status |
Yes |
string |
Specifies the backup policy status. The value can be ON or OFF. |
Deleting a Backup Policy
You can delete a backup policy using OpenStack4j based on the following code:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
public static void deletePolicy() {
osclient.blockStorage().policies().delete(policyId);
List<? extends VolumeBackupPolicy> policies = osclient.blockStorage().policies().list();
boolean isSuccess = true;
for (VolumeBackupPolicy policy:
policies) {
if (policy.getId().equals(policyId)) {
isSuccess = false;
break;
}
}
Assert.assertEquals(isSuccess, true);
}
|
|
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
|
tenant_id |
Yes |
string |
Specifies the ID of the tenant. |
|
policy_id |
Yes |
string |
Specifies the ID of the policy. |
Querying Backup Policies
You can query backup policies using OpenStack4j based on the following code:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
public static void queryPolicy() {
List<? extends VolumeBackupPolicy> policies = osclient.blockStorage().policies().list();
boolean isSuccess = false;
for (VolumeBackupPolicy policy:
policies) {
if (policy.getName().equals(policyName)) {
isSuccess = true;
policyId = policy.getId();
break;
}
}
Assert.assertEquals(isSuccess, true);
}
|
Last Article: ELB Java SDK Demo
Next Article: CTS Java SDK Demo
Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.