title: Extracting tar file with original time stamp
body: <p>My objective is to extract archive file members to different location with original timestamps using python 2.6.</p>
  
  <p>For example :</p>
  
  <pre><code>tar -tzvf nas_archive_11-15-12.tgz
  -rw-r--r-- appins/app     2337 2012-11-15 10:25:09 nfs4exports/opt/prod/fmac/files/inbound/test_archive/a.txt.gpg
  </code></pre>
  
  <p>I want to restore above file to "/nfs4exports/opt/prod/fmac/files/inbound/test_archive/11-15-12/a.txt.gpg" since it was last modified on 15th November 2012.</p>
  
  <p>I have created following script :</p>
  
  <pre><code>#!/usr/bin/python
  
  import os, tarfile
  from datetime import datetime, date, timedelta
  import datetime
  
  a_path = '/home/appins/.scripts/'
  
  for root, subFolders, files in os.walk(a_path):
          for file in files:
             if file.startswith("nas_archive"):
                  print file, " is getting extracted"
                  mytar = tarfile.open(file)
                  for member in mytar.getmembers():
                      if member.isreg():
                          myname = '/' + member.name
                          path_list = myname.rsplit('/')[1:]
                          print path_list
                          member.name = os.path.basename(member.name)
                          i_base = 'inbound'
                          i = -1
                          for index,value in enumerate(path_list):
                              if value == i_base:
                                  i = index
                                  break
                          if i == -1:
                              print i_base, " not found"
                          else:
                              path_list.insert(index + 2, '11-15-12')
                              path_list.remove(member.name)
                          print path_list
                          newpath = '/' +  os.path.join(*path_list)
                          print newpath
                          mytar.extract(member,newpath)
  </code></pre>
  
  <p>This script is working as expected but it extracting files with today's timestamps rather than original time stamp. Here I won't be able to use extractall method since i am calculating path separately for each file based on its original path. Is there a way for me to restore file to new location with original timestamps?</p>