Reducing the disk usage is one system administration task that you will eventually have to do at some point. It’s almost inevitable, if you run a public server. There are many different things that may cause issues. Backup files and log files are two of the typical culprits.
This article provides some helpful tips of finding the disk hogs and reducing the file usage. For this article I’ll use a live Plesk server as an example. Shell into your server as root user, for command line access. You’ll need to shell into the server or have command line access as root for most of the commands in this tutorial.
First, take a look at the overage usage/availability of space on the server using the following command.
df -h
For this server you’ll notice only about 27% of the space is in use. The primary partition /dev/vzfs is using about 11G out of the 40G total allocation. At only 27% used, space is not really an issue. If you have more than 75% used, I would consider trying to reduce usage. Anything over 90% usage and you may experience server issues or even server failure.
Next, get a break down of each root level folder’s usage. Notice the folders that are in Gigabytes(G).
du -hs /*
Or, show just for the top 5 root level folders by disk usage.
du -sm /*
| sort -rn | head -n 5
Notice the /var, /usr, and /root folders are the large root folders on this server. The /var/www folder on this server holds most of the Web site content which can get fairly large depending on the type of sites hosted. Don’t underestimate the size of Web sites these days. Even simple WordPress sites can have hundreds of multimegabyte photos and videos. Change into those directories and run the following to drill-down into the folders. The following will show the directory usage in block sizes of 1MB. This is sometimes called “play hunt the disk hog” and may take some time and research. Hopefully in the end, you will find the hog.
du -sm ./*
| sort -rn | head -n 5
Next, let us go free up some of the logs. This is a major problem on Plesk servers, as it is common to avoid setting restrictions thru the Plesk Administrative panel. This leaves everything at “unlimited”, which can quickly cause problems as logs build up over time. You will generally find the majority of disk space that can be freed up in logs. Run the following commands.
Find Site Logs Over 10Mb
find /var/www/vhosts/*/statistics/logs/* -size +10M -exec ls -lh {} ; | awk '{print $5 , $9}'
On this server we have a couple of small site logs.
Delete Site Logs Over 10Mb
find /var/www/vhosts/*/statistics/logs/* -size +10M -exec rm -f {} ;
Find Server Logs Over 10Mb
find /var/log/* -size +10M -exec ls -lh {} ; | awk '{print $5 , $9}'
On this server we have a couple of small logs.
Delete Server Logs Over 10Mb:
find /var/log/* -size +10M -exec rm -f {} ;
Find Mail Logs Over 10Mb:
find /usr/local/psa/var/log/* -size +10M -exec ls -lh {} ; | awk '{print $5 , $9}'
On this server we have found just over 256Mb of mail logs. This is becoming a common problem as SPAM has continued to become more aggressive.
Delete Mail Logs Over 10Mb:
find /usr/local/psa/var/log/* -size +10M -exec rm -f {} ;
Show disk usage for each site:
du -sm /var/www/vhosts/*/httpdocs | sort -rn
Next, you’re probably wondering what is filling up the rest of the disk usage. Well, Plesk itself is a disk hog and will fill 1-2 Gb depending what you have installed.
Next find the Plesk backup files. There are many types of backups on Plesk that may get out of control really fast; users, clients, domains, server, updates, etc. The default Plesk backup location is in /var/lib/psa/dumps/.
Keep in mind, when you make backups of sites using the Plesk Administration Planel, you are making a backup of everything. This may include file backups and/or database backups generated by user programs. This causes backups of backups to be made. You need to be extra careful that this does not occur, as your Plesk backups files will grow very quickly! In the screen shot shown below, there is a weekly backup of a Web site. Note, you will want to delete these files from the Plesk Administration Panel, not from the command line.
In the end you should have been able to reduce the disk usage. Again, watch out for those log files and watch out for the backups.