Ubuntu - 7zip Compression

Today I have been working on compressing database dumps (mysqldump) in order to save space, as well as allow them to be attached to emails (due to attachment file limits). 7zip appears to offer the best compression at the cost of a much slower speed. For more information on speed vs compression level please refer to the graph below.


[image source]

How to Install

sudo apt-get install p7zip-full

Useful Commands

This is the bog-standard/quick command for compressing a file, directory, or series of files

7z a [new-zip-file-name.7z] [files-to-compress]
# example
7z a database_dumps_archive.7z *.sql

For maximum compression at a much slower speed, add the -mx9 switch (1-9 being the level of compression)

7z -mx9 a [new-zip-file-name.7z] [files-to-compress]

PHP - Using Zip Insted of p7zip

It turns out that ZIP has some major advantages for me and I have switched to using that as the de-facto for the following reasons:

  • Zip is already integrated into PHP which is much nicer/more reliable when deploying than running shell_exec commands
  • It appears that Zip makes much better use of multi-threading capability as shown in the screenshots below

    [7zip compression - one thread used]



  • [zip compression - all threads used]

References

Whats The Best File Compression Method

No comments:

Post a Comment