Bug 14853 - Fix remote backups failures
Fix remote backups failures
Status: CLOSED WONTFIX
Product: Red Hat Linux
Classification: Retired
Component: rhbackup (Show other bugs)
5.2
i386 Linux
medium Severity medium
: ---
: ---
Assigned To: Nalin Dahyabhai
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2000-07-30 12:35 EDT by dmetz
Modified: 2007-04-18 12:27 EDT (History)
0 users

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2006-04-20 15:04:06 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)
src.rpm with patch to fix remote backup problems (15.89 KB, application/octet-stream)
2000-09-07 16:18 EDT, dmetz
no flags Details

  None (edit)
Description dmetz 2000-07-30 12:35:55 EDT
Fixed the remote backup problems.
Added some usage info and an opt for an alternate config file which you may
want to strip.
The modified version has been used extensively for some time without
complications.
As its small I've included the whole file as we are currently using it.
--------------------
# 990705-dam.  Fixes
# 1. create remote $LOGROOT dir here instead of repeatedly in remote_backup
# 2. the wildcard in the rsh must be expanded remotely
# 2. only issue the remote rm cmd once per host for incr* lists
# 3. read has stdin. protect it with redirect from /dev/null.
#    set its input to /dev/null or the next read will fail
---------------------

#!/bin/bash
# $Id: rhbackup,v 1.1 2000/06/29 00:04:28 dmetz Exp $
# $crtd:  by  ?Donald Barnes? in release redhat-5.2 $
# $cmnt:  Modified  by  Derald Metzger  on  990705.
#   See inline comments.
# 990819-dam. 
#   Modified user interface. Now accepts config file arg.
#   GPL license.
# $

### 990819-dam. BEG interface mods.

base=`basename $0`
cfg_fil=/etc/sysconfig/tape
echo=/bin/echo

usage="
NAME
  rhbackup - program to aid in backing up system data
SYNOPSIS
  rhbackup [--full | --test | --incremental] [-c cfg_fil]
DESCR
  This is a modified version of the original rhbackup program.
  See man page rhbackup(8).
  Modified to allow an additional cmdline arg for the config file.
  rhbackup supports local and remote backups. Remote backups fixed.
  The backup host executes this script.
  The source hosts provides the filesystem to backup.
  The sink host provides the backup device.
OPTIONS
  --full     - erases the incremental lists on the source hosts
               then does an incremental tar backup from source to sink
  --incremental - does an incremental tar backup from source to sink
  --test     - test access perms needed for backups using remote hosts
  -c cfg_fil - specify alternate env config file
FILES
  /etc/sysconfig/tape - default env config file
  /etc/backuptab      - customary backup source table
  /etc/backuptab-X    - customary backup excludes-list file
                        one on each source host
ALSO
  tar(1), rhbackup(8)
NOTES
  rhbackup is no longer part of the redhat distribution.
  rmt pkg is required on the remote hosts.
  A full backup deletes the incremental lists then does an incremental.
  Incremental lists are customarily kept in the log dir on each source
