I copied this script from some book to make tar.bz2 of some folders for backup.
#!/usr/bin/env python
import tarfile, os
def make_tar(folder_to_backup, dest_folder, compression='bz2'):
if compression:
dest_ext ='.' + compression
else:
dest_ext = ''
arcname = os.path.basename(folder_to_backup)
dest_name = '%s.tar%s' % (arcname, dest_ext)
dest_path = os.path.join(dest_folder, dest_name)
if compression:
dest_cmp = ':' + compression
else:
dest_cmp = ''
out = tarfile.TarFile.open(dest_path, 'w' +dest_cmp)
out.add(folder_to_backup, arcname)
out.close()
return dest_path
print "Doing Python"
make_tar('/home/bob/public_html','/home/bob/testbck', compression='bz2')
Now bash take 40 second to make backup of that folder and python takes around 8 minutes.
Am i wrong somewhere or python is always slower for these tasks