From 3ee941c1e6e497f6ac0ad7919c5c0703f5cb3607 Mon Sep 17 00:00:00 2001 From: Xing Yang Date: Mon, 16 Feb 2015 18:04:13 -0500 Subject: [PATCH] Add support to incremental backups in cinder Added a new option to "cinder backup-create" to support incremental backups. Specify --incremental to create an incremental backup. By default, it will be a full backup. Co-Authored-By: Xing Yang Implements: blueprint incremental-backup Change-Id: Id11ecd2982ea838181b4adaa5a742fc65f864acb --- cinderclient/tests/unit/v2/test_shell.py | 4 ++++ cinderclient/tests/unit/v2/test_volume_backups.py | 10 ++++++++++ cinderclient/v2/shell.py | 7 ++++++- cinderclient/v2/volume_backups.py | 7 +++++-- 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/cinderclient/tests/unit/v2/test_shell.py b/cinderclient/tests/unit/v2/test_shell.py index 10a8f5339..be41bcd98 100644 --- a/cinderclient/tests/unit/v2/test_shell.py +++ b/cinderclient/tests/unit/v2/test_shell.py @@ -324,6 +324,10 @@ class ShellTest(utils.TestCase): self.run_command('backup-create 1234') self.assert_called('POST', '/backups') + def test_backup_incremental(self): + self.run_command('backup-create 1234 --incremental') + self.assert_called('POST', '/backups') + def test_restore(self): self.run_command('backup-restore 1234') self.assert_called('POST', '/backups/1234/restore') diff --git a/cinderclient/tests/unit/v2/test_volume_backups.py b/cinderclient/tests/unit/v2/test_volume_backups.py index 106b828ec..1b77b9ca8 100644 --- a/cinderclient/tests/unit/v2/test_volume_backups.py +++ b/cinderclient/tests/unit/v2/test_volume_backups.py @@ -26,6 +26,16 @@ class VolumeBackupsTest(utils.TestCase): cs.backups.create('2b695faf-b963-40c8-8464-274008fbcef4') cs.assert_called('POST', '/backups') + def test_create_full(self): + cs.backups.create('2b695faf-b963-40c8-8464-274008fbcef4', + None, None, False) + cs.assert_called('POST', '/backups') + + def test_create_incremental(self): + cs.backups.create('2b695faf-b963-40c8-8464-274008fbcef4', + None, None, True) + cs.assert_called('POST', '/backups') + def test_get(self): backup_id = '76a17945-3c6f-435c-975b-b5685db10b62' cs.backups.get(backup_id) diff --git a/cinderclient/v2/shell.py b/cinderclient/v2/shell.py index 47811fa0a..bc427d629 100644 --- a/cinderclient/v2/shell.py +++ b/cinderclient/v2/shell.py @@ -1142,6 +1142,10 @@ def do_retype(cs, args): metavar='', default=None, help='Backup description. Default=None.') +@utils.arg('--incremental', + action='store_true', + help='Incremental backup. Default=False.', + default=False) @utils.service_type('volumev2') def do_backup_create(cs, args): """Creates a volume backup.""" @@ -1155,7 +1159,8 @@ def do_backup_create(cs, args): backup = cs.backups.create(volume.id, args.container, args.name, - args.description) + args.description, + args.incremental) info = {"volume_id": volume.id} info.update(backup._info) diff --git a/cinderclient/v2/volume_backups.py b/cinderclient/v2/volume_backups.py index a948b5ee0..faee6b177 100644 --- a/cinderclient/v2/volume_backups.py +++ b/cinderclient/v2/volume_backups.py @@ -35,19 +35,22 @@ class VolumeBackupManager(base.ManagerWithFind): resource_class = VolumeBackup def create(self, volume_id, container=None, - name=None, description=None): + name=None, description=None, + incremental=False): """Creates a volume backup. :param volume_id: The ID of the volume to backup. :param container: The name of the backup service container. :param name: The name of the backup. :param description: The description of the backup. + :param incremental: Incremental backup. :rtype: :class:`VolumeBackup` """ body = {'backup': {'volume_id': volume_id, 'container': container, 'name': name, - 'description': description}} + 'description': description, + 'incremental': incremental}} return self._create('/backups', body, 'backup') def get(self, backup_id):