UNIX Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsOperating SystemsUNIX Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old August 27th, 2011, 04:12 PM
lkraemer lkraemer is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2011
Posts: 1 lkraemer User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 m 56 sec
Reputation Power: 0
Help with script to copy drive with cpio

I found this script on the internet for my brother to use when copying his
Sun Box 20 Gig Hard Drive to a new 120 Gig Seagate. The script doesn't
traverse subdirectories, and therefore doesn't copy the 20 Gig to the
120 Gig drive. If someone could assist with the script to help getting it
to function with cpio to copy the 20 Gig to the 120 Gig I'd appreciate it,
as I know nothing about Unix.......

Code:
#!/bin/sh
#
# Original Script written by Constantin Ionescu
# Modified by Carlo Cosolo
# Modified by Peter Baer Galvin
# Modified by John West
#
#
# <<<----- Modified for use of cpio instead of ufsdump/ufsrestore
#
# Use and distribute freely
#
# Define variables for use in the script
#! Important, these must be set correctly !
#

# The root disk to duplicate (leave off slice numbers and path)
SRC=c0t0d0

# The empty disk to duplicate it to (leave off slice numbers and path)
DEST=c0t1d0

# The directory to mount destination partitions on while duplicating
MOUNTDIR=/dup_0

# The file name of this script, to rename it on the destination to avoid execution
SCRIPT=/opt/local/etc/rootcopy

# The slices that should be copied
# where s0 - / and s1 - swap and s3 - /usr
SLICES="s0 s3"

echo ===================================
echo Disk Copy script started `date`
echo

# Make sure the mount point for duplicate partitions exists

if [ ! -d $MOUNTDIR ]; then
mkdir $MOUNTDIR
chmod 700 $MOUNTDIR
fi

# Partition the duplicate disk, make filesystems, make it bootable

prtvtoc /dev/dsk/${SRC}s2 | fmthard -s - /dev/rdsk/${DEST}s2

# Less elegant, but working version of line above
#
# prtvtoc /dev/rdsk/${SRC}s2 > /tmp/vtoc
# fmthard -s /tmp/vtoc /dev/rdsk/${DEST}s2

installboot /usr/platform/`uname -i`/lib/fs/ufs/bootblk /dev/rdsk/${DEST}s0

# Modify the following loop to handle any special cases

for fs in $SLICES
do
	newfs /dev/dsk/${DEST}${fs} < /dev/null; mount /dev/dsk/${DEST}${fs} ${MOUNTDIR};
	find /dev/dsk/${SRC}${fs} -mount -print | cpio -pdmuV ${MOUNTDIR};
	if [ $fs = "s0" ]; then
		sed 's/${SRC}/${DEST}/g' /etc/vfstab > ${MOUNTDIR}/etc/vfstab;
		mv ${MOUNTDIR}/${SCRIPT} ${MOUNTDIR}/${SCRIPT}.DONTRUN;
	fi
umount ${MOUNTDIR}
done

echo 
echo Disk Copy script ended `date`
echo =====================================
echo




Thanks.


Larry

Reply With Quote
  #2  
Old August 27th, 2011, 10:37 PM
SimonJM SimonJM is offline
Contributing User
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Mar 2006
Posts: 2,108 SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 1 Week 1 Day 4 h 50 m 50 sec
Reputation Power: 1485
Your major problem, or one of them at least, is in the copying of the disk layout from source to target. Doing this is a good idea if the disks are the same, but doing so going from a 20GB disk to a 120GB disk means you end up with the second disk only being setup' to be 20GB. You can go back later and mess with the partitions to resize them, but tread carefully. It's been a while since I messed with disks in Solaris and I was wary even when I thought I knew what I was doing!

Whilst the script duplicates the disk layout from source to target it only copies whatever is mounted on sections 0 and 3 (root and usr I think are the defaults for those). Section 1 tends to be swap (generally don't copy that!), section 2 is 'whole disk' - great to backup entire disk if you are using dd or something similar, sections 4, 5, 6 and 7 - if used - would be for stuff like /var, /home (or /export/home), etc.
I have not used cpio a great deal, but that looks like it would deal with directories, so long as they are within the file system (partition) being copied.
If there are other mounted file systems on the source disk you'll want to include the section names in the variable SLICES.
__________________
The moon on the one hand, the dawn on the other:
The moon is my sister, the dawn is my brother.
The moon on my left and the dawn on my right.
My brother, good morning: my sister, good night.
-- Hilaire Belloc

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > Help with script to copy drive with cpio

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap