Skip to content

Instantly share code, notes, and snippets.

@tiagosampaio
Created February 7, 2022 17:14
Show Gist options
  • Save tiagosampaio/15d25a55eff00b35baa28d387032b040 to your computer and use it in GitHub Desktop.
Save tiagosampaio/15d25a55eff00b35baa28d387032b040 to your computer and use it in GitHub Desktop.
Compressing Magento 2 Media Directory

Compressing Magento 2 Media Directory

Let's say you have something like this on your media structure.

pub/
|-- errors
|-- media
|   |-- catalog
|   |   |-- category
|   |   |-- placeholder
|   |   |-- product
|   |   |   |-- a
|   |   |   |-- b
|   |   |   |-- c
|   |   |   |-- cache
|   |   |   |-- placeholder
|   |-- placeholder
|   |   `-- placeholder
|   |       `-- default
|   |-- tmp
|   |   |-- catalog
|   |   |   `-- product
|   |   `-- design
|   |       `-- file
|   `-- wysiwyg
|-- opt
|   `-- magento
|       `-- var
`-- static
    |-- adminhtml
    `-- frontend

Some of these directories may take a huge amout of disk space and they don't need to be compressed. It's the case for pub/media/catalog/product/cache and pub/media/tmp directories, for instance.

tar --exclude='catalog/product/cache' --exclude='tmp' -czpf media.tar.gz pub/media
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment