Search the FAQ Archives

3 - A - B - C - D - E - F - G - H - I - J - K - L - M
N - O - P - Q - R - S - T - U - V - W - X - Y - Z
faqs.org - Internet FAQ Archives

comp.unix.aix Frequently Asked Questions (Part 5 of 5)
Section - 8.06: How do I do remote backup?

( Part1 - Part2 - Part3 - Part4 - Part5 - Single Page )
[ Usenet FAQs | Web FAQs | Documents | RFC Index | Business Photos and Profiles ]


Top Document: comp.unix.aix Frequently Asked Questions (Part 5 of 5)
Previous Document: 8.05: Updating to 3.2.5
Next Document: 8.06: How do I do remote backup? (cont.)
See reader questions & answers on this topic! - Help others by sharing your knowledge

[ formerly in section 1.201 ]

#!/bin/ksh
# @(#) Create a backup tape of the private user data.
#=================================================================#
#   Script :  usave.sh                                            #
#   Author :  F. Kraemer                                          #
#   Date   :  92/02/19                                            #
#   Update :  92/10/29                                            #
#   Info   :  the ultimative backup script                        #
#   Example:  usave.sh /dev/rmt0      -  save to local tape       #
#             usave.sh /save/save.me  -  save to local file       #
#             usave.sh /tmp/pipe      -  save to remote tape      #
#-----------------------------------------------------------------#
PS4="(+) "
#set -x
PROG=$(basename $0)
HOST=$(hostname)
TODAY=$(date +%H:%M:%S)
#
# cleanup
#
cleanup ()
{
ec=$1
error=$2
case "$ec"
in
   "$USAGE_EC")    # usage error
     error="Usage:\t$PROG DeviceName\n" 1>&2
    ;;
   "$NOTAP_EC")    # Tape error
     error="error:\t$PROG: $DEVICE is not available on the system.\n" 1>&2
    ;;
   "$LISTE_EC")    # list error
     error="error:\t$PROG: could not create tar list for $LOGNAME.\n" 1>&2
    ;;
   "$NOTAR_EC")    # tar command error
     error="error:\t$PROG: tar command failed.\n" 1>&2
    ;;
   "$PIPEP_EC")    # pipe error
     error="error:\t$PROG: mknod command failed.\n" 1>&2
    ;;
   "$NORSH_EC")    # rsh error
     error="error:\t$PROG: rsh - Remote Shell command failed.\n" 1>&2
    ;;
   "$RHOST_EC")    # remote host error
     error="error:\t$PROG: Remote Host unknown.\n" 1>&2
    ;;
   *)
   ;;
esac
case "$DEVICE"
in
    #
    # Fix the block size if $DEVICE is a tape device
    #
    /dev/rmt[0-9]*)
        echo "\n\t$PROG: Rewinding tape to begin.........(please wait)\n"
        tctl -f $DEVICE rewind 2>/dev/null
        ;;
    *) ;;
esac
rm -f ${LIST} ${PIPE} 2>/dev/null
[ -n "$error" ] && echo "\n${error}\n"
trap '' 0 1 2 15
exit "$ec"
}
#
# Variables
#
USAGE_EC=1                         # exit code for usage error
NOMNT_EC=2                         # exit code wrong device name
NOTAP_EC=3                         # exit code no tape available
LISTE_EC=4                         # exit code backup list error
NOTAR_EC=5                         # exit code for wrong tar
TRAPP_EC=6                         # exit code for trap
PIPEP_EC=7                         # exit code for pipe
RHOST_EC=8                         # exit code for bad ping
NORSH_EC=9                         # exit code for bad rsh
DEVICE="$1"                        # device to tar into
LIST="/tmp/.tar.$LOGNAME.$$"       #
REMOTEH=""                         # Remote host for backup
REMOTET=""                         # Remote tape for backup
tapedev=                           #
PIPE="/tmp/pipe"                   # Pipe for remote backup
#
# main()
#
tput clear
echo "\n\t$PROG started from $LOGNAME@$HOST on $TERM at $TODAY.\n"
rm -f $LIST 2>/dev/null
#
# Trap on exit/interrupt/break to clean up
#
trap "cleanup $TRAPP_EC \"Abnormal program termination. $PROG"\"  0 1 2 15
#
# Check command options
#
[ "$#" -ne 1 ]  &&  cleanup "$USAGE_EC" ""
#
# Check device name
#
[ `expr "$DEVICE" : "[/]"` -eq 0 ] && cleanup "$NOMNT_EC" \
        "$PROG: Backup device or file name must start with a '/'."
