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:
parent
4d1bea7429
commit
7cd6ca0c8e
@ -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.
|
@ -48,7 +48,8 @@ class Backup(object):
|
|||||||
operation=operation, datastore=instance.datastore.name)
|
operation=operation, datastore=instance.datastore.name)
|
||||||
|
|
||||||
@classmethod
|
@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
|
create db record for Backup
|
||||||
:param cls:
|
:param cls:
|
||||||
@ -56,6 +57,9 @@ class Backup(object):
|
|||||||
:param instance:
|
:param instance:
|
||||||
:param name:
|
:param name:
|
||||||
:param description:
|
:param description:
|
||||||
|
:param parent_id:
|
||||||
|
:param incremental: flag to indicate incremental backup
|
||||||
|
based on previous backup
|
||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@ -76,6 +80,7 @@ class Backup(object):
|
|||||||
ds = instance_model.datastore
|
ds = instance_model.datastore
|
||||||
ds_version = instance_model.datastore_version
|
ds_version = instance_model.datastore_version
|
||||||
parent = None
|
parent = None
|
||||||
|
last_backup_id = None
|
||||||
if parent_id:
|
if parent_id:
|
||||||
# Look up the parent info or fail early if not found or if
|
# Look up the parent info or fail early if not found or if
|
||||||
# the user does not have access to the parent.
|
# the user does not have access to the parent.
|
||||||
@ -84,13 +89,22 @@ class Backup(object):
|
|||||||
'location': _parent.location,
|
'location': _parent.location,
|
||||||
'checksum': _parent.checksum,
|
'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:
|
try:
|
||||||
db_info = DBBackup.create(name=name,
|
db_info = DBBackup.create(name=name,
|
||||||
description=description,
|
description=description,
|
||||||
tenant_id=context.tenant,
|
tenant_id=context.tenant,
|
||||||
state=BackupState.NEW,
|
state=BackupState.NEW,
|
||||||
instance_id=instance_id,
|
instance_id=instance_id,
|
||||||
parent_id=parent_id,
|
parent_id=parent_id or
|
||||||
|
last_backup_id,
|
||||||
datastore_version_id=ds_version.id,
|
datastore_version_id=ds_version.id,
|
||||||
deleted=False)
|
deleted=False)
|
||||||
except exception.InvalidModelError as ex:
|
except exception.InvalidModelError as ex:
|
||||||
@ -110,7 +124,6 @@ class Backup(object):
|
|||||||
}
|
}
|
||||||
api.API(context).create_backup(backup_info, instance_id)
|
api.API(context).create_backup(backup_info, instance_id)
|
||||||
return db_info
|
return db_info
|
||||||
|
|
||||||
return run_with_quotas(context.tenant,
|
return run_with_quotas(context.tenant,
|
||||||
{'backups': 1},
|
{'backups': 1},
|
||||||
_create_resources)
|
_create_resources)
|
||||||
|
@ -64,12 +64,13 @@ class BackupController(wsgi.Controller):
|
|||||||
name = data['name']
|
name = data['name']
|
||||||
desc = data.get('description')
|
desc = data.get('description')
|
||||||
parent = data.get('parent_id')
|
parent = data.get('parent_id')
|
||||||
|
incremental = data.get('incremental')
|
||||||
context.notification = notification.DBaaSBackupCreate(context,
|
context.notification = notification.DBaaSBackupCreate(context,
|
||||||
request=req)
|
request=req)
|
||||||
with StartNotification(context, name=name, instance_id=instance,
|
with StartNotification(context, name=name, instance_id=instance,
|
||||||
description=desc, parent_id=parent):
|
description=desc, parent_id=parent):
|
||||||
backup = Backup.create(context, instance, name, desc,
|
backup = Backup.create(context, instance, name, desc,
|
||||||
parent_id=parent)
|
parent_id=parent, incremental=incremental)
|
||||||
return wsgi.Result(views.BackupView(backup).data(), 202)
|
return wsgi.Result(views.BackupView(backup).data(), 202)
|
||||||
|
|
||||||
def delete(self, req, tenant_id, id):
|
def delete(self, req, tenant_id, id):
|
||||||
|
@ -523,7 +523,8 @@ backup = {
|
|||||||
"description": non_empty_string,
|
"description": non_empty_string,
|
||||||
"instance": uuid,
|
"instance": uuid,
|
||||||
"name": non_empty_string,
|
"name": non_empty_string,
|
||||||
"parent_id": uuid
|
"parent_id": uuid,
|
||||||
|
"incremental": boolean_string
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -107,7 +107,12 @@ class BackupRunner(TestRunner):
|
|||||||
return [database.name for database in
|
return [database.name for database in
|
||||||
self.auth_client.databases.list(instance_id)]
|
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(
|
result = self.auth_client.backups.create(
|
||||||
name, instance_id, desc, parent_id=parent_id)
|
name, instance_id, desc, parent_id=parent_id)
|
||||||
self.assert_equal(name, result.name,
|
self.assert_equal(name, result.name,
|
||||||
@ -285,7 +290,8 @@ class BackupRunner(TestRunner):
|
|||||||
suffix = '_inc_2'
|
suffix = '_inc_2'
|
||||||
self.backup_inc_2_info = self.assert_backup_create(
|
self.backup_inc_2_info = self.assert_backup_create(
|
||||||
self.BACKUP_NAME + suffix, self.BACKUP_DESC + suffix,
|
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):
|
def run_wait_for_inc_backup_2(self):
|
||||||
self._verify_backup(self.backup_inc_2_info.id)
|
self._verify_backup(self.backup_inc_2_info.id)
|
||||||
|
Loading…
Reference in New Issue
Block a user