|
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.
|
Who's Online
We have 4 guests online
Statistics
Content View Hits : 37279
Top Stories
| Top Stories |
 |
|
|