How to Save 33GB of Disk Space (or… Managing Plesk Backups)

Posted by | October 22, 2009 | Advice and Troubleshooting | 3 Comments

Our hosted server recently ran out of disk space – an awkward situation. A little research revealed that /var/lib contained quite a lot of data – about 33GB more than we were expecting, most of it in /var/lib/psa/dumps/tmp.

Turns out that this is where Plesk puts its temporary files when doing backups, and for some reason they weren’t getting removed, and in our case, they totalled 33GB. So… first of all we removed them, and then set about making sure the situation didn’t happen again.

Chris Meller notes that sometimes the permissions on the directory get broken (such as when you restore from a backup), so I made sure that it was owner/group psaadm:psaadm and then, just to be sure, added a quick nightly cron job for root that runs the following script to remove any temporary files older than 90 days.  Job done.

#!/bin/sh
#
# Delete backup more than 90 days old.
#
backupDir="/var/lib/psa/dumps/tmp"
#
daysToKeep=90

echo "Checking for files older than $daysToKeep days in $backupDir"
listOfFiles=`find $backupDir -mtime +$daysToKeep`
if [ ! -z $listOfFiles ]
then
      echo "Found [$listOfFiles]"
else
      echo "None found."
fi
for toDelete in $listOfFiles
do
      echo "Deleting $toDelete"
      rm -rf $toDelete
done
echo "Done."

3 Comments

  • Nice tutorial Chris! Thanks for sharing this. My server was having the same issues and driving me crazy.

    I’ve added your script to my server root (is there a more appropriate place for it?) and am wondering how to initiate the daily cron? Should I setup the cron under a domain in Plesk? Or is there a better way?

    Thanks,
    Matt

  • Avatar for Chris Lilley Alexander Garzon says:

    Really cool.

    BTW, in news Plesk versions the path is

    backupDir=”/var/lib/psa/dumps”

    Thanks for this useful script !

  • Avatar for Chris Lilley Ivan Vučica says:

    Looks like this might delete folders that do contain newer backups, but themselves aren’t modified! For example, the entire /var/lib/psa/dumps!

    I’m passing additional “-type f” argument to find.

    listOfFiles=`find $backupDir -mtime +$daysToKeep -type f`

    Also, I’ve removed -rf to avoid even accidentally deleting entire folders. Just in case.

Leave a Reply

Your email address will not be published.

Get in touch to see how Black Pepper can help your business Contact Us