Tuesday, October 19, 2010

5 Tips to Free Up Disk Space on Linux Server

From time to time we need to clear up disk space on our servers, whether it is to just reduce disk space to help minimize the costs and usage of backup servers, or if it’s to clean up the server and help with performance.
Here are 5 easy ways you can instantly clear up hard drive space and reduce the number of inodes on your server:

1.) Remove User Generated cPanel Backups

Many times cPanel users aren’t aware that they should delete a cPanel backup before performing another cPanel backup. Essentially they are taking backups of backups and this can quite easily add up to several gigabytes of space just for one account. A quick and easy way to remove these is to run the following command from root:

for user in `/bin/ls -A /var/cpanel/users` ; do rm -fv /home/$user/backup-*$user.tar.gz ; done

Make sure to copy the full command exactly how it is above. This will work for cPanel hosting servers only.

2.) Audit your MySQL Databases

Not only will this free up disk space but it can greatly help with increasing the performance on your server. Large MySQL databases on sites that are receiving a large amount of traffic can really slow down a server. Many times the tables that are using the most space in a database are simply from visitor logging or caching, things that can be freed up instantly be truncating the table.
Use the following command when logged in as root to show the highest usage
databases on the server:

du -k --max-depth 1 /var/lib/mysql | sort -n

This will show a list of individual databases from lowest to highest. Databases larger than 500mb can be an issue with performance so it is worth it to investigate them.
Once you have the results from the command above, it is easy to go into phpMyAdmin and find the database. Once you have clicked on the database you should sort the table size by space, clicking it twice so that it shows the highest usage table on the top.
If the table is some type of visitor logging or tracking table, it generally is okay to truncate it. The same goes for caching. Make sure to backup the database just in-case before doing so, and it won’t hurt to do a quick google search to see if that table is okay to empty. Searching for the exact term/table name usually will bring up the results you are looking for.
This is a great way to free up disk space, RAM and help increase overall server performance.

3.) Remove Installatron and Fantastico Backups

If you are running Installatron or Fantastico on your server, it is easy for the backups for these files to use up a lot of inodes and space, taking up resources and slowing down performance. Usually once every few months we will remove these for that reason. You can do so by entering the following commands:

For Fantastico:

rm -rfv /home/*/fantastico_backups

For Installatron:

rm -rfv /home/*/.installatron/backups

These are the two software installers I am familiar with, if you are using another software installer the same can be done for it if you just insert the proper location where the backups are stored. Consult with the software developer to make sure it is okay to do so first.

4.) Get Rid of Cached Yum Files

Updates from Yum usually leave some unneeded files on the server. Do some
Yum house cleaning:

yum clean all

5.) Delete Failed FTP Uploads

When users are uploading files via pure-ftp and the upload either fails or is interrupted it will leave a partial file on the server. You can quickly get rid of these to clean up some disk space:

locate .pureftpd-upload | xargs rm -fv

Using the above five ways we have sometimes cleared hundreds of Gigabytes of space and doing all of the above should take you less than an hour.
Let us know your results or if you have anything to add.


  © Blogger templates Newspaper III by Ourblogtemplates.com 2008

Back to TOP