def backup_machine_to_filesystem(self, machineid, backuppath):
from shutil import make_archive
if self.isCurrentStorageAction(machineid):
raise Exception("Can't delete a locked machine")
domain = self.connection.lookupByUUIDString(machineid)
diskfiles = self._get_domain_disk_file_names(domain)
if domain.state(0)[0] != libvirt.VIR_DOMAIN_SHUTOFF:
domain.destroy()
for diskfile in diskfiles:
if os.path.exists(diskfile):
try:
vol = self.connection.storageVolLookupByPath(diskfile)
except BaseException:
continue
poolpath = os.path.join(self.basepath, domain.name())
if os.path.exists(poolpath):
archive_name = os.path.join(
backuppath, 'vm-%04x' % machineid)
root_dir = poolpath
make_archive(archive_name, gztar, root_dir)
return True
评论列表
文章目录