Why is this script with rsync not working?

lloyd252

Member
Sep 24, 2010
15
0
51
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
 

cPanelTristan

Quality Assurance Analyst
Staff member
Oct 2, 2010
7,607
40
348
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.