Added --overwrite parameter for removing all files from restore directory.
Default value --overwrite=False Change-Id: I5c1aea7000c888b966c2b6e57d22744e35fbdfae Closes-bug: #1544713
This commit is contained in:
parent
7c0f5bce69
commit
9efa12fea6
@ -62,7 +62,8 @@ DEFAULT_PARAMS = {
|
||||
'mode': 'fs', 'action': 'backup', 'shadow': '', 'shadow_path': '',
|
||||
'windows_volume': '', 'command': None, 'metadata_out': False,
|
||||
'storage': 'swift', 'ssh_key': '', 'ssh_username': '', 'ssh_host': '',
|
||||
'ssh_port': DEFAULT_SSH_PORT, 'compression': 'gzip'
|
||||
'ssh_port': DEFAULT_SSH_PORT, 'compression': 'gzip',
|
||||
'overwrite': False,
|
||||
}
|
||||
|
||||
|
||||
@ -332,8 +333,11 @@ _COMMON = [
|
||||
dest='config',
|
||||
help="Config file abs path. Option arguments are provided from "
|
||||
"config file. When config file is used any option from "
|
||||
"command line provided take precedence."
|
||||
)
|
||||
"command line provided take precedence."),
|
||||
cfg.BoolOpt('overwrite',
|
||||
dest='overwrite',
|
||||
help='With overwrite removes files from restore path before '
|
||||
'restore.'),
|
||||
]
|
||||
|
||||
|
||||
|
@ -115,12 +115,16 @@ class BackupEngine(object):
|
||||
break
|
||||
time.sleep(1)
|
||||
|
||||
def restore(self, backup, restore_path):
|
||||
def restore(self, backup, restore_path, overwrite):
|
||||
"""
|
||||
:type backup: freezer.storage.Backup
|
||||
"""
|
||||
logging.info("Creation restore path: {0}".format(restore_path))
|
||||
utils.create_dir_tree(restore_path)
|
||||
if not overwrite and not utils.is_empty_dir(restore_path):
|
||||
raise Exception(
|
||||
"Restore dir is not empty. "
|
||||
"Please use --overwrite or provide different path.")
|
||||
logging.info("Creation restore path completed")
|
||||
for level in range(0, backup.level + 1):
|
||||
b = backup.full_backup.increments[level]
|
||||
|
@ -185,7 +185,7 @@ class RestoreJob(Job):
|
||||
backup = self.storage.find_one(conf.hostname_backup_name,
|
||||
restore_timestamp)
|
||||
|
||||
self.engine.restore(backup, restore_abs_path)
|
||||
self.engine.restore(backup, restore_abs_path, conf.overwrite)
|
||||
return {}
|
||||
|
||||
res = restore.RestoreOs(conf.client_manager, conf.container)
|
||||
|
@ -44,6 +44,10 @@ def create_dir_tree(dir):
|
||||
raise exc
|
||||
|
||||
|
||||
def is_empty_dir(path):
|
||||
return not os.listdir(path)
|
||||
|
||||
|
||||
def create_dir(directory, do_log=True):
|
||||
"""
|
||||
Creates a directory if it doesn't exists and write the execution
|
||||
|
Loading…
x
Reference in New Issue
Block a user