#!/bin/bash # # $Id: copysafe 356 2011-09-24 23:25:47Z svnuser $ # # $Log: copysafe,v $ # Revision 1.14 2003/04/18 18:36:36 merlin # Better sed code to deal with fstab with labels from RH (orig sub) # rsync is not in -v mode by default anymore # # Revision 1.13 2001/11/12 22:40:35 merlin # Deal with SFS # # Revision 1.12 2000/05/25 04:49:52 merlin # Fixed latest problems with /mnt/disk/safe # # Revision 1.11 2000/05/25 04:25:51 merlin # Fixed to handle /mnt/disk/safe correctly # # Revision 1.10 2000/05/20 04:21:10 merlin # Root filesystem on safe can't be mounted read only. Doh! # # Revision 1.9 2000/05/20 04:10:13 merlin # Don't show mkdir failures # # Revision 1.8 2000/05/20 04:08:41 merlin # Create mount points on the safe partition # # Revision 1.7 2000/05/20 03:56:20 merlin # Gar! I can't even write a shell script... # # Revision 1.6 2000/05/20 03:53:34 merlin # Fix tab bug # # Revision 1.5 2000/05/20 03:48:31 merlin # Added warning # # Revision 1.4 2000/05/20 03:40:34 merlin # Converted from cp to rsync # # Revision 1.3 1999/09/16 23:41:51 merlin # Die really works now # # Revision 1.2 1998/08/10 01:32:33 merlin # Much improved version # # Revision 1.1 1998/08/03 23:05:09 merlin # Initial checkin # # die () { echo "$1 failed. Exit code: $?" exit 1 } if [ z"$1" = z-v ]; then RSYNCOPT=-v fi if [ -d /safe ]; then SAFE=safe SEDSAFE=safe fi if [ z$SAFE == z ]; then echo "Cannot run copysafe if you didn't create a /safe partition. You should have!" exit fi echo -n "Backup root is in /$SAFE. Replacing in 5 seconds" for i in 1 2 3 4 5 do sleep 1 /bin/echo -n "." done echo echo "Remounting /$SAFE read/write" mount -o remount,rw /$SAFE || die "Can't remount /$SAFE -o rw" echo "Starting rsync" # mount | sed -e "s/.*on /--exclude=/" -e "s/ .*//" | grep -v "^/$" | tr '\012' ' ' rsync $RSYNCOPT -aSHx --delete --exclude journal.dat --delete-excluded / /$SAFE rsync $RSYNCOPT -aSHx --delete --exclude journal.dat --delete-excluded /boot/. /$SAFE/boot/. echo echo "Creating /$SAFE mountpoints and converting /$SAFE/etc/fstab" mkdir -p `mount | grep -v none | sed -e "s/.* on /\/$SEDSAFE/" -e "s/ .*//" | grep -v "^/$SAFE/$" | tr '\012' ' '` 2>/dev/null mkdir /$SAFE/orig cat /etc/fstab | sed -e "s/\([ ]\)\/\([ ]\)/\1\/orig\2/" -e "s/\([ ]\)\/$SEDSAFE/\1\//" -e "s/,ro//" > /$SAFE/etc/fstab echo "Remounting /$SAFE read only" mount -o remount,ro /$SAFE || die "remount /$SAFE -o ro" if [ -f /etc/lilo.conf ]; then echo "Detected that you have lilo" if egrep -q "^image=/$SAFE/(boot/|)vmlinuz" /etc/lilo.conf; then echo "Running lilo to install new map" /sbin/lilo || die "lilo" else echo "/etc/lilo.conf isn't configured to offer kernel images in /$SAFE" echo "There is no point having a safe partition if you can't boot from it :-)" echo "Fix this and run lilo" fi elif [ -f /boot/grub/grub.conf ]; then echo "Detected that you have grub" if egrep -qi safe /boot/grub/grub.conf; then echo "Grub seems to be configured to boot from /safe, you're all set" else echo "Grub may not know how to boot from /safe, which kind of negates" echo "The purpose of that partition. Edit /boot/grub/grub.conf to fix this" fi else echo "Mmmhh, you seem to have neither lilo or grub. Make sure the system will reboot" fi