fssnap improvements to a basic Solaris disk cloning script

I have a basic cloning script which replicates slices on a second, spare disk, which I run manually in single-user mode.   I would like introduce fssnap to allow me to run it on mounted file systems, including root (/), in mult-user mode so I can use a periodic cron job for backups.  

I've looked at the scripts suggested by JustUNIX in http://www.experts-exchange.com/Operating_Systems/Solaris/Q_20782407.html?query=ghost-like+mirror&clearTAFilter=true. but have a few questions.

The key change seems to to be as in the example below:

BEFORE:
mount /dev/dsk/c0t2d0s0 /mnt
/usr/sbin/ufsdump 0f - / | (cd /mnt; ufsrestore rf -)
rm /mnt/restoresymtable
cd /
umount /mnt

AFTER:
mount /dev/dsk/c0t2d0s0 /mnt
/usr/sbin/ufsdump 0f - `fssnap -F ufs -o raw,bs=<backing store>,unlink / `| ( cd /mnt ; ufsrestore rf - )
rm /mnt/restoresymtable
cd /
umount /mnt

My questions are:
1. Should the clone source be the mount point (e.g. "/") , block device (/dev/dsk/c0t0d0s0) or raw device (/dev/rdsk/c0t0d0s0)?
2. Do I need to clone each slice seperately, or can I use s2?
3. If have only two disks on the system, and they are the source and target disks, where should the backing store in the pipeline reside?
4. If I use fnsnsp unlink option, am I correct to assume I don't need to fssnap -d to remove the temporary snapshot after its use in the pipeline? Is unlink the best option to use?

Full, current script below.

# Disk to Disk Backup
#
date
echo "Creating New File Systems"
newfs /dev/rdsk/c0t2d0s0
newfs /dev/rdsk/c0t2d0s7
#
# recreate s0
echo "### Backup / file system"
mount /dev/dsk/c0t2d0s0 /mnt
/usr/sbin/ufsdump 0f - / | (cd /mnt; ufsrestore rf -)
rm /mnt/restoresymtable
cd /
umount /mnt
#
# recreate s7
echo "### Backup /export/home file system"
mount /dev/dsk/c0t2d0s7 /mnt
/usr/sbin/ufsdump 0f - /export/home | (cd /mnt; ufsrestore rf -)
rm /mnt/restoresymtable
cd /
umount /mnt
#
# Repair Recreated Disks
echo "###Repair / file system"
fsck -F ufs /dev/dsk/c0t2d0s0
echo "###Repair /export/home file system"
fsck -F ufs /dev/dsk/c0t2d0s7
#
echo "###install bootblk"
installboot /usr/platform/SUNW,UltraAX-i2/lib/fs/ufs/bootblk /dev/rdsk/c0t2d0s0
#
# Correct /etc/vfstab for disk2 (c0t2d0)
echo "###Correct /etc/vfstab for disk2"
mount /dev/dsk/c0t2d0s0 /mnt
cp /mnt/etc/vfstab       /mnt/etc/vfstab.disk0
cp /mnt/etc/vfstab.disk2 /mnt/etc/vfstab
cd /
umount /mnt
#
date
melcockAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

neteducationCommented:
My questions are:
1. Should the clone source be the mount point (e.g. "/") , block device (/dev/dsk/c0t0d0s0) or raw device (/dev/rdsk/c0t0d0s0)?

ufsdump takes the raw device. However if it is listed in /etc/vfstab you may also take the mountpoint, so technically seen you can take both, but I would prefer the mountpoint (it just looks nicer)

2. Do I need to clone each slice seperately, or can I use s2?

You need to do each slice seperatly.

3. If have only two disks on the system, and they are the source and target disks, where should the backing store in the pipeline reside?

While doing the root slice: on slice 7, while doing slice 7 on the root slice.

4. If I use fnsnsp unlink option, am I correct to assume I don't need to fssnap -d to remove the temporary snapshot after its use in the pipeline? Is unlink the best option to use?

Right, shouldnt need to to do fssnap -d anymore.
melcockAuthor Commented:
Thanks for that it clears up almost all my worries.

For Q3, do there need to be specific directories created for temporary storage of the backing store, e.g. /export/scratch and /scratch.  How much space is required (df-kl for each slice)?

neteducationCommented:
You dont need to create specific directories, it will simply create a file in that directory you specified. I could very well imagine that the backing store isn't used at all in your situation, the system will work like this:

From the moment on you do the snap the system will write any changes it does on the apropriate partition to new (unused) blocks on that partition and keeps the old blocks with the old data.

If another change to the same datablock is done, then the block that was written before is overwritten (still keeping the block from when the snapshot was taken).

