diff --git a/cinder/backup/drivers/posix.py b/cinder/backup/drivers/posix.py index b7f151b25..d6accc035 100644 --- a/cinder/backup/drivers/posix.py +++ b/cinder/backup/drivers/posix.py @@ -23,6 +23,7 @@ import stat from oslo_config import cfg from oslo_log import log as logging +from oslo_utils import timeutils from cinder.backup import chunkeddriver from cinder import exception @@ -129,7 +130,11 @@ class PosixBackupDriver(chunkeddriver.ChunkedBackupDriver): os.remove(path) def _generate_object_name_prefix(self, backup): - return 'backup' + timestamp = timeutils.utcnow().strftime("%Y%m%d%H%M%S") + prefix = 'volume_%s_%s_backup_%s' % (backup.volume_id, timestamp, + backup.id) + LOG.debug('_generate_object_name_prefix: %s', prefix) + return prefix def get_extra_metadata(self, backup, volume): return None diff --git a/cinder/tests/unit/backup/drivers/test_backup_posix.py b/cinder/tests/unit/backup/drivers/test_backup_posix.py index 1b86bad4f..ff3a21dd7 100644 --- a/cinder/tests/unit/backup/drivers/test_backup_posix.py +++ b/cinder/tests/unit/backup/drivers/test_backup_posix.py @@ -24,6 +24,7 @@ from six.moves import builtins from cinder.backup.drivers import posix from cinder import context +from cinder import objects from cinder import test from cinder.tests.unit import fake_constants as fake @@ -180,3 +181,15 @@ class PosixBackupDriverTestCase(test.TestCase): self.assertRaises(OSError, self.driver.delete_object, FAKE_CONTAINER, FAKE_OBJECT_NAME) + + @mock.patch.object(posix.timeutils, 'utcnow') + def test_generate_object_name_prefix(self, utcnow_mock): + timestamp = '20170518102205' + utcnow_mock.return_value.strftime.return_value = timestamp + backup = objects.Backup(self.ctxt, volume_id=fake.VOLUME_ID, + id=fake.BACKUP_ID) + res = self.driver._generate_object_name_prefix(backup) + expected = 'volume_%s_%s_backup_%s' % (backup.volume_id, + timestamp, + backup.id) + self.assertEqual(expected, res) diff --git a/releasenotes/notes/nfs_backup_no_overwrite-be7b545453baf7a3.yaml b/releasenotes/notes/nfs_backup_no_overwrite-be7b545453baf7a3.yaml new file mode 100644 index 000000000..73227a65c --- /dev/null +++ b/releasenotes/notes/nfs_backup_no_overwrite-be7b545453baf7a3.yaml @@ -0,0 +1,5 @@ +--- +fixes: + - | + Fix NFS backup driver, we now support multiple backups on the same + container, they are no longer overwritten.