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.

Why is this script with rsync not working?

Discussion in 'General Discussion' started by lloyd252, Sep 17, 2012.

  1. lloyd252

    lloyd252 Member

    Joined:
    Sep 24, 2010
    Messages:
    15
    Likes Received:
    0
    Trophy Points:
    1
    So the script below comes from Brian Coogan to create a rotate schedule of the cpanel backups. That way I'm keeping multiple days, weeks, and months. Works perfectly.

    After his script, I added a couple lines at the end to rsync the contents of the cpbackup folder (and all the various daily, weekly, monthly backups) to another folder on the server. this isn't working. The files are not being copied successfully, so I suspect I've done something wrong with how I added the rsync portion.
    Code:
    #! /bin/sh
    
    # number of each to keep... comment out to skip that rotation
    # keepmonthly=2
    keepweekly=2
    keepdaily=3
    
    export PATH=$PATH:/usr/local/sbin:/usr/local/bin
    export POSTCPBACKUP=$$
    
    if testing=echo system.backup 2>/dev/null 1>&2
    then
       # backup system directories with optional script
       system.backup
    fi
    
    
    $debug cd /backup/cpbackup || exit 1
    test -s .postcpbackup && . .postcpbackup
    
    # daily backup - if daily is new, archive it and rotate archives
    if [ "$keepdaily" != "" -a -d daily/files ]
    then
        (( keepdaily++ ))
        cdate=$(date +"%Y%m%d")
        $test mv daily daily_$cdate
        $test mkdir daily
        ls -d daily?* 2>/dev/null | tac | tail -n +$keepdaily |
    	xargs -r $test rm -rf 2>/dev/null
    fi
    
    # if the weekly backup is new, archive it and rotate archives
    if [ "$keepweekly" != "" -a -d weekly/files ]
    then
        (( keepweekly++ ))
        cdate=$(date +"%Y%m%d")
        $test mv weekly weekly_$cdate
        $test mkdir weekly
        ls -d weekly?* 2>/dev/null | tac | tail -n +$keepweekly |
    	xargs -r $test rm -rf 2>/dev/null
    fi
    
    # if the monthly backup is new, archive it and rotate archives
    if [ "$keepmonthly" != "" -a -d monthly/files ]
    then
        (( keepmonthly++ ))
        cdate=$(date +"%Y%m")
        $test mv monthly monthly_$cdate
        $test mkdir monthly
        ls -d monthly?* 2>/dev/null | tac | tail -n +$keepmonthly |
    	xargs -r $test rm -fr 2>/dev/null
    fi
    
    exit 0
    
    # -end-
    
    #!/bin/bash
    rsync -avz --delete /backup/cpbackup/ /s3backup
    
     
  2. cPanelTristan

    cPanelTristan Quality Assurance Analyst
    Staff Member

    Joined:
    Oct 2, 2010
    Messages:
    7,623
    Likes Received:
    21
    Trophy Points:
    38
    Location:
    somewhere over the rainbow
    cPanel Access Level:
    Root Administrator
    Wouldn't you need to have the rsync section above this line?

    Code:
    exit 0
    This is causing the program to exit. You cannot run commands after that and have them actually process.
     
Loading...

Share This Page