7zip Exclude from compression but still store

  • Robert Readman

    Robert Readman - 2010-01-21

    When backing up with 7zip i.e.

    tar cvf - /my/backups/ | 7za a -si -t7z backup.tar.7z -mx=9

    In backups I have lots of files and folders, around 40% of them are .jpg files and .pdf files. I would still like to backup these files however they takeup alot of time to try compress only to shave a few bytes.
    Is there away to exclude the *.pdf and *.jpg from being compressed, however still store them in the .7z file.

    Many Thanks,

    Robert Readman.

  • Marcin Zajaczkowski

    You can use two phase compression. The first to store everything with exclusion on selected extension, the second to add to the same archive previously excluded files (with no compression). -ms=on is an optional flag.
    $ 7za a -mx=8 -ms=on foo-2phases.7z foo/ -xr\!foo/*.jpg -xr\!foo/*.png
    $ 7za a -mx=0 foo-2passes.7z -ir\!foo/*.jpg -ir\!foo/*.png

    It can be wrapped with a script containing a list of commonly known extensions which don't compress well, but nevertheless I thing there could be a switch in 7-zip/p7zip to make it in one command. That mechanism could have predefined (hardcoded) list of that extensions which could be overridden by an user using for example system variable.

    Something like:
    $ export P7ZIP_STORE_EXT="jpg gif 7z …"
    $ 7za a -mx=8 -mse=on foo.7z foo/


  • luminoso

    luminoso - 2011-06-21

    Could you please explain a little better you to use the variable? I have a big list that can greatly improve my backup speed!


    export the variable is enough?

  • ivanatpr

    ivanatpr - 2015-11-25

    I couldn't find an easy way to do this so I created a PowerShell script that will quickly compress a directory by storing filetypes that are already compressed (like .zip files) without trying to re-compress them.
    It uses 7zip's command line interface and uses filename extensions in order to decide whether to compress or simply store any given file.

    You can find the script here: https://gist.github.com/ivanatpr/5dea086172eab573ba71


Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks