I want to write a python script which can compress multiple folders and their content with gzip with maximum compression ratio.
As an example I have following folders in my linux directory with mentioned folder size
/tmp/project1 (50MB)
/tmp/project2 (100MB)
I need to compress both folders together with a single name and need to reduce total compressed size at least 50% of total actual folder size. I tried following code, but it doesn’t gives me the expected result (my examples gives 148MB as compressed file)
import tarfile
tar = tarfile.TarFile.gzopen("test_archive.gz", mode="w", compresslevel=9)
tar.add("/tmp/project1", arcname="project1")
tar.add("/tmp/project2", arcname="project2")
tar.close()