Only if the system is running out of empty datablocks on that partition it will store the old information into the backing store.

You can specify the maximum size of the backing store using -o maxsize=500m. If you would have more changes then the system would discard the old version making the snapshot useless.

So basically if you dont have a lot of changes on many different files and only few space left over on your partition, then the backing store isn't used at all (but should still be specified)

Oh, yes and correcting my Answer4: I just tried... and you do have to do the fssnap -d afterwards. (You have chosen a good time to ask this question, I'm teaching a Solaris Admin II course right now, and I let one of the students try out :-))

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Exploring ASP.NET Core: Fundamentals

Learn to build web apps and services, IoT apps, and mobile backends by covering the fundamentals of ASP.NET Core and  exploring the core foundations for app libraries.

melcockAuthor Commented:
I have successfully updted my script to produce a backup of /export/home using fssnap, but still get errors on / (root) "fssnap: ioctl: error 16: Device busy".  

My suspision is that my backing-store in /export/home, uses a link from the source disk on root (/) i.e. /export.  What else can I use for a valid backing-store that is not on my root slice, on my two disk system?

Filesystem            kbytes    used   avail capacity  Mounted on
/dev/dsk/c0t0d0s0    22018105 2488970 19308954    12%    /
/proc                      0       0       0     0%    /proc
fd                         0       0       0     0%    /dev/fd
mnttab                     0       0       0     0%    /etc/mnttab
swap                 2039512      16 2039496     1%    /var/run
swap                 2039512      16 2039496     1%    /tmp
/dev/dsk/c0t0d0s7    8266877 1863446 6320763    23%    /export/home

Extract from script:

# recreate s0
echo "### Backup / file system using fssnap"
mount /dev/dsk/c0t2d0s0 /mnt
/usr/sbin/ufsdump 0f - \
    `fssnap -F ufs -o raw,backing-store=/export/home,unlink / ` \
    | (cd /mnt; ufsrestore rf -)
rm /mnt/restoresymtable
cd /
umount /mnt
#
echo "### Check / fssnap file & delete"
fssnap -F ufs -i /
fssnap -F ufs -d /
#

Extract from log file:

### Backup / file system using fssnap
fssnap: ioctl: error 16: Device busy
Cannot open("/dev/tty"): No such device or address
Usage: ufsdump [0123456789fustdWwnDCcbavloS [argument]] filesystem
Volume is not in dump format
/mnt/restoresymtable: No such file or directory
### Check / fssnap file & delete
Snapshot number               : 0
Block Device                  : /dev/fssnap/0
Raw Device                    : /dev/rfssnap/0
Mount point                   : /
Device state                  : idle
Backing store path            : /export/home/snapshot0 <UNLINKED>
Backing store size            : 1920 KB
Maximum backing store size    : Unlimited
Snapshot create time          : Mon Jul 11 14:07:31 2005
Copy-on-write granularity     : 32 KB
Deleted snapshot 0.
neteducationCommented:
you could put it in /tmp which is a ramdisk.
melcockAuthor Commented:
I figured out the orginal problem I was attmpting to use bs=/export/home on the disk I had just newfs'd!  fssanp rejected bs=/dev/dsk/c0t2d0s7, so as a temporary measure I mounted /dev/dsk/c0t2d0s7 as /mnt2, and used this successfully as a backing store before umounting as using the target for the second dump.  

Using /tmp as follows does not seem to work...

#mount /dev/dsk/c0t2d0s7 /mnt2
/usr/sbin/ufsdump 0f - \
    `fssnap -F ufs -o raw,backing-store=/tmp / ` \
    | (cd /mnt; ufsrestore rf -)
rm /mnt/restoresymtable
cd /
umount /mnt
#
echo "### Check / fssnap file & delete"
fssnap -F ufs -i /
fssnap -F ufs -d /

Gives:

### Backup / file system using fssnap
Cannot open("/dev/tty"): No such device or address
Usage: ufsdump [0123456789fustdWwnDCcbavloS [argument]] filesystem
Volume is not in dump format
/mnt/restoresymtable: No such file or directory
### Check / fssnap file & delete
fssnap: ioctl: error 2: No such file or directory
melcockAuthor Commented:
Any ideas for a more elegant solution thna my temorary measure?
neteducationCommented:
as far as I can see you'll have to do it with some temporary mount. I suppose on your spare drive will also have a partition for swaping. You could put a filesystem onto that partition and then use it as a backing store.

If you, for whatever reason need to boot from the spare disk, then simply the partition is used as swwapspace again
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Unix OS

From novice to tech pro — start learning today.