home *** CD-ROM | disk | FTP | other *** search
- #!/bin/bash
-
- function check_list() {
- set -f
- for i in $2
- do
- NAME=`echo $1 | egrep -x -e "$i"`
- if [ -n "$NAME" ]
- then
- echo $NAME
- break;
- fi
- done
- set +f
- }
-
- function Usage() {
- echo `basename $0` understands the following options:
- echo "--tape=<Device>"
- echo " Use <Device> as Tape instead of /dev/nrst0"
- echo "--verbose"
- echo "-v"
- echo " Use verbose option for tar command"
- echo "--help"
- echo " Print this message"
- echo "--exclude-disk=<List>"
- echo " Exclude the disks in this list from having their partition"
- echo " information written to tape"
- echo " Wildcards work \"/dev/hd?\" excludes all IDE disks"
- echo "--include-disk=<List>"
- echo " Write only the partition information of these disks to tape"
- echo " Wildcards work \"/dev/hd*\" includes all IDE disks"
- echo "--dirlist=<List of Directories>"
- echo " Save only these Directories to tape instead of everything"
- echo "--root=<Dir>"
- echo " Change to <Dir> before saving the files to tape"
- exit 1
- }
-
- TAPE=/dev/nst0
- CHDIR=/
- while [ "$#" -gt 0 ]
- do
- case "$1" in
- --tape=*)
- TAPE=`echo $1 | sed s/^.*=//`
- ;;
- --root=*)
- CHDIR=`echo $1 | sed s/^.*=//`
- if [ -z "$DIRLIST" ]
- then
- DIRLIST=.
- fi
- ;;
- --dirlist=*)
- DIRLIST=`echo $1 | sed s/^.*=//`
- ;;
- --verbose|-v)
- VERBOSE=-v
- ;;
- --exclude-disk=*)
- EXCLUDE_DISK=`echo $1 | sed -e "s/^.*=//" -e "s/?/./g" -e "s/*/.*/g"`
- if [ -n "$INCLUDE_DISK" ]
- then
- echo "not possible to use both --exclude-disk and --include-disk"
- exit 1
- fi
- ;;
- --include-disk=*)
- INCLUDE_DISK=`echo $1 | sed -e "s/^.*=//" -e "s/?/./g" -e "s/*/.*/g"`
- if [ -n "$EXCLUDE_DISK" ]
- then
- echo "not possible to use both --exclude-disk and --include-disk"
- exit 1
- fi
- ;;
- --help|-h|-?)
- Usage
- ;;
- *)
- echo unknown Option \"$1\"
- Usage
- ;;
- esac
- shift
- done
- if [ -z "$DIRLIST" ]
- then
- DIRLIST=`mount | egrep -v " proc| autofs | iso9660| devpts| nfs" |
- awk '{ print $3 }' | sed s:^/:./: | tr \\\n ' ' | sed "s: $::"`
- fi
- TMPDIR=/tmp/`basename $0`.$$
- rm -rf $TMPDIR
- mkdir -p $TMPDIR
- cd $TMPDIR
- echo Rewinding Tape "$TAPE"
- mt -f $TAPE rewind
- echo Saving partition information on Tape "$TAPE"
- /usr/lib/YaST/create_yast_partfiles
- for i in part.*
- do
- DEVICE=`echo $i | sed -e "s:part.:/:" -e "s:\\.:/:"`
- if [ -n "$INCLUDE_DISK" ]
- then
- FILE=`check_list $DEVICE "$INCLUDE_DISK"`
- [ -z "$FILE" ] && rm -f $i
- elif [ -n "$EXCLUDE_DISK" ]
- then
- FILE=`check_list $DEVICE "$EXCLUDE_DISK"`
- [ -z "$FILE" ] || rm -f $i
- fi
- done
- cd $CHDIR
- cat etc/fstab | grep -v ^# | awk '{print $2 }' | grep ^/ | sed s:^/:: \
- | grep -v ^$ | (cpio -o >mpoints.cpio 2>/dev/null)
- cd -
- mv $CHDIR/mpoints.cpio .
- tar cf $TAPE part.* mpoints.cpio
- cd $CHDIR
- echo Saving Filesystems under \"$DIRLIST\" on Tape "$TAPE"
- tar --numeric-owner -c -z -l $VERBOSE -f $TAPE $DIRLIST
- sleep 10
- mt -f $TAPE rewind
- rm -rf $TMPDIR
-