title: how to make a tar file backup of a directory in python
body: <p><strong>What I'm trying to do</strong>: I'm trying to make a <em>recursive</em> <code>.tar</code> file backup of the directory this python script is run in.</p>
  
  <p><strong>What I currently have:</strong></p>
  
  <pre><code>import os
  import zipfile
  import datetime
  import tarfile
  datetime = str( datetime.datetime.now() )
  def zipdir(path, zip):
      for root, dirs, files in os.walk(path):
          for file in files:
              zip.write(os.path.join(root, file))
  backupdir = raw_input('Which directory should we backup to? \n')
  if backupdir :
      try:
          zipf = zipfile.ZipFile('DrupalInstanceBackup'+datetime+'.zip', mode='w')
          zipdir('/Users/localuser/Downloads/backup', zipf)
      except Exception as e:
          print e
      finally:
          zipf.close()
  </code></pre>
  
  <p><strong>What it currently does:</strong>
  It makes a .zip backup, but when extracted it doesn't show any files.</p>
  
  <p><strong>What Im trying to do:</strong>
  Can someone help me make this script recursively backup a directory and create a <code>.tar</code> archive of the directory and its files in a recursive manner?</p>
  
  <p>Thank you</p>