host.
"
if [ $# -lt 1 ]; then $echo "### $base: insufficient args $usage"; exit 1;
fi

if [ -n "$2" ]; then \
  if [ "$2" = "-c" ]; then cfg_fil=$3
  else $echo "### $base: invalid config file arg $usage"; exit 1; fi
fi

# need system config info
if [ -f $cfg_fil ]; then . /etc/sysconfig/tape
else $echo "### $base: Can't find config file $cfg_fil"; exit 1; fi

### 990819-dam. END interface mods.

# need backup config info
if [ ! -f "$BACKUPTAB" ]; then
        echo "Sorry, no $BACKUPTAB config file found."
        exit 1
fi

# who am i?
HOSTNAME=`hostname`

# setup the tape drive based on given info from /etc/sysconfig/tape
tape_setup () {

        echo -e "Backup started at $DATE.\nLogging to $LOG" >&2
        echo "$DATE" > $LOG

        echo -n "Setting up tape ... " >&2
        echo "rewinding" >&2
        mt -f $DEV rewind >> $LOG 2>&1
        echo "                    setting block size to $BLOCKSIZE" >&2
        mt -f $DEV setblk $BLOCKSIZE >> $LOG 2>&1
# 990705-dam.  Fixes
# 1. create remote $LOGROOT dir here instead of repeatedly in remote_backup
# 2. the wildcard in the rsh must be expanded remotely
# 2. only issue the remote rm cmd once per host for incr* lists
# 3. read has stdin. protect it with redirect from /dev/null.
#    set its input to /dev/null or the next read will fail
    HOSTLIST=""
    cat $BACKUPTAB | grep -v "^#" | grep -v "^$" | while read i; do
        set $i
        echo $HOSTLIST | grep $1
        if [ $? -ne 0 ]; then \
            HOSTLIST="$HOSTLIST $1"
            rsh $1 "[ -d $LOGROOT ] || mkdir -p $LOGROOT" < /dev/null
            rsh $1 rm -f $LOGROOT/'incremental-*' </dev/null
        fi
    done
}

tape_done () {
        sleep $SLEEP
        BLOCK=$(mt -f $DEV tell)
        DATE=$(date)
        echo -e "$DATE\n$BLOCK\nBackup completed." >> $LOG
        echo -e "Backup complete at $DATE.\nLogged to $LOG" >&2

        echo "Compressing $LOG in background ..."
        gzip -9 $LOG &

        echo "$BLOCK"
}

tape_rewind () {
# some crap code to only rewind after all incrementals are
# done.  Needs to be re-worked.
#if [ `cat $COUNTER` -gt 3 ]; then
#       tape_rewind
#       rm -f $COUNTER
#fi
#
# mt -f /dev/nst0 offline

        echo "Rewinding tape ..."
        mt -f $DEV rewind
}
# $1 is the error condition
# $2 is the machine
# $3 is the dir it was backing up
mail_it () {

        [ $1 -ne 0 ] && \
                cat << EOF | mail -s "Backups Failed" "$ADMIN"

Hi, this is the backup program at $HOSTNAME.  Your backups failed
for:

        $2:$3

EOF

}

# $1 should be the machine name
# $2 should be the dir to back up
# $3 should be the exclude file
# 000101-dam. Strip comments and blank lines from exclude-from file
local_backup() {
        expr `cat $DOTCOUNT` + 1 > $DOTCOUNT
        EXCLUDE=""
    MACHINE="$1"
    BACKUP_DIR="$2"
    if [ "$3" != "" ]; then
        sed -e '/^$/d' -e '/^#/d' <$3 >/tmp/backuptab-X_$$
        EXCLUDE="-X /tmp/backuptab-X_$$"
    fi 
    sleep $SLEEP
    date >> $LOG
    BLOCK=$(mt -f $DEV tell)
    echo -e "Backing up $MACHINE:$BACKUP_DIR ...\n$BLOCK" >> $LOG
    echo -e "Backing up $MACHINE:$BACKUP_DIR ...\n$BLOCK" >&2
    tar -cvlSp -g "$LIST-`cat $DOTCOUNT`" -b 64 -V "Date: `date` ***
Volume: $MACHINE:$BACKUP_DIR" $EXCLUDE -f $DEV $BACKUP_DIR >> $LOG 2>&1
        mail_it $? $MACHINE $BACKUP_DIR
    [ -f /tmp/backuptab-X_$$ ] && rm /tmp/backuptab-X_$$
}

# $1 should be the machine name
# $2 should be the dir to back up
# $3 should be the exclude file
# 000101-dam. Strip comments and blank lines from exclude-from file
remote_backup() {
        expr `cat $DOTCOUNT` + 1 > $DOTCOUNT
        EXCLUDE=""
    MACHINE="$1"
    BACKUP_DIR="$2"
    if [ "$3" != "" ]; then
        rsh $MACHINE "sed -e '/^$/d' -e '/^#/d' <$3 >/tmp/backuptab-X_$$"
</dev/null
        EXCLUDE="-X /tmp/backuptab-X_$$"
    fi 
    sleep $SLEEP
    date >> $LOG
    BLOCK=$(mt -f $DEV tell)
    echo -e "Backing up $MACHINE:$BACKUP_DIR ...\n$BLOCK" >> $LOG
    echo -e "Backing up $MACHINE:$BACKUP_DIR ...\n$BLOCK" >&2
    rsh $MACHINE tar -cvlSp -g "\"$LIST-`cat $DOTCOUNT`\"" -b 64 -V
"\"Date: `date` *** Volume: $MACHINE:$BACKUP_DIR\"" $EXCLUDE -f
"\"$HOSTNAME:$DEV\"" $BACKUP_DIR < /dev/null >> $LOG 2>&1
        mail_it $? $MACHINE $BACKUP_DIR
    rsh $MACHINE "[ -f /tmp/backuptab-X_$$ ] && rm /tmp/backuptab-X_$$"
</dev/null
}

full_backup () {
        echo 1 > $COUNTER
        echo 0 > $DOTCOUNT
        mkdir -p $LOGROOT/$DAY
        LOG=$LOGROOT/$DAY/full-backup-log-$SHORTDATE
        
        tape_setup

        # cycle through /etc/backuptab backing up from everything
        # that's there...       

        cat $BACKUPTAB | grep -v "^#" | grep -v "^$" | while read i; do
                set $i
                if [ $1 = $HOSTNAME -o $1 = "localhost" ]; then
                        local_backup $1 $2 $3
                else 
                        remote_backup $1 $2 $3
                fi
        done

        tape_done
}

incr_backup () {

        echo 0 > $DOTCOUNT
        mkdir -p $LOGROOT/$DAY
        LOG=$LOGROOT/$DAY/incr-backup-log-$SHORTDATE

        
        # cycle through /etc/backuptab backing up from everything
        # that's there...       

        cat $BACKUPTAB | grep -v "^#" | grep -v "^$" | while read i; do
                set $i
                if [ $1 = $HOSTNAME -o $1 = "localhost" ]; then
                        local_backup $1 $2 $3
                else 
                        remote_backup $1 $2 $3
                fi
        done

        tape_done
        expr `cat $COUNTER` + 1 > $COUNTER
}
test_con () {

        cat $BACKUPTAB | grep -v "^#" | grep -v "^$" | while read i; do
                set $i
                if [ ! $1 = $HOSTNAME -a ! $1 = "localhost" ]; then
                        echo "Testing $1"
                        rsh $1 "rsh $HOSTNAME date" < /dev/null > /dev/null
                        if [ $? -ne 0 ]; then
                                echo "Test failed!"
                                exit 1
                        else
                                echo "Test passed."
                        fi
                fi
        done

}

case "$1" in
        --full)
        full_backup
        ;;
        --incremental)
        incr_backup
        ;;
        --test)
        test_con
        ;;
        *)
        # Need correct argument...
        echo "Usage: full-backup --incremental|--full|--test"
        exit 2
        ;;
esac

# No need to rewind tape...full_backup will do that and incr_backup
# expects to be at the end of the tape anyway.
#
# tape_rewind

echo "Done."
Comment 1 dmetz 2000-09-07 16:18:02 EDT
Created attachment 3279 [details]
src.rpm with patch to fix remote backup problems
Comment 2 Brent Fox 2006-04-20 15:04:06 EDT
Closing bug due to old age.  We don't ship rhbackup anymore.

Note You need to log in before you can comment on or make changes to this bug.