Remove auto_snap
Change-Id: I6dd80297d82ee96ef26b4717017157d49047ec11
This commit is contained in:
parent
8fd790837c
commit
04de1570f7
|
@ -40,7 +40,7 @@ DEFAULT_SSH_PORT = 22
|
|||
|
||||
DEFAULT_PARAMS = {
|
||||
'os_identity_api_version': None,
|
||||
'lvm_auto_snap': False, 'lvm_volgroup': False,
|
||||
'lvm_auto_snap': None, 'lvm_volgroup': False,
|
||||
'exclude': False, 'sql_server_conf': False,
|
||||
'backup_name': False, 'quiet': False,
|
||||
'container': 'freezer_backups', 'no_incremental': False,
|
||||
|
@ -109,7 +109,8 @@ _COMMON = [
|
|||
"will invoke vssadmin"),
|
||||
cfg.StrOpt('lvm-auto-snap',
|
||||
dest='lvm_auto_snap',
|
||||
help="Automatically guess the volume group and volume name for "
|
||||
help="(Deprecated) Please use --snapshot instead"
|
||||
"Automatically guess the volume group and volume name for "
|
||||
"given PATH."),
|
||||
cfg.StrOpt('lvm-srcvol',
|
||||
dest='lvm_srcvol',
|
||||
|
@ -467,6 +468,10 @@ def get_backup_args():
|
|||
backup_args.path_to_backup[:3]
|
||||
|
||||
# todo(enugaev) move it to new command line param backup_media
|
||||
|
||||
if backup_args.lvm_auto_snap:
|
||||
raise Exception('lvm-auto-snap is deprecated. '
|
||||
'Please use --snapshot instead')
|
||||
backup_media = 'fs'
|
||||
if backup_args.cinder_vol_id:
|
||||
backup_media = 'cinder'
|
||||
|
|
|
@ -92,10 +92,8 @@ class BackupJob(Job):
|
|||
|
||||
metadata = {
|
||||
'curr_backup_level': level,
|
||||
'fs_real_path': (self.conf.lvm_auto_snap or
|
||||
self.conf.path_to_backup),
|
||||
'vol_snap_path':
|
||||
self.conf.path_to_backup if self.conf.lvm_auto_snap else '',
|
||||
'fs_real_path': self.conf.path_to_backup,
|
||||
'vol_snap_path': self.conf.path_to_backup,
|
||||
'client_os': sys.platform,
|
||||
'client_version': self.conf.__version__,
|
||||
'time_stamp': self.conf.time_stamp
|
||||
|
|
|
@ -185,6 +185,7 @@ def storage_from_dict(backup_args, work_dir, max_segment_size,
|
|||
|
||||
def main():
|
||||
"""freezer-agent/freezerc binary main execution"""
|
||||
backup_args = None
|
||||
try:
|
||||
freezer_config.config()
|
||||
freezer_config.setup_logging()
|
||||
|
@ -194,7 +195,8 @@ def main():
|
|||
sys.exit(1)
|
||||
freezer_main(backup_args)
|
||||
except Exception as err:
|
||||
return fail(1, err, backup_args.quiet)
|
||||
quiet = backup_args.quiet if backup_args else False
|
||||
return fail(1, err, quiet)
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
|
|
|
@ -82,63 +82,35 @@ def lvm_snap(backup_opt_dict):
|
|||
Checks the provided parameters and create the lvm snapshot if requested
|
||||
|
||||
The path_to_backup might be adjusted in case the user requested
|
||||
a lvm snapshot without specifying an exact path for the snapshot
|
||||
(lvm_auto_snap).
|
||||
a lvm snapshot without specifying an exact path for the snapshot).
|
||||
The assumption in this case is that the user wants to use the lvm snapshot
|
||||
capability to backup the specified filesystem path, leaving out all
|
||||
the rest of the parameters which will guessed and set by freezer.
|
||||
|
||||
if a snapshot is requested using the --snapshot flag, but lvm_auto_snap
|
||||
is not provided, then path_to_backup is supposed to be the path to backup
|
||||
*before* any information about the snapshot is added and will be
|
||||
adjusted.
|
||||
|
||||
:param backup_opt_dict: the configuration dict
|
||||
:return: True if the snapshot has been taken, False otherwise
|
||||
"""
|
||||
if backup_opt_dict.snapshot:
|
||||
if not backup_opt_dict.lvm_auto_snap:
|
||||
# 1) the provided path_to_backup has the meaning of
|
||||
# the lvm_auto_snap and is therefore copied into it
|
||||
# 2) the correct value of path_to_backup, which takes into
|
||||
# consideration the snapshot mount-point, is cleared
|
||||
# and will be calculated by freezer
|
||||
backup_opt_dict.lvm_auto_snap =\
|
||||
backup_opt_dict.path_to_backup
|
||||
backup_opt_dict.path_to_backup = ''
|
||||
|
||||
if not backup_opt_dict.lvm_snapname:
|
||||
backup_opt_dict.lvm_snapname = \
|
||||
"{0}_{1}".format(freezer_config.DEFAULT_LVM_SNAP_BASENAME,
|
||||
uuid.uuid4().hex)
|
||||
|
||||
if backup_opt_dict.lvm_auto_snap:
|
||||
# adjust/check lvm parameters according to provided lvm_auto_snap
|
||||
lvm_info = get_lvm_info(backup_opt_dict.lvm_auto_snap)
|
||||
# adjust/check lvm parameters according to provided path_to_backup
|
||||
lvm_info = get_lvm_info(backup_opt_dict.path_to_backup)
|
||||
|
||||
if not backup_opt_dict.lvm_volgroup:
|
||||
backup_opt_dict.lvm_volgroup = lvm_info['volgroup']
|
||||
if not backup_opt_dict.lvm_volgroup:
|
||||
backup_opt_dict.lvm_volgroup = lvm_info['volgroup']
|
||||
|
||||
if not backup_opt_dict.lvm_srcvol:
|
||||
backup_opt_dict.lvm_srcvol = lvm_info['srcvol']
|
||||
if not backup_opt_dict.lvm_srcvol:
|
||||
backup_opt_dict.lvm_srcvol = lvm_info['srcvol']
|
||||
|
||||
if not backup_opt_dict.lvm_dirmount:
|
||||
backup_opt_dict.lvm_dirmount = \
|
||||
"{0}_{1}".format(freezer_config.DEFAULT_LVM_MOUNT_BASENAME,
|
||||
uuid.uuid4().hex)
|
||||
if not backup_opt_dict.lvm_dirmount:
|
||||
backup_opt_dict.lvm_dirmount = \
|
||||
"{0}_{1}".format(freezer_config.DEFAULT_LVM_MOUNT_BASENAME,
|
||||
uuid.uuid4().hex)
|
||||
|
||||
path_to_backup = os.path.join(backup_opt_dict.lvm_dirmount,
|
||||
lvm_info['snap_path'])
|
||||
if backup_opt_dict.path_to_backup:
|
||||
# path_to_backup is user-provided, check if consistent
|
||||
if backup_opt_dict.path_to_backup != path_to_backup:
|
||||
raise Exception('Path to backup mismatch. '
|
||||
'provided: {0}, should be LVM-mounted: {1}'.
|
||||
format(backup_opt_dict.path_to_backup,
|
||||
path_to_backup))
|
||||
else:
|
||||
# path_to_backup not provided: use the one calculated above
|
||||
backup_opt_dict.path_to_backup = path_to_backup
|
||||
backup_opt_dict.path_to_backup = os.path.join(backup_opt_dict.lvm_dirmount,
|
||||
lvm_info['snap_path'])
|
||||
|
||||
if not validate_lvm_params(backup_opt_dict):
|
||||
logging.info('[*] No LVM requested/configured')
|
||||
|
@ -211,18 +183,18 @@ def lvm_snap(backup_opt_dict):
|
|||
return True
|
||||
|
||||
|
||||
def get_lvm_info(lvm_auto_snap):
|
||||
def get_lvm_info(path):
|
||||
"""
|
||||
Take a file system path as argument as backup_opt_dict.path_to_backup
|
||||
and return a list containing lvm_srcvol, lvm_volgroup
|
||||
where the path is mounted on.
|
||||
|
||||
:param lvm_auto_snap: the original file system path where backup needs
|
||||
:param path: the original file system path where backup needs
|
||||
to be executed
|
||||
:returns: a dict containing the keys 'volgroup', 'srcvol' and 'snap_path'
|
||||
"""
|
||||
|
||||
mount_point_path, snap_path = utils.get_mount_from_path(lvm_auto_snap)
|
||||
mount_point_path, snap_path = utils.get_mount_from_path(path)
|
||||
|
||||
with open('/proc/mounts', 'r') as mount_fd:
|
||||
mount_points = mount_fd.readlines()
|
||||
|
|
|
@ -37,6 +37,8 @@ def snapshot_create(backup_opt_dict):
|
|||
:param backup_opt_dict:
|
||||
:return: boolean value, True if snapshot has been taken, false otherwise
|
||||
"""
|
||||
if not backup_opt_dict.snapshot:
|
||||
return False
|
||||
|
||||
if winutils.is_windows():
|
||||
if backup_opt_dict.snapshot:
|
||||
|
|
|
@ -121,96 +121,21 @@ class TestBackupFSLocalstorage(common.TestFS):
|
|||
self.assertTreesMatch()
|
||||
|
||||
@unittest.skipIf(not common.TestFS.use_lvm, "No LVM support")
|
||||
def test_backup_local_storage_lvm_raises_path_mismatch(self):
|
||||
|
||||
def test_backup_local_storage_use_lvm_snapshot_and_path_to_backup(self):
|
||||
self.source_tree.add_random_data()
|
||||
self.assertTreesMatchNot()
|
||||
|
||||
backup_name = uuid.uuid4().hex
|
||||
lvm_auto_snap= self.source_tree.path
|
||||
lvm_snapsize= '1G'
|
||||
path_to_backup= self.source_tree.path
|
||||
lvm_snapsize= '50M'
|
||||
lvm_snapname= 'freezer-snap_{0}'.format(backup_name)
|
||||
lvm_dirmount = '/var/freezer/freezer-{0}'.format(backup_name)
|
||||
path_to_backup = os.path.join(lvm_dirmount, self.source_tree.path)
|
||||
|
||||
with common.Temp_Tree() as storage_dir:
|
||||
backup_args = {
|
||||
'action': 'backup',
|
||||
'mode': 'fs',
|
||||
'path_to_backup': path_to_backup,
|
||||
'lvm_auto_snap': lvm_auto_snap,
|
||||
'lvm_dirmount': lvm_dirmount,
|
||||
'lvm_snapsize': lvm_snapsize,
|
||||
'lvm_snapname': lvm_snapname,
|
||||
'container': storage_dir.path,
|
||||
'storage': 'local',
|
||||
'max_level': '6',
|
||||
'max_segment_size': '67108864',
|
||||
'backup_name': backup_name
|
||||
}
|
||||
|
||||
result = common.execute_freezerc(
|
||||
backup_args, must_fail=True, merge_stderr=True)
|
||||
self.assertIn('Path to backup mismatch', result)
|
||||
|
||||
@unittest.skipIf(not common.TestFS.use_lvm, "No LVM support")
|
||||
def test_backup_local_storage_lvm_with_auto_snap(self):
|
||||
|
||||
self.source_tree.add_random_data()
|
||||
self.assertTreesMatchNot()
|
||||
|
||||
backup_name = uuid.uuid4().hex
|
||||
lvm_auto_snap= self.source_tree.path
|
||||
lvm_snapsize= '1G'
|
||||
lvm_snapname= 'freezer-snap_{0}'.format(backup_name)
|
||||
lvm_dirmount = '/var/freezer/freezer-{0}'.format(backup_name)
|
||||
path_to_backup = os.path.join(lvm_dirmount, self.source_tree.path)
|
||||
|
||||
with common.Temp_Tree() as storage_dir:
|
||||
backup_args = {
|
||||
'action': 'backup',
|
||||
'mode': 'fs',
|
||||
'lvm_auto_snap': lvm_auto_snap,
|
||||
'lvm_dirmount': lvm_dirmount,
|
||||
'lvm_snapsize': lvm_snapsize,
|
||||
'lvm_snapname': lvm_snapname,
|
||||
'container': storage_dir.path,
|
||||
'storage': 'local',
|
||||
'max_level': '6',
|
||||
'max_segment_size': '67108864',
|
||||
'backup_name': backup_name
|
||||
}
|
||||
restore_args = {
|
||||
'action': 'restore',
|
||||
'restore_abs_path': self.dest_tree.path,
|
||||
'backup_name': copy(backup_args['backup_name']),
|
||||
'storage': 'local',
|
||||
'container': storage_dir.path
|
||||
}
|
||||
|
||||
result = common.execute_freezerc(backup_args)
|
||||
self.assertIsNotNone(result)
|
||||
result = common.execute_freezerc(restore_args)
|
||||
self.assertIsNotNone(result)
|
||||
self.assertTreesMatch()
|
||||
|
||||
@unittest.skipIf(not common.TestFS.use_lvm, "No LVM support")
|
||||
def test_backup_local_storage_use_lvm_snapshot_and_path_to_backup(self):
|
||||
self.source_tree.add_random_data()
|
||||
self.assertTreesMatchNot()
|
||||
|
||||
backup_name = uuid.uuid4().hex
|
||||
lvm_auto_snap= self.source_tree.path
|
||||
lvm_snapsize= '50M'
|
||||
lvm_snapname= 'freezer-snap_{0}'.format(backup_name)
|
||||
lvm_dirmount = '/var/freezer/freezer-{0}'.format(backup_name)
|
||||
path_to_backup = os.path.join(lvm_dirmount, self.source_tree.path)
|
||||
|
||||
with common.Temp_Tree() as storage_dir:
|
||||
backup_args = {
|
||||
'action': 'backup',
|
||||
'mode': 'fs',
|
||||
'path_to_backup': lvm_auto_snap,
|
||||
'snapshot': '',
|
||||
'lvm_dirmount': lvm_dirmount,
|
||||
'lvm_snapsize': lvm_snapsize,
|
||||
|
@ -369,17 +294,15 @@ class TestBackupSSH(common.TestFS):
|
|||
self.assertTreesMatchNot()
|
||||
|
||||
backup_name = uuid.uuid4().hex
|
||||
lvm_auto_snap= self.source_tree.path
|
||||
path_to_backup= self.source_tree.path
|
||||
lvm_snapsize= '1G'
|
||||
lvm_snapname= 'freezer-snap_{0}'.format(backup_name)
|
||||
lvm_dirmount = '/var/freezer/freezer-{0}'.format(backup_name)
|
||||
path_to_backup = os.path.join(lvm_dirmount, os.path.relpath(self.source_tree.path, '/'))
|
||||
|
||||
backup_args = {
|
||||
'action': 'backup',
|
||||
'mode': 'fs',
|
||||
'path_to_backup': path_to_backup,
|
||||
'lvm_auto_snap': lvm_auto_snap,
|
||||
'lvm_dirmount': lvm_dirmount,
|
||||
'lvm_snapsize': lvm_snapsize,
|
||||
'lvm_snapname': lvm_snapname,
|
||||
|
@ -575,7 +498,6 @@ class TestBackupUsingSwiftStorage(common.TestFS):
|
|||
self.source_tree = common.Temp_Tree(dir='/var/lib/mysql', create=False)
|
||||
|
||||
backup_name = uuid.uuid4().hex
|
||||
lvm_auto_snap = self.source_tree.path
|
||||
lvm_snapsize = '1G'
|
||||
lvm_snapname = 'freezer-snap_{0}'.format(backup_name)
|
||||
lvm_dirmount = '/var/freezer/freezer-{0}'.format(backup_name)
|
||||
|
|
|
@ -35,31 +35,6 @@ class Test_lvm_snap_remove(unittest.TestCase):
|
|||
|
||||
class Test_lvm_snap(unittest.TestCase):
|
||||
|
||||
@patch('freezer.snapshot.lvm.validate_lvm_params')
|
||||
def test_no_lvm_configured_returns_false(self, mock_validate_lvm_params):
|
||||
backup_opt = Mock()
|
||||
backup_opt.lvm_auto_snap = ''
|
||||
mock_validate_lvm_params.return_value = False
|
||||
backup_opt.snapshot = False
|
||||
self.assertFalse(lvm.lvm_snap(backup_opt))
|
||||
|
||||
@patch('freezer.snapshot.lvm.validate_lvm_params')
|
||||
@patch('freezer.snapshot.lvm.get_lvm_info')
|
||||
@patch('freezer.snapshot.lvm.utils.create_dir')
|
||||
def test_with_auto_snap_param_path_mismatch_raises(self, mock_create_dir, mock_get_lvm_info, mock_validate_lvm_params):
|
||||
mock_get_lvm_info.return_value = {
|
||||
'volgroup': 'lvm_volgroup',
|
||||
'srcvol': 'lvm_device',
|
||||
'snap_path': 'snap_path'}
|
||||
|
||||
backup_opt = Mock()
|
||||
backup_opt.snapshot = False
|
||||
backup_opt.lvm_auto_snap = '/just/a/path'
|
||||
backup_opt.path_to_backup = '/different'
|
||||
backup_opt.lvm_dirmount = '/var/mountpoint'
|
||||
|
||||
self.assertRaises(Exception, lvm.lvm_snap, backup_opt)
|
||||
|
||||
@patch('freezer.snapshot.lvm.get_lvm_info')
|
||||
@patch('freezer.snapshot.lvm.utils.create_dir')
|
||||
def test_with_snapshot_opt_simple_sets_correct_path_and_raises_on_perm(self, mock_create_dir, mock_get_lvm_info):
|
||||
|
@ -70,7 +45,6 @@ class Test_lvm_snap(unittest.TestCase):
|
|||
|
||||
backup_opt = Mock()
|
||||
backup_opt.snapshot = True
|
||||
backup_opt.lvm_auto_snap = ''
|
||||
backup_opt.path_to_backup = '/just/a/path'
|
||||
backup_opt.lvm_dirmount = '/var/mountpoint'
|
||||
backup_opt.lvm_snapperm = 'invalid_value'
|
||||
|
@ -98,7 +72,6 @@ class Test_lvm_snap(unittest.TestCase):
|
|||
|
||||
backup_opt = Mock()
|
||||
backup_opt.snapshot = True
|
||||
backup_opt.lvm_auto_snap = ''
|
||||
backup_opt.path_to_backup = '/just/a/path'
|
||||
backup_opt.lvm_dirmount = '/var/mountpoint'
|
||||
backup_opt.lvm_snapperm = 'ro'
|
||||
|
@ -125,7 +98,6 @@ class Test_lvm_snap(unittest.TestCase):
|
|||
|
||||
backup_opt = Mock()
|
||||
backup_opt.snapshot = True
|
||||
backup_opt.lvm_auto_snap = ''
|
||||
backup_opt.path_to_backup = '/just/a/path'
|
||||
backup_opt.lvm_dirmount = '/var/mountpoint'
|
||||
backup_opt.lvm_snapperm = 'ro'
|
||||
|
@ -156,7 +128,6 @@ class Test_lvm_snap(unittest.TestCase):
|
|||
|
||||
backup_opt = Mock()
|
||||
backup_opt.snapshot = True
|
||||
backup_opt.lvm_auto_snap = ''
|
||||
backup_opt.path_to_backup = '/just/a/path'
|
||||
backup_opt.lvm_dirmount = '/var/mountpoint'
|
||||
backup_opt.lvm_snapperm = 'ro'
|
||||
|
@ -192,7 +163,6 @@ class Test_lvm_snap(unittest.TestCase):
|
|||
|
||||
backup_opt = Mock()
|
||||
backup_opt.snapshot = True
|
||||
backup_opt.lvm_auto_snap = ''
|
||||
backup_opt.path_to_backup = '/just/a/path'
|
||||
backup_opt.lvm_dirmount = '/var/mountpoint'
|
||||
backup_opt.lvm_snapperm = 'ro'
|
||||
|
|
Loading…
Reference in New Issue