Clean backups and other files from a Web Hosting Server

Yes, you can simply find all the zip, tar, gzip and rar files and delete those, that would fix it. But are you sure you are not removing an important file for any of your customers or even from your server?

This bash script will remove most known backup files without removing any other file, also will remove logs, will empty trash bins, remove sql files and iso files (disabled by default).

The last 2 steps of the script will find more files that you could remove manually but the script will NOT remove any of these files for security.

This script will only look over /home/ /home2/ /home3/ and so on. This script will NOT remove anything out of these folders.

#!/bin/bash

echo "Starting user files cleaning ..."

echo "1/17 Cleaning up wpress files..."
find /home*/ -type f -name "*.wpress" -print -delete

echo "2/17 Cleaning up updraft files..."
find /home*/ -path "*/updraft/*" -type f -regex '.*\.\(zip\|gz\)$' -print -delete

echo "3/17 Cleaning up wpvividbackups files..."
find /home*/ -path "*/wpvividbackups/*" -type f -name "*.zip" -print -delete

echo "4/17 Cleaning up softaculous_backups..."
find /home*/ -path "*/softaculous_backups/*" -type f -regex '.*\.\(zip\|gz\)$'  -print -delete

echo "5/17 Cleaning up backups-dup-pro..."
find /home*/ -path "*/backups-dup-pro/*" -type f -regex '.*\.\(zip\|daf\)$'  -print -delete
find /home*/ -path "*/backups-dup-lite/*" -type f -name "*.zip" -print -delete

echo "6/17 Cleaning up wp_all_backup..."
find /home*/ -path "*/wp_all_backup/*" -type f -name "*.zip" -print -delete


echo "7/17 Cleaning up wp-staging..."
find /home*/ -path "*/wp-staging/backups/*" -type f -name "*.wpstg" -print -delete

echo "8/17 Cleaning up error logs..."
find /home*/ -name error_log -type f -size +1M -print -exec truncate --size 0 "{}" \;
find /home*/ -name debug.log -type f -size +1M -print -exec truncate --size 0 "{}" \;

echo "9/17 Cleaning up cPanel backup files..."
find /home*/* -type f -name "backup-*gz" -print -delete
find /home*/* -type f -name "cpmove-*gz" -print -delete

#echo "Cleaning up iso files..."
#find /home/ -type f -name "*.iso" -print -delete

echo "10/17 Cleaning up trash bins..."
find /home*/ -path '/home*/*/.trash/*' -type f -not -path '/home*/virtfs/' -delete

echo "11/17 Removing .well-known.zip files..."
find /home*/ -name ".well-known.zip" -type f -print -delete
find /home*/ -name "well-known.zip" -type f -print -delete

echo "12/17 Removing .cgi-bin.zip files..."
find /home*/ -name ".cgi-bin.zip" -type f -print -delete
find /home*/ -name "cgi-bin.zip" -type f -print -delete

echo "13/17 Removing .sql backups..."
#find /home*/ -name "*.sql" -type f -size +30M -print -delete

echo "14/17 Cleaning up backuply files..."
find /home*/ -path "*/backuply/*" -type f -name "*.gz" -print -delete

echo "15/17 Cleaning up backupbuddy files..."
find /home*/ -path "*/backupbuddy_backups/*" -type f -regex '.*\.\(zip\|dat\)$' -print -delete

echo "16/17 Cleaning up backupwordpress files..."
find /home*/ -path "*/backupwordpress-*-backups/*" -type f -regex '.*\.\(zip\|gz\)$' -print -delete

echo "17/17 Cleaning up backwpup files..."
find /home*/ -path "*/backwpup-*backups/*" -type f -regex '.*\.\(zip\|gz\)$' -print -delete

echo "Removing files Done."

echo "1/2 Checking the rest of files, you may find something that you want to manually clean up..."
find /home*/ -type f -regex '.*\.\(zip\|gz\|tar\|rar\|exe\)$' -size +50M ! -path "*/mysql-backup/*" -exec du -sh {} \;

echo "2/2 Checking to stuck cPanel File Manager temporary files ..."
find /home*/ -name "zi??????" -type f -regex '^[^.]*$' -exec du -sh {} \;

Leave a Reply