Add file/dir check upon backup using tar
When a tar backup is made the freezer client checks whether the parameter to --path-to-backup is a file or a directory and creates the correct tar command Change-Id: I14d2ea141637b7237bae286476dc9dcd068c273a Closes-Bug: #1469206
This commit is contained in:
parent
c3bdcf2548
commit
354a1c6085
|
@ -287,16 +287,24 @@ def backup_mode_fs(backup_opt_dict, time_stamp, manifest_meta_dict):
|
|||
backup_opt_dict.path_to_backup,
|
||||
backup_opt_dict.windows_volume)
|
||||
|
||||
path_to_backup = backup_opt_dict.path_to_backup
|
||||
filepath = '.'
|
||||
chdir_path = os.path.expanduser(
|
||||
os.path.normpath(backup_opt_dict.path_to_backup.strip()))
|
||||
if not os.path.isdir(chdir_path):
|
||||
filepath = os.path.basename(chdir_path)
|
||||
chdir_path = os.path.dirname(chdir_path)
|
||||
os.chdir(chdir_path)
|
||||
|
||||
# Change che current working directory to op_dict.path_to_backup
|
||||
os.chdir(os.path.normpath(path_to_backup.strip()))
|
||||
|
||||
logging.info('[*] Changing current working directory to: {0} \
|
||||
'.format(path_to_backup))
|
||||
logging.info('[*] Backup started for: {0}'.format(path_to_backup))
|
||||
'.format(chdir_path))
|
||||
logging.info('[*] Backup started for: {0}'.format(
|
||||
backup_opt_dict.path_to_backup))
|
||||
|
||||
builder = TarCommandBuilder(backup_opt_dict.tar_path)
|
||||
builder.set_dereference(backup_opt_dict.dereference_symlink)
|
||||
builder.set_filepath(filepath)
|
||||
curr_backup_level = manifest_meta_dict.get(
|
||||
'x-object-meta-backup-current-level', '0')
|
||||
tar_meta = manifest_meta_dict.get('x-object-meta-tar-meta-obj-name')
|
||||
|
|
|
@ -38,6 +38,7 @@ class TarCommandBuilder:
|
|||
def __init__(self, path):
|
||||
self.dereference = ''
|
||||
self.path = path
|
||||
self.filepath = '.'
|
||||
self.level = 0
|
||||
self.exclude = None
|
||||
self.dereference_mode = {
|
||||
|
@ -52,6 +53,9 @@ class TarCommandBuilder:
|
|||
self.openssl_path = None
|
||||
self.encrypt_pass_file = None
|
||||
|
||||
def set_filepath(self, path):
|
||||
self.filepath = path
|
||||
|
||||
def set_level(self, level):
|
||||
self.level = level
|
||||
|
||||
|
@ -105,7 +109,7 @@ class TarCommandBuilder:
|
|||
file=self.encrypt_pass_file)
|
||||
tar_command = '{0} | {1} '.format(tar_command, openssl_cmd)
|
||||
|
||||
return ' {0} . '.format(tar_command)
|
||||
return ' {0} {1} '.format(tar_command, self.filepath)
|
||||
|
||||
|
||||
def tar_restore_args_valid(backup_opt_dict):
|
||||
|
|
|
@ -977,6 +977,10 @@ class Os:
|
|||
def isdir(cls, directory=True):
|
||||
return 'testdir'
|
||||
|
||||
@classmethod
|
||||
def isfile(cls, directory=True):
|
||||
return True
|
||||
|
||||
@classmethod
|
||||
def split(cls, directory=True):
|
||||
return ['/tmp', '']
|
||||
|
|
|
@ -52,6 +52,7 @@ class TestBackUP:
|
|||
monkeypatch.setattr(os.path, 'expanduser', expanduser.expanduser)
|
||||
monkeypatch.setattr(os.path, 'isdir', expanduser.isdir)
|
||||
monkeypatch.setattr(os, 'makedirs', expanduser.makedirs)
|
||||
monkeypatch.setattr(os, 'chdir', expanduser.makedirs)
|
||||
monkeypatch.setattr(os.path, 'exists', expanduser.exists)
|
||||
monkeypatch.setattr(swiftclient, 'client', fakeswiftclient.client)
|
||||
|
||||
|
|
Loading…
Reference in New Issue