def recover_disk(base_disk, base_mem, overlay_mem, overlay_disk, recover_path, chunk_size): recover_fd = open(recover_path, "wb") # get delta list from file and recover it to origin delta_stream = open(overlay_disk, "r") recovered_memory = Recovered_delta(base_disk, base_mem, chunk_size, \ parent=base_disk, overlay_memory=overlay_mem) for delta_item in DeltaList.from_stream(delta_stream): recovered_memory.recover_item(delta_item) delta_list = recovered_memory.delta_list # overlay map chunk_list = [] # sort delta list using offset delta_list.sort(key=itemgetter('offset')) for delta_item in delta_list: if len(delta_item.data) != chunk_size: raise DiskError("recovered size is not same as page size") chunk_list.append("%ld:1" % (delta_item.offset/chunk_size)) recover_fd.seek(delta_item.offset) recover_fd.write(delta_item.data) last_write_offset = delta_item.offset + len(delta_item.data) # fill zero to the end of the modified file if last_write_offset: diff_offset = os.path.getsize(base_disk) - last_write_offset if diff_offset > 0: recover_fd.seek(diff_offset-1, os.SEEK_CUR) recover_fd.write('0') recover_fd.close() # overlay chunk format: chunk_1:1,chunk_2:1,... return ','.join(chunk_list)
raise MemoryError("footer data is different") LOG.info("meta file information is matched with original") elif command == "delta": if (not settings.mig_file) or (not settings.base_file): sys.stderr.write("Error, Cannot find modified memory file. See help\n") sys.exit(1) raw_path = settings.base_file meta_path = settings.base_file + EXT_META modi_mem_path = settings.mig_file out_path = settings.mig_file + ".delta" #delta_list = create_memory_overlay(modi_mem_path, raw_path, \ # modi_mem_path, out_path) mem_deltalist= create_memory_deltalist(modi_mem_path, basemem_meta=meta_path, basemem_path=raw_path) DeltaList.statistics(mem_deltalist) DeltaList.tofile(mem_deltalist, modi_mem_path + ".delta") elif command == "recover": if (not settings.base_file) or (not settings.delta_file): sys.stderr.write("Error, Cannot find base/delta file. See help\n") sys.exit(1) base_mem = settings.base_file overlay_mem = settings.delta_file base_memmeta = settings.base_file + EXT_META out_path = base_mem + ".recover" memory_overlay_map = recover_memory(None, base_mem, overlay_mem, \ base_memmeta, out_path, verify_with_original="./tmp/modi")