diff --git a/libvirtnbdbackup/common.py b/libvirtnbdbackup/common.py index c86c1c6b..ab039060 100644 --- a/libvirtnbdbackup/common.py +++ b/libvirtnbdbackup/common.py @@ -209,6 +209,9 @@ def copy(args: Namespace, source: str, target: str) -> None: if args.sshClient: args.sshClient.copy(source, target) else: + if args.restore_root is not None: + dir, _ = os.path.split(target) + os.makedirs(dir, exist_ok=True) shutil.copyfile(source, target) except OSError as e: log.warning("Failed to copy [%s] to [%s]: [%s]", source, target, e) diff --git a/libvirtnbdbackup/restore/files.py b/libvirtnbdbackup/restore/files.py index 52a19fce..e9edd42b 100644 --- a/libvirtnbdbackup/restore/files.py +++ b/libvirtnbdbackup/restore/files.py @@ -38,6 +38,9 @@ def restore(args: Namespace, vmConfig: str, virtClient: virt.client) -> None: for setting, val in info.items(): f = lib.getLatest(args.input, f"*{os.path.basename(val)}*", -1) + if args.restore_root is not None: + _, _, val_as_relative = os.path.splitroot(val) + val = os.path.join(args.restore_root, val_as_relative) if lib.exists(args, val): logging.info( "File [%s]: for boot option [%s] already exists, skipping.", diff --git a/virtnbdrestore b/virtnbdrestore index 429e691f..dbbfa0ff 100755 --- a/virtnbdrestore +++ b/virtnbdrestore @@ -175,6 +175,13 @@ def main() -> None: action="store_true", help="Preallocate restored qcow images. (default: %(default)s)", ) + opt.add_argument( + "-R", + "--restore-root", + default=None, + type=str, + help="Store restored misc VM files (loader, firmware vars, etc) under alternative root directory (default /)", + ) remopt = parser.add_argument_group("Remote Restore options") argopt.addRemoteArgs(remopt)