-
Notifications
You must be signed in to change notification settings - Fork 3
/
cpanel-disk-cleaner
82 lines (65 loc) · 3.2 KB
/
cpanel-disk-cleaner
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/bin/bash
# Just a quick and simple cpanel cleaning script by @DJ_PRMF
# Homepage: http://tugatech.com.pt and http://djprmf.com
# This script is intended to clean some trash from cpanel servers.
# All the content removed should be safe for standard cpanel installations.
# IM NOT RESPONSIBLE FOR ANY DAMAGE, INCLUDING DATA LOST - except trash -, NUCLEAR WAR OR EXPLOSIONS
# But again, should be safe...
# PLEASE READ - PLEASE READ - PLEASE READ - PLEASE READ - PLEASE READ - PLEASE READ - PLEASE READ - PLEASE READ
# This script is not intended to ALL the servers. This should be used only as a reference.
# Edit the script and comment any command that you don't wanna run in the server.
# In doubt, apply every command manualy and don't run the full script.
# All the archived/compressed logs will be deleted. If you relly in the old logs, make a backup/download them first.
## Shows the usage before cleaning the house
df -h
## Lets clean the YUM
yum clean all
## Remove /var/logs compressed logs and remove any variations (most of the times archived and useless)
rm -f /var/log/*.gz
rm -f /var/log/*.?
rm -f /var/log/archive/*.gz
rm -f /var/log/audit/*.?
## Remove logs from NGINX. This could be disable if Nginx is not installed in the server.
rm -f /var/log/nginx/*.gz
rm -f /var/log/nginx/*.?
## Remove /usr/local/apache/logs compressed logs and remove any variations (most of the times archived and useless)
rm -f /usr/local/apache/logs/*.gz
rm -f /usr/local/apache/logs/*.?
rm -f /usr/local/apache/logs/archive/*.gz
## Remove /usr/local/cpanel/logs compressed logs and remove any variations (most of the times archived and useless)
rm -f /usr/local/cpanel/logs/*.gz
rm -f /usr/local/cpanel/logs/*.?
rm -f /usr/local/cpanel/logs/archive/*.gz
## Remove the cloudlinux-collectl archives - If installed under CloudLinux
## Can have a huge ammount of files not needed. Check before delete, if stats are important.
rm -f /var/log/cloudlinux-collect/*.gz
## Now moving on to /home
# Remove all the Core files - Not needed
rm -rf /home/core.*
# Remove Easy Apache update archives - Not needed
rm -rf /home/cpeasyapache
# Remove old MySQL install files
rm -rf /home/MySQL-install
# Remove cPanel File Manager temp files
rm -fv /home/*/tmp/Cpanel_*
# Delete all cPanel users .trash folders
find /home/*/.trash/* -exec rm -rf {} \;
# This will clean all the backup files generated under the users accounts.
# Useful if the backup feature in cPanel is enabled and users are not deleting old backups
# Probably you wanna alert the users before, so it will not run by default.
# for user in `/bin/ls -A /var/cpanel/users` ; do rm -fv /home/$user/backup-*$user.tar.gz ; done;
# Remove more useless files in /home
rm -f /home/latest
rm -rf /home/cprubygemsbuild
rm -rf /home/cprubybuild
rm -rf /home/cprestore
#rm -rf /usr/local/cpanel/src/3rdparty/* -> Use with caution. May be needed depending of the server usage. By default not running in the cleaning.
cd /tmp
for files in `ls`; do rm -f $files; done;
# restart MySQL - i leave this off by default, but could be enable to save more space and memory
# /scripts/restartsrv_mysql
# restart Apache (just for a "spring clean)
/scripts/restartsrv_apache
## Output again the space after the cleaning
df -h
## The End