#!/bin/sh # # Copyright (c) 2004 Kurt J. Lidl # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # 3. The name of the author may not be used to endorse or promote products # derived from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS # OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR # TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE # USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # # $Id: dodiskbackup,v 1.1.1.1 2004/05/17 23:52:49 lidl Exp $ # sdisk=sd0 ddisk=sd1 mnt=/a # scsi command and option research for spinup/spindown by Chris Ross spindown() { local disk disk=$1 scsicmd -f /dev/r${disk}c -c lu -P re-ten=0,load=0 } spinup() { local disk disk=$1 scsicmd -f /dev/r${disk}c -c lu -P re-ten=0,load=1 } do_newfs() { for part in a d e f h do newfs -d 0 -i 8192 -U nosoft /dev/r${ddisk}${part} done } do_mounts() { mount -o async /dev/${ddisk}a ${mnt} mkdir ${mnt}/usr ${mnt}/var ${mnt}/data mount -o async /dev/${ddisk}d ${mnt}/usr mount -o async /dev/${ddisk}e ${mnt}/var mkdir ${mnt}/var/tmp mount -o async /dev/${ddisk}f ${mnt}/var/tmp # make sure the direction is set properly chmod 1777 ${mnt}/var/tmp mount -o async /dev/${ddisk}h ${mnt}/data } do_tunefs() { local value local part value=$1 if [ "$value" = "disable" -o "$value" = "enable" ]; then for part in a d e f h do tunefs -n $value /dev/${ddisk}${part} done fi } # this are done one a time so any error message is easier to see do_umounts() { umount ${mnt}/data umount ${mnt}/var/tmp umount ${mnt}/var umount ${mnt}/usr umount ${mnt} } do_dump_restore() { for fs in / /usr /var /var/tmp /data do dump 0uf - ${fs} | (cd ${mnt}${fs} && restore -rf -) echo ${fs} done } # sed the existing fstab to reflect the new disk realities do_fstab_fixup() { sed -e "s|^/dev/"${sdisk}"|/dev/"${ddisk}"|" < /etc/fstab > ${mnt}/etc/fstab } # turn off soft updates while we do the restore date spinup ${ddisk} do_newfs do_tunefs "disable" do_mounts #exit do_dump_restore do_fstab_fixup do_umounts do_tunefs "enable" #do_mounts spindown ${ddisk} date