Merge "Add --incremental flag to backup-create"
This commit is contained in:
@@ -0,0 +1,6 @@
|
|||||||
|
features:
|
||||||
|
- The --incremental flag for backup-create will
|
||||||
|
add the abiility 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.
|
@@ -55,7 +55,7 @@ class BackupManagerTest(testtools.TestCase):
|
|||||||
def test_create(self):
|
def test_create(self):
|
||||||
create_mock = mock.Mock()
|
create_mock = mock.Mock()
|
||||||
self.backups._create = create_mock
|
self.backups._create = create_mock
|
||||||
args = {'name': 'test_backup', 'instance': '1'}
|
args = {'name': 'test_backup', 'instance': '1', 'incremental': False}
|
||||||
body = {'backup': args}
|
body = {'backup': args}
|
||||||
self.backups.create(**args)
|
self.backups.create(**args)
|
||||||
create_mock.assert_called_with('/backups', body, 'backup')
|
create_mock.assert_called_with('/backups', body, 'backup')
|
||||||
@@ -63,7 +63,8 @@ class BackupManagerTest(testtools.TestCase):
|
|||||||
def test_create_description(self):
|
def test_create_description(self):
|
||||||
create_mock = mock.Mock()
|
create_mock = mock.Mock()
|
||||||
self.backups._create = create_mock
|
self.backups._create = create_mock
|
||||||
args = {'name': 'test_backup', 'instance': '1', 'description': 'foo'}
|
args = {'name': 'test_backup', 'instance': '1', 'description': 'foo',
|
||||||
|
'incremental': False}
|
||||||
body = {'backup': args}
|
body = {'backup': args}
|
||||||
self.backups.create(**args)
|
self.backups.create(**args)
|
||||||
create_mock.assert_called_with('/backups', body, 'backup')
|
create_mock.assert_called_with('/backups', body, 'backup')
|
||||||
@@ -71,7 +72,8 @@ class BackupManagerTest(testtools.TestCase):
|
|||||||
def test_create_with_instance_obj(self):
|
def test_create_with_instance_obj(self):
|
||||||
create_mock = mock.Mock()
|
create_mock = mock.Mock()
|
||||||
self.backups._create = create_mock
|
self.backups._create = create_mock
|
||||||
args = {'name': 'test_backup', 'instance': self.instance_with_id.id}
|
args = {'name': 'test_backup', 'instance': self.instance_with_id.id,
|
||||||
|
'incremental': False}
|
||||||
body = {'backup': args}
|
body = {'backup': args}
|
||||||
self.backups.create('test_backup', self.instance_with_id)
|
self.backups.create('test_backup', self.instance_with_id)
|
||||||
create_mock.assert_called_with('/backups', body, 'backup')
|
create_mock.assert_called_with('/backups', body, 'backup')
|
||||||
@@ -79,7 +81,16 @@ class BackupManagerTest(testtools.TestCase):
|
|||||||
def test_create_incremental(self):
|
def test_create_incremental(self):
|
||||||
create_mock = mock.Mock()
|
create_mock = mock.Mock()
|
||||||
self.backups._create = create_mock
|
self.backups._create = create_mock
|
||||||
args = {'name': 'test_backup', 'instance': '1', 'parent_id': 'foo'}
|
args = {'name': 'test_backup', 'instance': '1', 'parent_id': 'foo',
|
||||||
|
'incremental': False}
|
||||||
|
body = {'backup': args}
|
||||||
|
self.backups.create(**args)
|
||||||
|
create_mock.assert_called_with('/backups', body, 'backup')
|
||||||
|
|
||||||
|
def test_create_incremental_2(self):
|
||||||
|
create_mock = mock.Mock()
|
||||||
|
self.backups._create = create_mock
|
||||||
|
args = {'name': 'test_backup', 'instance': '1', 'incremental': True}
|
||||||
body = {'backup': args}
|
body = {'backup': args}
|
||||||
self.backups.create(**args)
|
self.backups.create(**args)
|
||||||
create_mock.assert_called_with('/backups', body, 'backup')
|
create_mock.assert_called_with('/backups', body, 'backup')
|
||||||
@@ -88,7 +99,7 @@ class BackupManagerTest(testtools.TestCase):
|
|||||||
create_mock = mock.Mock()
|
create_mock = mock.Mock()
|
||||||
self.backups._create = create_mock
|
self.backups._create = create_mock
|
||||||
args = {'name': 'test_backup', 'instance': 'foo',
|
args = {'name': 'test_backup', 'instance': 'foo',
|
||||||
'backup': '1'}
|
'backup': '1', 'incremental': False}
|
||||||
body = {'backup': args}
|
body = {'backup': args}
|
||||||
self.backups.create(**args)
|
self.backups.create(**args)
|
||||||
create_mock.assert_called_with('/backups', body, 'backup')
|
create_mock.assert_called_with('/backups', body, 'backup')
|
||||||
|
@@ -767,7 +767,8 @@ class ShellTest(utils.TestCase):
|
|||||||
'POST', '/backups',
|
'POST', '/backups',
|
||||||
{'backup': {
|
{'backup': {
|
||||||
'instance': '1234',
|
'instance': '1234',
|
||||||
'name': 'bkp_1'
|
'name': 'bkp_1',
|
||||||
|
'incremental': False
|
||||||
}})
|
}})
|
||||||
|
|
||||||
def test_backup_copy(self):
|
def test_backup_copy(self):
|
||||||
@@ -776,6 +777,7 @@ class ShellTest(utils.TestCase):
|
|||||||
'POST', '/backups',
|
'POST', '/backups',
|
||||||
{'backup': {
|
{'backup': {
|
||||||
'name': 'new_bkp',
|
'name': 'new_bkp',
|
||||||
|
'incremental': False,
|
||||||
'backup': {'region': None, 'id': 'bk-1234'}
|
'backup': {'region': None, 'id': 'bk-1234'}
|
||||||
}})
|
}})
|
||||||
|
|
||||||
|
@@ -51,18 +51,21 @@ class Backups(base.ManagerWithFind):
|
|||||||
query_strings)
|
query_strings)
|
||||||
|
|
||||||
def create(self, name, instance, description=None, parent_id=None,
|
def create(self, name, instance, description=None, parent_id=None,
|
||||||
backup=None,):
|
backup=None, incremental=False):
|
||||||
"""Create a new backup from the given instance.
|
"""Create a new backup from the given instance.
|
||||||
|
|
||||||
:param name: name for backup.
|
:param name: name for backup.
|
||||||
:param instance: instance to backup.
|
:param instance: instance to backup.
|
||||||
:param description: (optional).
|
:param description: (optional).
|
||||||
:param parent_id: base for incremental backup (optional).
|
:param parent_id: base for incremental backup (optional).
|
||||||
|
:param incremental: flag to indicate incremental backup based on
|
||||||
|
last backup
|
||||||
:returns: :class:`Backups`
|
:returns: :class:`Backups`
|
||||||
"""
|
"""
|
||||||
body = {
|
body = {
|
||||||
"backup": {
|
"backup": {
|
||||||
"name": name
|
"name": name,
|
||||||
|
"incremental": int(incremental)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -943,13 +943,18 @@ def do_backup_delete(cs, args):
|
|||||||
@utils.arg('--parent', metavar='<parent>', default=None,
|
@utils.arg('--parent', metavar='<parent>', default=None,
|
||||||
help='Optional ID of the parent backup to perform an'
|
help='Optional ID of the parent backup to perform an'
|
||||||
' incremental backup from.')
|
' incremental backup from.')
|
||||||
|
@utils.arg('--incremental', action='store_true', default=False,
|
||||||
|
help='Create an incremental backup based on the last'
|
||||||
|
' full or incremental backup. It will create a'
|
||||||
|
' full backup if no existing backup found.')
|
||||||
@utils.service_type('database')
|
@utils.service_type('database')
|
||||||
def do_backup_create(cs, args):
|
def do_backup_create(cs, args):
|
||||||
"""Creates a backup of an instance."""
|
"""Creates a backup of an instance."""
|
||||||
instance = _find_instance(cs, args.instance)
|
instance = _find_instance(cs, args.instance)
|
||||||
backup = cs.backups.create(args.name, instance,
|
backup = cs.backups.create(args.name, instance,
|
||||||
description=args.description,
|
description=args.description,
|
||||||
parent_id=args.parent)
|
parent_id=args.parent,
|
||||||
|
incremental=args.incremental)
|
||||||
_print_object(backup)
|
_print_object(backup)
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user