#
# Check tape device
#
case "$DEVICE"
in
    #
    # Fix the block size if $DEVICE is a tape device
    #
    /dev/rmt[0-9]*)
        #
        echo "\n\t$PROG: Verify backup media ($DEVICE)............\n"
        #
        # see if a low or high density tape device was specified
        # (eg rmt0.1)
        density="`expr $DEVICE : \
                "/dev/rmt[0-9]*\.\([0-9]*\)"`"
        #
        # strip /dev/ from device name and
        # get the base name (eg translate:
        # /dev/rmt0.2 to rmt0)
        #
        tapedev="`expr $DEVICE : \
                "/dev/\(rmt[0-9]*\)[\.]*[0-9]*"`"
        #
        # Check if the tape is defined in the system.
        lsdev -C -c tape -S Available -F "name" | grep $tapedev >/dev/null 2>&1
        rc=$?
        [ "$rc" -ne 0 ] && cleanup "$NOTAP_EC" ""
        #
        # Restore old tape name.
        #
        [ "${density:-1}" -lt 4 ] && density=1 || density=5
        DEVICE="/dev/${tapedev}.${density}"
        echo "\n\t$PROG: Insert a tape in ($DEVICE)........(press enter)\n"
        read TEMP
        echo "\n\t$PROG: Rewinding tape to begin...........(please wait)\n"
        tctl -f $DEVICE rewind 2>/dev/null
        ;;
    #
    # Backup is done on remote host. The remote shell facility
    # must be set up and running.
    #
    ${PIPE}*)
        #
        echo "\n\t$PROG: Assuming remote backup via network.\n"
        echo "\t$PROG: Enter name of Remote Host   ===> \c"
        read REMOTEH
        echo "\n\t$PROG: Pinging Remote Host to test connection.\n"
        ping ${REMOTEH} 1 1 >/dev/null 2>&1
        rc=$?                                    # give up unknown host
        [ "$rc" -ne 0 ] && cleanup "$RHOST_EC" ""
        JUNK=$(rsh ${REMOTEH} "/usr/sbin/lsdev -C -c tape -S Available")
        rc=$?                                    # give up rsh failed
        [ "$rc" -ne 0 ] && cleanup "$NORSH_EC" ""
        echo "\t$PROG: Available Tapes on ${REMOTEH} are :\n\n\t\t${JUNK}\n"
        echo "\t$PROG: Enter name of Remote Tape (e.g. /dev/rmt0) ===> \c"
        read REMOTET
        echo "\n\t$PROG: Insert tape on ${REMOTEH} in ${REMOTET}..(press enter)"
        read TEMP
        echo "\t$PROG: Rewinding Remote Tape ${REMOTET} on ${REMOTEH}.\n"
        rsh ${REMOTEH} "tctl -f ${REMOTET} rewind"
        rc=$?                                    # give up rsh failed
        [ "$rc" -ne 0 ] && cleanup "$NOTAP_EC" ""
        rm -f ${PIPE} 2>/dev/null
        mknod ${PIPE} p
        rc=$?                                    # give up mknod failed
        [ "$rc" -ne 0 ] && cleanup "$PIPEP_EC" ""
        cat ${DEVICE} | rsh ${REMOTEH} "dd of=${REMOTET} obs=100b 2>/dev/null" &
        ;;
    *)  ;;
esac
#
# Prepare the list
#
echo "\n\t$PROG: Create list of files to be saved...."
find $HOME -print > $LIST
rc=$?
[ "$rc" -ne 0 ] &&  cleanup "$LISTE_EC" ""
#
# tar the files
#
echo "\n\t$PROG: Changing current directory to (/)...."
cd / > /dev/null 2>&1
echo "\n\t$PROG: Running tar format backup from user ($LOGNAME)...."
tar -cvf "$DEVICE" -L "$LIST"
rc="$?"
[ "$rc" -ne 0 ]  && cleanup "$NOTAR_EC" ""
#
# Backup completed
#
TODAY=$(date +%H:%M:%S)
echo "\n\t$PROG ended at $TODAY............................\n\n"
cleanup 0

User Contributions:

Comment about this article, ask questions, or add new information about this topic:

CAPTCHA




Top Document: comp.unix.aix Frequently Asked Questions (Part 5 of 5)
Previous Document: 8.05: Updating to 3.2.5
Next Document: 8.06: How do I do remote backup? (cont.)

Part1 - Part2 - Part3 - Part4 - Part5 - Single Page

[ Usenet FAQs | Web FAQs | Documents | RFC Index ]

Send corrections/additions to the FAQ Maintainer:
bofh@mail.teleweb.pt (Jose Pina Coelho)





Last Update March 27 2014 @ 02:11 PM