:: Shashank.net :: Personal Web

  • Increase font size
  • Default font size
  • Decrease font size
Home Articles Preserve Cpanel User Backups

Preserve Cpanel Backups

E-mail Print PDF
User Rating: / 0
PoorBest 

Hello Friends,

I will be releasing my scripts collection one my one from now one and so I start with the backups script I created recently This script maintains cpanel backups for any number of days you want for one particular user. A multi user version of this script is coming soon.

The script goes as below :

#!/bin/bash

#===========================================================================#
# Script by Shashank Wagh #
# Shashank.net(C) 2008. #
# This script preserves cpanel backups for any number of days for a domain. #
# Version 0.2 #
# This script is provided as it is. You should use it at your own risk. #
#===========================================================================#

### Please specify the four variables below ####

# user is the cpanel username to be packaged and saved
USER="cpanelusername"

# Please specify the mount mount of the parition for the backup.
# Command examples : /backup , /home2
BACKUPPAR="/backup"

# backupdir is the path to the place where these backups will be stored.
BACKUPDIR=$BACKUPPAR/userbackup/

# Number of days to keep backups
DAYS=30

# Changes than normal
# Host /home does not have enough space so tarroot is /backup
# I am using cpanel's userbackup method so that we get cpanel's time stamp.
===================================================================
### !!!! Warning: DO NOT edit anything below this line. !!!! ###
===================================================================

diskcheck() {
echo "[*] Checking backup partition usage"
usage=`df -h | grep backup | tr -s " " " " | cut -d " " -f 5 | cut -d "%" -f 1`
if [ $usage -gt 95 ]; then
echo "[*] Backup partition full. Aborting backups"
exit 0
else
echo "[*] Backup Partition check passed"
fi
}

createbackup() {
echo "[*] Checking Cpanel Users Homedir"
if [ -d /home/$USER ]; then
echo "[*] Homedir exists. Proceeding ..."
else
echo "[*] Homedir does not exist. Aborting script..."
exit 0
fi
echo "[*] Generating backup .."
/scripts/pkgacct $USER /backup userbackup
mv /backup/backup-*-$USER.tar.gz $BACKUPDIR/
echo "[*] Backup for $now moved to $BACKUPDIR"
}

cleanbackups() {
echo "[*] Checking for backups more than $DAYS old"
for i in `find $BACKUPDIR -maxdepth 1 -type f -mtime +$DAYS`
do
echo "The backup file $i is more than $DAYS old. Removing file.."
rm -rfv $i
done
echo "[*] Cleanup Completed"
}
diskcheck
cleanbackups
createbackup

Thank you.

 

 
Dedicated Servers

Search


Who's Online

We have 7 guests online

Statistics

Content View Hits : 11393

Syndication

Top Stories

Top Stories
Yahoo! News
  • Cruise passengers describe "cheeky" pirate attack (AP)

    Pirates ride alongside the luxury American cruise ship M/S Nautica, in this photo take from the Nautica, during a hijack attempt on the vessel, off the coast of Yemen in the Gulf of Aden, Sunday, Nov. 30, 2008.  The M/S Nautica, carrying 656 international passengers and 399 crew members, was sailing through the Gulf of Aden on Sunday when it encountered six bandits in two speedboats.  The pirates fired at the passenger liner but the larger ship was faster than the pirates' vessels, and escaped being boarded.(AP Photo)AP - Ordered to get inside and stay down, Oregon tourist Clyde Thornburg heard the pirates' rifle shots hit the side of the luxury cruise liner — "Pop! Pop! Pop!" — then felt the ship speed up to escape.


  • Paulson said weighing bailout's next $350 billion (Reuters)

    Treasury Secretary Henry Paulson speaks at a news conference at the Treasury Department in Washington, November 25, 2008. (Jason Reed/Reuters)Reuters - Treasury Secretary Henry Paulson is weighing whether to ask Congress for the remaining $350 billion of the financial bailout fund, with White House aides approaching President-elect Barack Obama's transition team about the idea, an Obama aide said on Wednesday.


  • UAW to renegotiate labor terms, suspend jobs bank (AP)

    United Auto Workers members listen to UAW President Ron Gettelfinger speak at a news conference at a meeting of UAW officials in Detroit, Wednesday, Dec. 3, 2008.  (AP Photo/Paul Sancya)AP - The United Auto Workers said Wednesday it is willing to change its contracts with U.S. automakers and accept delays payments of billions of dollars to a union-run health care trust to do its part to help the struggling companies secure $34 billion in government loans.