Created
September 12, 2018 08:20
-
-
Save slavama/e4fe8797d38dfd294370d945aee5786b to your computer and use it in GitHub Desktop.
tar.gz archiving in python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import tarfile | |
from contextlib import closing | |
dirs = ['/var/www/clients/site1', '/var/www/clients/site2'] | |
for d in dirs: | |
contents = os.listdir(d) | |
name = d.split('/')[4] | |
print (name) | |
with closing(tarfile.open('%s.tar.gz' % name, 'w:gz')) as tar: | |
for item in contents: | |
tar.add(os.path.join(d, item)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment