web analytics

/backup taking up space

Sometimes you may get a disk critical error, and if it is the cpanel backup that is taking space, the following may help. Sometimes the backup of a lot of terminated/cancelled accounts may be present in the backup which may be adding to the disk usage. The following scripts checks the monthly backup and if there are backups of inactive accounts in the server, deletes them to regain space.


1) Get the accounts in /etc/userdomains

cat /etc/userdomains | awk -F: ‘{print $2}’ > /root/list_domains


2) Get the accounts present in the monthly backup ( use the correct path)

ls -al /backup/cpbackup/monthly/ | awk ‘{print $9}’ > /root/list_backup


3)Create a script to compare the accounts in userdomains and monthly backup and if not found in userdomains,it will be displayed.

vi checking

#!/bin/bash

#home=$1 #home
#bkp=$2 #backup
home=”/root/list_domains”
bkp=”/root/list_backup”

backups=(`cat $bkp`)
for index in ${!backups[*]}; do
var=${backups[$index]}
check=${var/.tgz}
if [[ ! `awk “/$check/” $home` ]]; then
# echo $var
cd /backup/cpbackup/monthly/ ; du -sh $var
#du -sh “/backup/cpbackup/monthly/$var”
#echo -e “33[31m $var : No Home Directory Found 33[0m”
fi
done

ANOTHER ONE

vi /root/checking

#!/bin/bash

for i in `cat /root/list_backup`
do
match_found=0
for j in `cat /root/list_domains`
do
if [ “$i” == “$j” ]
then
match_found=1
fi
done
if [ $match_found -ne 1 ]
then
echo $i
fi
done


4) Give execute permission to the script

./checking > /root/list_unused


5) Get the list of unused accounts into a file.

./checking > /root/list_unused


6) The list /root/list_unused contains the inactive/cancelled/terminated accounts in the server which can be then deleted to regain space. Make sure that the account is not present in the server before deleting.


7) It is not always necessary to delete all the unused accounts. If you want, you may just remove the large accounts only. You can get the size of unused accounts as follows.

for i in `cat /root/list_unused`; do du -sh /backup/cpbackup/monthly/$i; done


PS: Thanks to my brother Praveen and MAR for helping me with the script 🙂

Leave a reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>