Fix dom0 restore
This commit is contained in:
parent
60bfd63a25
commit
30dd7acaa9
@ -564,6 +564,10 @@ class ExtractWorker3(Process):
|
|||||||
else:
|
else:
|
||||||
# ignore this directory
|
# ignore this directory
|
||||||
tar2_cmdline = None
|
tar2_cmdline = None
|
||||||
|
elif os.path.dirname(inner_name) == "dom0-home":
|
||||||
|
tar2_cmdline = ['cat']
|
||||||
|
redirect_stdout = subprocess.PIPE
|
||||||
|
|
||||||
elif inner_name in self.handlers:
|
elif inner_name in self.handlers:
|
||||||
tar2_cmdline = ['tar',
|
tar2_cmdline = ['tar',
|
||||||
'-%svvO' % ("t" if self.verify_only else "x"),
|
'-%svvO' % ("t" if self.verify_only else "x"),
|
||||||
@ -578,14 +582,18 @@ class ExtractWorker3(Process):
|
|||||||
os.remove(filename)
|
os.remove(filename)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
tar_compress_cmd = None
|
||||||
if self.compressed:
|
if self.compressed:
|
||||||
if self.compression_filter:
|
if self.compression_filter:
|
||||||
tar2_cmdline.insert(-1,
|
tar_compress_cmd = self.compression_filter
|
||||||
"--use-compress-program=%s" %
|
else:
|
||||||
self.compression_filter)
|
tar_compress_cmd = DEFAULT_COMPRESSION_FILTER
|
||||||
|
if os.path.dirname(inner_name) == "dom0-home":
|
||||||
|
# Replaces 'cat' for compressed dom0-home!
|
||||||
|
tar2_cmdline = [tar_compress_cmd, "-d"]
|
||||||
else:
|
else:
|
||||||
tar2_cmdline.insert(-1, "--use-compress-program=%s " %
|
tar2_cmdline.insert(-1, "--use-compress-program=%s " %
|
||||||
DEFAULT_COMPRESSION_FILTER)
|
tar_compress_cmd)
|
||||||
|
|
||||||
self.log.debug("Running command %s", str(tar2_cmdline))
|
self.log.debug("Running command %s", str(tar2_cmdline))
|
||||||
if self.encrypted:
|
if self.encrypted:
|
||||||
@ -647,7 +655,7 @@ class ExtractWorker3(Process):
|
|||||||
os.remove(filename)
|
os.remove(filename)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
self.log.debug("Releasing next chunck")
|
self.log.debug("Releasing next chunk")
|
||||||
self.feed_tar2(filename, input_pipe)
|
self.feed_tar2(filename, input_pipe)
|
||||||
|
|
||||||
self.tar2_current_file = filename
|
self.tar2_current_file = filename
|
||||||
@ -1660,33 +1668,27 @@ class BackupRestore(object):
|
|||||||
reverse=True)
|
reverse=True)
|
||||||
|
|
||||||
|
|
||||||
def _handle_dom0(self, backup_path):
|
def _handle_dom0(self, stream):
|
||||||
'''Extract dom0 home'''
|
'''Extract dom0 home'''
|
||||||
local_user = grp.getgrnam('qubes').gr_mem[0]
|
local_user = grp.getgrnam('qubes').gr_mem[0]
|
||||||
|
backup_path = os.path.join("dom0-home", local_user)
|
||||||
home_dir = pwd.getpwnam(local_user).pw_dir
|
home_dir = pwd.getpwnam(local_user).pw_dir
|
||||||
backup_dom0_home_dir = os.path.join(self.tmpdir, backup_path)
|
backup_dom0_home_dir = os.path.join(self.tmpdir, backup_path)
|
||||||
restore_home_backupdir = "home-pre-restore-{0}".format(
|
restore_home_backupdir = "home-restore-{0}".format(
|
||||||
time.strftime("%Y-%m-%d-%H%M%S"))
|
time.strftime("%Y-%m-%d-%H%M%S"))
|
||||||
|
|
||||||
self.log.info("Restoring home of user '%s'...", local_user)
|
self.log.info("Restoring home of user '%s' to '%s' directory...",
|
||||||
self.log.info("Existing files/dirs backed up in '%s' dir",
|
local_user, restore_home_backupdir)
|
||||||
restore_home_backupdir)
|
os.mkdir(os.path.join(home_dir, restore_home_backupdir))
|
||||||
os.mkdir(home_dir + '/' + restore_home_backupdir)
|
tar3_cmdline = ['tar','-C',
|
||||||
for f_name in os.listdir(backup_dom0_home_dir):
|
os.path.join(home_dir,restore_home_backupdir), '-x']
|
||||||
home_file = home_dir + '/' + f_name
|
retcode = subprocess.call(tar3_cmdline, stdin=stream)
|
||||||
if os.path.exists(home_file):
|
|
||||||
os.rename(home_file,
|
|
||||||
home_dir + '/' + restore_home_backupdir + '/' + f_name)
|
|
||||||
if self.header_data.version == 1:
|
|
||||||
subprocess.call(
|
|
||||||
["cp", "-nrp", "--reflink=auto",
|
|
||||||
backup_dom0_home_dir + '/' + f_name, home_file])
|
|
||||||
elif self.header_data.version >= 2:
|
|
||||||
shutil.move(backup_dom0_home_dir + '/' + f_name, home_file)
|
|
||||||
retcode = subprocess.call(['sudo', 'chown', '-R',
|
|
||||||
local_user, home_dir])
|
|
||||||
if retcode != 0:
|
if retcode != 0:
|
||||||
self.log.error("*** Error while setting home directory owner")
|
raise QubesException("Inner tar error for dom0-home")
|
||||||
|
retcode = subprocess.call(['sudo', 'chown', '-R',
|
||||||
|
local_user, os.path.join(home_dir, restore_home_backupdir)])
|
||||||
|
if retcode != 0:
|
||||||
|
self.log.error("*** Error while setting restore directory owner")
|
||||||
|
|
||||||
def _handle_appmenus_list(self, vm, stream):
|
def _handle_appmenus_list(self, vm, stream):
|
||||||
'''Handle whitelisted-appmenus.list file'''
|
'''Handle whitelisted-appmenus.list file'''
|
||||||
@ -1827,7 +1829,8 @@ class BackupRestore(object):
|
|||||||
new_vm = None
|
new_vm = None
|
||||||
vm_name = restore_info[vm.name].name
|
vm_name = restore_info[vm.name].name
|
||||||
|
|
||||||
if self.options.verify_only:
|
if self.options.verify_only or vm.name == 'dom0':
|
||||||
|
# can't create vm, but need backup info
|
||||||
new_vm = self.backup_app.domains[vm_name]
|
new_vm = self.backup_app.domains[vm_name]
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
|
@ -188,13 +188,12 @@ def handle_broken(app, args, restore_info):
|
|||||||
"--ignore-username-mismatch to continue anyway.")
|
"--ignore-username-mismatch to continue anyway.")
|
||||||
else:
|
else:
|
||||||
app.log.warning("Continuing as directed.")
|
app.log.warning("Continuing as directed.")
|
||||||
app.log.warning("NOTE: Before restoring the dom0 home directory, "
|
app.log.warning("NOTE: The archived dom0 home directory "
|
||||||
"a new directory named "
|
"will be restored to a new directory "
|
||||||
"'home-pre-restore-<current-time>' will be "
|
"'home-restore-<current-time>' "
|
||||||
"created inside the dom0 home directory. If any "
|
"created inside the dom0 home directory. Restored "
|
||||||
"restored files conflict with existing files, "
|
"files should be copied or moved out of the new "
|
||||||
"the existing files will be moved to this new "
|
"directory before using them.")
|
||||||
"directory.")
|
|
||||||
|
|
||||||
def main(args=None, app=None):
|
def main(args=None, app=None):
|
||||||
'''Main function of qvm-backup-restore'''
|
'''Main function of qvm-backup-restore'''
|
||||||
|
Loading…
Reference in New Issue
Block a user