Backup

jbk jbk at mail2.gis.net
Fri Dec 14 08:28:51 EST 2001


I have run a couple test backups and have some errors. I
believe they have to do with the -N option to tar, but I
haven't had the time yet to adjust the format.
I left the "rsh" calls alone as I have no other  "*nix"
machines now.

Since I am using  tar  to write to the tape I assume that
tar should be used to extract records from the tape.

The way I intend to do backups is to do a full to tape on
Monday, and then incremental backups to the same tape the
remainder of the week, put a new tape in and do the same for
the following week. This pattern repeats for 3 cycles and
then the first tape is overwritten. I have no need for
archival copies and no business to write off the cost of
tapes.

In light of this if you could look at the revised script and
logs I would appreciate any comments you have.  My system is
based on RH7.0 .

Jim
-------------- next part --------------
#!/bin/bash
# backup

append()	# append item to backup list table
{
    n=${#blist[*]}
    blist[$n]=$1
}

# Backup table
#
#     host    platform  filesystem   levels (Full/Incremental MTWTF)
# append 'loki       LinuxTar /mnt/windows/gbb 	I I I F I'
#####################
# append 'raijin     Linux    /dev/hda1 		I I I F I'
#####################
append 'localhost       LocalTar /etc   		F I I I I'
# append 'localhost       LocalTar /var	        	F I I I I'
# append 'localhost       LocalTar /usr/local		F I I I I'
# append 'localhost       LocalTar /home/Dad		F I I I I'
#####################

# Using 'dd' to write the tape avoids requiring .rhosts on artemis (owner
# of the tape drive) giving access to root from the other systems.  If
# the command were of the form 'rsh <remothost> dump f artemis:/dev/rst0',
# artemis would need to give root rsh privileges to <remotehost>.  Not doing
# this avoids giving system wide superuser privileges to people with Unix
# machines on their desks, while allowing those same people to have 
# superuser privileges for the machines on their desks.
#

TAPEDEV=/dev/nht0
WRT_TAPE="dd of=$TAPEDEV obs=126b"

error_exit()
{
    echo "The nightly backup failed" | mail -s "backup failed" backuplist
    mt -f $TAPEDEV rewoffl
    exit
}

dump_host()	# args: host platform filesystem levels day_of_week
{
    echo '####################'
    date
    # first test if we can access remote host
    # rsh -n $1 echo
    # if [ $? != 0 ] ; then
    #    echo "rsh to $1 failed" | mail -s "backup failed" backuplist
    #	return
    #	 fi

    day=$(($9 + 2))
    level=${!day}	# evaluate $day'th positional argument

    if [ $level = F ] ; then
	dl=0
	echo File $fileno: Full backup of $3 on $1
    else
	dl=5
	echo File $fileno: Incremental backup of $3 on $1
    fi

    case $2 in 
	SunOS)	  rsh -n $1 /etc/dump ${dl}uf - $3 | $WRT_TAPE ;;
	Solaris)  rsh -n $1 /usr/sbin/ufsdump ${dl}uf - $3 | $WRT_TAPE ;;
	Linux)	  rsh -n $1 /sbin/dump ${dl}uf - $3 | $WRT_TAPE ;;
	LinuxTar) if [ $level = F ] ; then
		    rsh -n $1 tar zcf - $3 | $WRT_TAPE
		  else
		    rsh -n $1 tar zcf - -N \"7 days ago\" $3 | $WRT_TAPE
		  fi ;;
	LocalTar) if [ $level = F ] ; then
		   tar zcf - $3 | $WRT_TAPE
		  else
		   tar zcf - -N \"7 days ago\" $3 | $WRT_TAPE 
		  fi;;
    esac

    if [ $? != 0 ] ; then error_exit ; fi

    fileno=$(($fileno + 1))
}

date
mt -f $TAPEDEV rewind
if [ $? != 0 ] ; then error_exit; fi

#
set -v
# cd /root/backup 

# Put a copy of the backup scripts on the tape as File 0
# tar cvf $TAPEDEV backup pc.backup
# if [ $? != 0 ] ; then error_exit; fi

# Determine backup level for today.  Get the day of the week, and
# add in the offset to the backup level arguments.  The crontab entries
# run backups starting at midnight, Monday night - Friday night, so
# the day of week numbers will be 2-6.  The level arguments start at $4.

if [ $# -eq 1 ] ; then
    case $1 in 
	Mon)    day_of_week=2 ;;
	Tue)    day_of_week=3 ;;
	Wed)    day_of_week=4 ;;
	Thu)    day_of_week=5 ;;
	Fri)    day_of_week=6 ;;
	*)  echo use day of week in lowercase
	    exit ;;
    esac
else
    day_of_week=$((`date +%w`))
    if [ $day_of_week -lt 2 ] ; then day_of_week=2 ; fi
    if [ $day_of_week -gt 6 ] ; then day_of_week=6 ; fi
fi

# Main loop.  Execute the backup for each host entry.
fileno=1
i=0
while [ $i -lt ${#blist[*]} ] ; do

    dump_host ${blist[$i]} $day_of_week

    i=$(($i + 1))
done

date
echo File $fileno - 'M$-win units'
#/root/backup/pc.backup $fileno

mt -f $TAPEDEV rewoffl
-------------- next part --------------
[root at kelly-rand /root]# backup
Thu Dec 13 21:47:31 EST 2001
####################
Thu Dec 13 21:47:34 EST 2001
File 1: Incremental backup of /etc on localhost
tar: Substituting 1969-12-31 18:59:59 for unknown date format `"7'
tar: days: Cannot stat: No such file or directory
tar: ago": Cannot stat: No such file or directory
tar: Removing leading `/' from member names
tar: Error exit delayed from previous errors
1840+0 records in
14+1 records out
####################
Thu Dec 13 21:48:01 EST 2001
File 2: Incremental backup of /var on localhost
tar: Substituting 1969-12-31 18:59:59 for unknown date format `"7'
tar: days: Cannot stat: No such file or directory
tar: ago": Cannot stat: No such file or directory
tar: Removing leading `/' from member names
tar: Error exit delayed from previous errors
157020+0 records in
1246+1 records out
####################
Thu Dec 13 21:52:44 EST 2001
File 3: Incremental backup of /usr/local on localhost
tar: Substituting 1969-12-31 18:59:59 for unknown date format `"7'
tar: days: Cannot stat: No such file or directory
tar: ago": Cannot stat: No such file or directory
tar: Removing leading `/' from member names
tar: Error exit delayed from previous errors
2260+0 records in
17+1 records out
####################
Thu Dec 13 21:53:00 EST 2001
File 4: Incremental backup of /home/Dad on localhost
tar: Substituting 1969-12-31 18:59:59 for unknown date format `"7'
tar: days: Cannot stat: No such file or directory
tar: ago": Cannot stat: No such file or directory
tar: Removing leading `/' from member names
tar: Error exit delayed from previous errors
83740+0 records in
664+1 records out
Thu Dec 13 22:00:08 EST 2001
File 5 - M$-win units
-------------- next part --------------
Fri Dec 14 08:01:29 EST 2001
####################
Fri Dec 14 08:01:31 EST 2001
File 1: Incremental backup of /etc on localhost
Fri Dec 14 08:02:02 EST 2001
File 2 - M$-win units


More information about the Discuss mailing list