Expire Plesk backups older than X days

Public

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.

</> CopyGet raw version
bash
  1. #!/bin/sh
  2. #
  3. # Delete backup more than 7 days old.
  4. #
  5. backupDir="/var/lib/psa/dumps/"
  6. #
  7. daysToKeep=7
  8.  
  9. echo "Checking for files older than $daysToKeep days in $backupDir"
  10. listOfFiles=`find $backupDir -mtime +$daysToKeep -type f`
  11.  
  12. if [[ ! -z $listOfFiles ]]
  13. then
  14. echo "Found [$listOfFiles]"
  15. else
  16. echo "None found."
  17. fi
  18. for toDelete in $listOfFiles
  19. do
  20. echo "Deleting $toDelete"
  21. rm $toDelete
  22. done
  23. echo "Done."