[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Bash commands



Bob Proulx wrote:
> 
> Russell <rjshaw@iprimus.com.au> [2002-09-01 15:40:58 +1000]:
> > I might have gotten somewhere initially if i hadn't have
> > used those square [] brackets.
> 
> A couple of gratuitous comments concerning the scripting plus the
> helpful comments which were posted.  I can't help but to say
> something...

Thanks for the tips. I'm getting better;)
I've been making this backup script which
is nearly complete:

#!/bin/sh
#
# Russ' backup
#
# Warning: Do not run unless you understand every line of this script
#
# Copy everything (almost) from the system to a backup removeable hard-disk
# Assumptions:
#  run in super-user mode
#  the spare hard-disk has enough capacity
#  the spare disk has been formatted to match the original
#    in number and type of partitions
#
# The spare disk won't be bootable unless lilo is run separately,
#  which i haven't got around to doing yet

# The /boot partition:
HDD_BOOT=hdc1

# The main root / partition:
HDD_MAIN=hdc3


# Mount /boot partition
if ! mount | grep -qs /dev/$HDD_BOOT
then
  if ! mount -t ext2 /dev/$HDD_BOOT /mnt
  then
    echo "Removeable /dev/$HDD_BOOT not working"
    exit 1
  fi
fi

# Copy /boot partition
echo "Updating /boot"
if ! cp -auv /boot /mnt
then
  echo "Failed to update /boot"
  exit 1
fi

# Mount main partition
umount /mnt
if ! mount | grep -qs /dev/$HDD_MAIN
then
  if ! mount -t ext2 /dev/$HDD_MAIN /mnt
  then
    echo "Removeable $HDD_MAIN not working"
    exit 1
  fi
fi

# Copy everything on main partition
# Strip some top level directories we don't want to copy
FILES=$( ls / | sed -e s/boot//g | sed -e s/cdrom//g | sed -e s/proc//g | sed -e s/floppy//g | sed
-e s/mnt//g | sed -e s/dev//g)
# Note: I really want to copy some of these directories and their contents with
#       any attributes preserved, but without copying the contents of the files
#       (haven't figured out a command for that yet)

OPTS="-auv"
for i in $FILES
do
  echo "Updating /$i"
  if ! chroot / cp $OPTS $i /mnt
  then
    echo "Failed to update /$i"
    exit 1
  fi
done

echo "System backup successful"
exit 0



Reply to: