Skip to content

Commit

Permalink
add --restore-root option to specify target for misc vm files
Browse files Browse the repository at this point in the history
Provide a flag to specify where misc files (NVRAM vars, loader, etc) restored from the backup should be placed.
  • Loading branch information
richardstephens committed Sep 17, 2024
1 parent c0e7a4c commit 88a63af
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
3 changes: 3 additions & 0 deletions libvirtnbdbackup/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions libvirtnbdbackup/restore/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
7 changes: 7 additions & 0 deletions virtnbdrestore
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 88a63af

Please sign in to comment.