VPS

High disk usage with Magento

It is common for Magento installations to end up filling the disk. First you need to identify where the space is being used, then set up a scheduled task to free it automatically.

Add the following commands to a cron job running once per hour, replacing USUARIO with your actual username. See how to verify a cron job's output to confirm they run correctly.

High disk usage in /var/session/

Delete sessions older than 7 days:

find /home/USUARIO/public_html/var/session/ -name "sess_*" -type f -mtime +7 -exec rm -f {} \;

If there are a huge number of files, find may be slow. Another option is ls, although in this case you will delete every session (logged-in users will lose their session):

ls -U | head -99999999 | grep sess_ | xargs rm

High disk usage in /pub/media/captcha/base/

Delete captcha images older than one day:

find /home/USUARIO/public_html/pub/media/captcha/base/ -name "*.png" -type f -mtime +1 -exec rm -f {} \;

High disk usage in /var/report/

Delete error reports older than 7 days:

find /home/USUARIO/public_html/var/report/ -type f -mtime +7 -exec rm -f {} \;

High disk usage in /media/catalog/product/cache/

Delete the product image cache older than 7 days (Magento regenerates it on demand):

find /home/USUARIO/public_html/media/catalog/product/cache/ -type f -mtime +7 -exec rm -f {} \;