Add --incremental flag to backup-create

Add --incremental flag to backup-create and set the default
value to False. When the flag is passed it will create a
backup based on the last good known full/incremental backup.
If there is no previous backup a full backup will be created.

Change-Id: I6fcd60f6068dfb0145fa64248a2d8b3fdfc1004d
Depends-On: I96498180890b8b1692b1bac3b19988532f6eb077
Partial-Bug: #1607429
This commit is contained in:
Ali Adil 2016-07-28 20:38:48 +00:00 committed by Ali Asgar Adil
parent 4d1bea7429
commit 7cd6ca0c8e
5 changed files with 36 additions and 9 deletions

View File

@ -0,0 +1,6 @@
features:
- The --incremental flag for backup-create will
add the ability to create incremental backup based
on last full or incremental backup. If no full or
incremental backup exists a new full backup will
be created.

View File

@ -48,7 +48,8 @@ class Backup(object):
operation=operation, datastore=instance.datastore.name)
@classmethod
def create(cls, context, instance, name, description=None, parent_id=None):
def create(cls, context, instance, name, description=None,
parent_id=None, incremental=False):
"""
create db record for Backup
:param cls:
@ -56,6 +57,9 @@ class Backup(object):
:param instance:
:param name:
:param description:
:param parent_id:
:param incremental: flag to indicate incremental backup
based on previous backup
:return:
"""
@ -76,6 +80,7 @@ class Backup(object):
ds = instance_model.datastore
ds_version = instance_model.datastore_version
parent = None
last_backup_id = None
if parent_id:
# Look up the parent info or fail early if not found or if
# the user does not have access to the parent.
@ -84,13 +89,22 @@ class Backup(object):
'location': _parent.location,
'checksum': _parent.checksum,
}
elif incremental:
_parent = Backup.get_last_completed(context, instance_id)
if _parent:
parent = {
'location': _parent.location,
'checksum': _parent.checksum
}
last_backup_id = _parent.id
try:
db_info = DBBackup.create(name=name,
description=description,
tenant_id=context.tenant,
state=BackupState.NEW,
instance_id=instance_id,
parent_id=parent_id,
parent_id=parent_id or
last_backup_id,
datastore_version_id=ds_version.id,
deleted=False)
except exception.InvalidModelError as ex:
@ -110,7 +124,6 @@ class Backup(object):
}
api.API(context).create_backup(backup_info, instance_id)
return db_info
return run_with_quotas(context.tenant,
{'backups': 1},
_create_resources)

View File

@ -64,12 +64,13 @@ class BackupController(wsgi.Controller):
name = data['name']
desc = data.get('description')
parent = data.get('parent_id')
incremental = data.get('incremental')
context.notification = notification.DBaaSBackupCreate(context,
request=req)
with StartNotification(context, name=name, instance_id=instance,
description=desc, parent_id=parent):
backup = Backup.create(context, instance, name, desc,
parent_id=parent)
parent_id=parent, incremental=incremental)
return wsgi.Result(views.BackupView(backup).data(), 202)
def delete(self, req, tenant_id, id):

View File

@ -523,7 +523,8 @@ backup = {
"description": non_empty_string,
"instance": uuid,
"name": non_empty_string,
"parent_id": uuid
"parent_id": uuid,
"incremental": boolean_string
}
}
}

View File

@ -107,7 +107,12 @@ class BackupRunner(TestRunner):
return [database.name for database in
self.auth_client.databases.list(instance_id)]
def assert_backup_create(self, name, desc, instance_id, parent_id=None):
def assert_backup_create(self, name, desc, instance_id, parent_id=None,
incremental=False):
if incremental:
result = self.auth_client.backups.create(
name, instance_id, desc, incremental=incremental)
else:
result = self.auth_client.backups.create(
name, instance_id, desc, parent_id=parent_id)
self.assert_equal(name, result.name,
@ -285,7 +290,8 @@ class BackupRunner(TestRunner):
suffix = '_inc_2'
self.backup_inc_2_info = self.assert_backup_create(
self.BACKUP_NAME + suffix, self.BACKUP_DESC + suffix,
self.instance_info.id, parent_id=self.backup_inc_1_info.id)
self.instance_info.id, parent_id=self.backup_inc_1_info.id,
incremental=True)
def run_wait_for_inc_backup_2(self):
self._verify_backup(self.backup_inc_2_info.id)