def get_item_vectors(config, items, domain): bs = int(ltoUtil.get_blocksize(config)) ids = string.join(items, ',') params = urllib.urlencode({'domain':domain, 'ids':ids}) conn = httplib.HTTPConnection(ltoUtil.get_host_port(config)) try: conn.request('POST', ltoUtil.get_lto_url(config)+'/xquery/get-file-lto-vector.xql?'+params, None, {}) response = conn.getresponse() data = response.read() if '<exception>' in data: print ltoUtil.get_xquery_exception_msg(data) print ltoUtil.get_script_name()+' script terminated.' sys.exit(2) except httplib.HTTPException, e: print 'Unable to connect to database'
def restore_media_items(config, domain, vectors): tape = ltoUtil.get_tape_device(config) restore_dir = ltoUtil.get_restore_dir(config) bs = int(ltoUtil.get_blocksize(config)) blocking_factor = bs/512 setup_done = False prev_tape_id = "" for v in vectors: tape_id = v[0] offset = v[1] filesize = v[2] record_offset = v[3] filename = v[4] md5 = v[5] blocks = int(filesize/bs)+2 trim = (record_offset*512)%bs if not prev_tape_id == tape_id: raw_input('Insert tape: '+tape_id+' [Press Enter to continue]') if not setup_done: ltoWriteUtil.setup_tape_drive(config) setup_done = True print '\nSeeking to tape block: '+str(offset) p = subprocess.Popen('mt -f '+tape+' seek '+str(offset), shell=True) sts = os.waitpid(p.pid, 0) print 'Restoring file: '+filename p = subprocess.Popen('dd if='+tape+' bs='+str(bs)+' count='+str(blocks)+' | dd bs='+str(trim)+' skip=1 | tar -x -C '+restore_dir+' '+filename+' --occurrence', shell=True, stderr=subprocess.PIPE) sts = os.waitpid(p.pid, 0) #md5 check restored files if md5 == ltoUtil.get_md5_hash(restore_dir+'/'+filename): print 'Verified MD5: '+filename else: print 'MD5 verification failed for '+filename #Rename files to include event metadata extra_metadata_str = get_session_full_name(config, session_id) filepath = restore_dir+'/'+filename ltoUtil.move(filepath, filepath[:-4]+'_'+extra_metadata_str+'.'+ltoUtil.get_file_extn(filepath)) prev_tape_id = tape_id print '\nAll files successfully restored to '+ltoUtil.get_restore_dir(config)