Not a 100% drupal snippet, but related. I was surprised with the fact that Plesk doesn't expire already created backups! Create a bash script with the following code, put it somewhere and create a cron job for a root user to launch it once a day.
Get raw version
- # Delete backup more than 7 days old.
- echo "Checking for files older than $daysToKeep days in $backupDir"
- listOfFiles=`find $backupDir -mtime +$daysToKeep -type f`
- if [[ ! -z $listOfFiles ]]
- echo "Found [$listOfFiles]"
- echo "None found."
- for toDelete in $listOfFiles
- echo "Deleting $toDelete"
- rm $toDelete
- echo "Done."