The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

SOLVED: Local & Remote Backups

Discussion in 'Data Protection' started by davetanguay, Nov 25, 2009.

  1. davetanguay

    davetanguay Active Member

    Joined:
    Mar 30, 2008
    Messages:
    25
    Likes Received:
    0
    Trophy Points:
    1
    After months of testing a local and remote backup solution we have finally found one that works and doesn't overload our servers.

    We cannot do full cPanel backups on the server since it causes a high load on large sites (over 4gig) and causes the servers to crash for hours on end.

    So we do local incremental backups (running as nice -n19) to a secondary drive using the standard cpbackup feature within WHM.

    Then weekly we transfer the /backup/cpbackup/daily backup to a remote FTP server using the script below. The backup script compresses each user's backup folder to a tar.gz file before transfer. We run the script as nice -19 as follows:

    nice -n19 /root/cpbackup-ncftp.sh

    You must have ncftp installed to your server in order for this to work.

    It's a cost effective solution since our remote FTP server is just a Windows XP machine running Filezilla. It has an external disk array of 4 SATA II drives which is very easy and inexpensive to upgrade. We're able to backup 6 cPanel servers remotely in just over a day. Total remote backup is over 600gig.

    Hope this helps someone out there! I know I can sleep at night now :)

    Code:
    ftpUser="insert-ftp-user-here"
    ftpPass="insert-password-here"
    ftpHost="insert-remote-ftp-hostname-here"
    remLoc="insert-server-name-here"
    SUBJECT="Remote Backup of $(hostname) Completed"
    TEMPFILE="$(mktemp)"
    DATE="date + Y- m- d"
    EMAIL="insert-email-here"
    
    echo "cPanel Backup Script..." >> $TEMPFILE
    echo "=============================" >> $TEMPFILE
    echo "Backup Start Date/Time: $(date)" >> $TEMPFILE
    echo "Performing Backup..." >> $TEMPFILE
    cd /backup/cpbackup/
    echo "Rotating & Uploading backup: $ftpHost" >> $TEMPFILE
    ncftp -u $ftpUser -p $ftpPass $ftpHost -P 21 <<**
    passive
    cd $remLoc
    rm -rf dump3
    rename dump2 dump3
    rename dump1 dump2
    mkdir dump1
    **
    rm -rf /backup/*-ncftp
    for i in `cat /etc/trueuserdomains | cut -d ':' -f2 | sed 's/ //'`
    do
    cd /backup/cpbackup/daily/
    mkdir /backup/$i-ncftp
    tar -zcf /backup/$i-ncftp/$i.tar.gz $i
    cd /backup/$i-ncftp/
    ncftp -u $ftpUser -p $ftpPass $ftpHost -P 21 <<**
    passive
    cd $remLoc
    cd dump1
    mput -R *
    **
    cd /backup/cpbackup/daily/
    rm -rf /backup/$i-ncftp
    done
    
    echo "Backup End Date/Time: $(date)" >> $TEMPFILE
    echo "=============================" >> $TEMPFILE
    echo "Backup Completed " >> $TEMPFILE
    echo "=============================" >> $TEMPFILE
    mail -s "$SUBJECT" "$EMAIL" < $TEMPFILE
    rm -f $TEMPFILE
    
     
    #1 davetanguay, Nov 25, 2009
    Last edited: Jan 24, 2010
  2. Vinayak

    Vinayak Well-Known Member

    Joined:
    Jun 27, 2003
    Messages:
    267
    Likes Received:
    2
    Trophy Points:
    18
    Location:
    Bharat
    cPanel Access Level:
    Root Administrator
    #2 Vinayak, Feb 3, 2010
    Last edited: Feb 3, 2010
  3. krisdv

    krisdv Well-Known Member

    Joined:
    Jun 18, 2003
    Messages:
    175
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    Belgium
    Excellent script!
     
    #3 krisdv, Apr 14, 2010
    Last edited: May 11, 2010
Loading...

Share This Page