Welcome, guest | Sign In | My Account | Store | Cart
import os
import tarfile

dstfolder = '/somepath/to/output'
fileorfoldertobackup = '/home/username'
dst = '%s.tar.bz2' % os.path.join(dstfolder, os.path.basename(fileorfoldertobackup))
out = tarfile.TarFile.open(dst, 'w:bz2')
out.addfile(fileorfoldertobackup, arcname=os.path.basename(fileorfoldertobackup))
out.close()

You can add as many 'addfile' commands as you would like. I hope this saves someone the momentary confusion I experienced.

History

  • revision 5 (19 years ago)
  • previous revisions are not available