VBS Python SDK Demo
Creating a VBS Backup
You can create a VBS backup using the Python OpenStack SDK based on the following code. After the VBS backup is created, it will be displayed in the VBS list on the VBS console.
1 2 3 4 5 6 7 8 9 10 |
def create_backup(self):
backup = {
"volume_id": self.volume.id,
"name": "sds",
"description": "created by openstacksdk"
}
result = self.conn.volume_backup.create_backup(**backup)
# assert result.job_id != None
self.job_id = result.id
|
|
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 the Python OpenStack SDK based on the following code:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
def query_backups_detail(self):
backups = self.conn.volume_backup.backups(details=True)
query = {
"name": "volume-backup-" + self.volume.id,
# "status": "available",
"volume_id": self.volume.id,
# "marker": "some-backup-id",
"limit": 10
}
backups = self.conn.volume_backup.backups(details=True, **query)
for backup in backups:
print backup.name
|
|
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 the Python OpenStack SDK based on the following code:
1 2 3 |
def restore_backup(self):
self.query_backups()
return self.conn.volume_backup.restore_backup(self.backup_id, self.volume.id)
|
|
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 the Python OpenStack SDK based on the following code:
1 2 3 |
def delete_backup(self):
self.query_backups()
self.conn.volume_backup.delete_backup(self.backup_id)
|
|
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 the Python OpenStack SDK based on the following code:
1 2 3 4 5 6 7 8 9 10 11 |
def create_policy(self):
data = {
"remain_first_backup_of_curMonth": True,
"rentention_num": 10,
"frequency": 1,
"start_time": "12:00",
"status": "ON"
}
volume_backup_name = "SDK-backup-test-1"
policy = self.conn.volume_backup.create_backup_policy(volume_backup_name, **data)
print policy
|
|
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 the Python OpenStack SDK based on the following code:
1 2 3 |
def delete_policy(self):
policy_id = self.query_policies().id
self.conn.volume_backup.delete_backup_policy(policy_id)
|
|
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 the Python OpenStack SDK based on the following code:
1 2 3 4 |
def query_policies(self):
policies = list(self.conn.volume_backup.backup_policies())
if policies and len(policies) > 0:
return policies[0]
|
Last Article: ELB Python SDK Demo
Next Article: KMS Python SDK Demo
Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.