Create gzipped tarballs with Python
Here's a little something that I've been using a lot lately on our servers. I use it mostly for compressing database backups prior to sending them off to an S3 bucket.
# We use this later for looping over and sending archived names.
archives = []
def compress(source):
target = "%s.%s" % (source, 'tgz')
with tarfile.open(target, "w:gz") as tgz:
tgz.add(source, arcname=target)
archives.appent(target)
tgz.close()
Simple and to the point, just as code should be.
Written by Brian Tomlinson
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Python
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#