From 7cd6ca0c8eb0352c1588637e7ac47fb7882414e6 Mon Sep 17 00:00:00 2001 From: Ali Adil Date: Thu, 28 Jul 2016 20:38:48 +0000 Subject: [PATCH] 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 --- .../incremental_backup-1910ded0fc3474a3.yaml | 6 ++++++ trove/backup/models.py | 19 ++++++++++++++++--- trove/backup/service.py | 3 ++- trove/common/apischema.py | 3 ++- .../tests/scenario/runners/backup_runners.py | 14 ++++++++++---- 5 files changed, 36 insertions(+), 9 deletions(-) create mode 100644 releasenotes/notes/incremental_backup-1910ded0fc3474a3.yaml diff --git a/releasenotes/notes/incremental_backup-1910ded0fc3474a3.yaml b/releasenotes/notes/incremental_backup-1910ded0fc3474a3.yaml new file mode 100644 index 0000000000..7e93107a87 --- /dev/null +++ b/releasenotes/notes/incremental_backup-1910ded0fc3474a3.yaml @@ -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. diff --git a/trove/backup/models.py b/trove/backup/models.py index 3a248bfb41..49878f9c5a 100644 --- a/trove/backup/models.py +++ b/trove/backup/models.py @@ -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) diff --git a/trove/backup/service.py b/trove/backup/service.py index 6ebe8c956c..56a60c7146 100644 --- a/trove/backup/service.py +++ b/trove/backup/service.py @@ -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): diff --git a/trove/common/apischema.py b/trove/common/apischema.py index 8eaa90df03..1e929d03d8 100644 --- a/trove/common/apischema.py +++ b/trove/common/apischema.py @@ -523,7 +523,8 @@ backup = { "description": non_empty_string, "instance": uuid, "name": non_empty_string, - "parent_id": uuid + "parent_id": uuid, + "incremental": boolean_string } } } diff --git a/trove/tests/scenario/runners/backup_runners.py b/trove/tests/scenario/runners/backup_runners.py index c5c45d9869..3833806c7d 100644 --- a/trove/tests/scenario/runners/backup_runners.py +++ b/trove/tests/scenario/runners/backup_runners.py @@ -107,9 +107,14 @@ 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): - result = self.auth_client.backups.create( - name, instance_id, desc, parent_id=parent_id) + 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, 'Unexpected backup name') self.assert_equal(desc, result.description, @@ -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)