Пример #1
0
def move_tar_files(config, session_id, device_code):
    tb = ltoUtil.get_tar_build_dir(config)
    archive_id = session_id+'-'+device_code
    tar = tb+'/'+archive_id+'.tar'
    xml = tb+'/'+archive_id+'.xml'
    dest = config.get('Dirs', 'tar_archive_dir')
    try: 
        print '\nMoving '+archive_id+'.tar to '+dest 
        ltoUtil.move(tar, dest)
        print '\nMoving '+archive_id+'.xml to '+dest 
        ltoUtil.move(xml, dest)
    except Exception, e:
        print '\nUnable to move archive files to: '+dest
        print ltoUtil.get_script_name()+' script terminated.'
        sys.exit(2)
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)
Пример #3
0
def write_tape_xml_file(config, tape_xml_doc, tape_id):
    tape_xml_filepath = ltoUtil.get_tape_build_dir(config)+'/'+tape_id+'.xml'
    print 'Creating tape index file '+tape_xml_filepath
    ltoUtil.write_xml(tape_xml_doc, tape_xml_filepath)
   
def move_build_virtual_tape_files(config, tape_id):
    dest = config.get('Dirs', 'virtual_tape_dir')+'/pending/'+tape_id
    try:
        if not os.path.exists(dest):
            os.mkdir(dest)
        else:
            ltoUtil.delete_dir_content(dest)
    except OSError, e:
        print 'Unable to create virtual tape directory: '+dest
        print 'OSError '+str(e.errno)+': '+e.strerror
        print ltoUtil.get_script_name()+' script terminated.'
        sys.exit(2)
    print 'Created virtual tape directory: '+dest
    
    tb = ltoUtil.get_tape_build_dir(config)
    for f in os.listdir(tb):
        if f.endswith('.tar') or f == tape_id+'.xml':
            try: 
                print 'Moving '+tb+'/'+f+' to '+dest 
                ltoUtil.move(tb+'/'+f, dest)
            except Exception, e:
                print '\nUnable to move file '+f+' to '+dest
                print ltoUtil.get_script_name()+' script terminated.'
                sys.exit(2)