LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Other *NIX Forums > Solaris / OpenSolaris
User Name
Password
Solaris / OpenSolaris This forum is for the discussion of Solaris, OpenSolaris, OpenIndiana, and illumos.
General Sun, SunOS and Sparc related questions also go here. Any Solaris fork or distribution is welcome.

Notices


Reply
  Search this Thread
Old 02-12-2009, 12:06 PM   #1
tuxtutorials
Member
 
Registered: Dec 2008
Location: New York
Distribution: RedHat, Solaris
Posts: 68

Rep: Reputation: 16
Scrutanize shell ufsdump backup script


Hello guys, I was wondering if you could give me some feedback on a shell script I wrote to dump our systems to disk. It works but I would like to know how to make it better and more efficient. Perhaps less lines of shell code if possible. I would like to write better shell scripts so any suggestions would be helpful.

Here is the script.

Code:
#!/usr/bin/bash
#Date: 12-02-08
#Author: tuxtutorials
#Purpose: Dump all file systems to NFS mount for local os backups


global=`hostname | awk -F. '{ print $1}'`
netmnt=backuphost:/export/backup
localmnt=/ufsbackup
date=$(date +%m%d%y%S)
log=/var/adm/backup.log

vol="`df -F nfs | grep "/export/backup"`"
stat=$?

echo "Starting dump on $date" >> $log 2>&1

#Tests to see if ufsbackup dir is created
if [ -d $localmnt ] 
then
echo "$localmnt Directory exists" >> $log 2>&1
else 
echo "Directory does not exist" >> $log 2>&1
mkdir $localmnt
fi
#Tests to see if netapp vol mounted
if [ $stat != "0" ]
then
echo "$netmnt is not mounted" >> $log 2>&1
echo "$netmnt is being mounted to $localmnt" >> $log 2>&1
mount $netmnt $localmnt
else
echo "$netmnt is already mounted" >> $log 2>&1
fi

if [ -d $localmnt/$global ]
then
echo "NFS $global directory Exists" >> $log 2>&1
echo "Dumping vtoc" >> $log 2>&1
if [ -f /$localmnt/$global/*.vtoc ]
then
echo "vtoc exists" >> /dev/null
else
prtvtoc /dev/dsk/c0t0d0s2 > /$localmnt/$global/$global.$date.vtoc
fi
#
echo "Dumping filesystem" >> $log 2>&1
ufsdump ${1}uf $localmnt/$global/$global.root.$date.ufs${2} / >> $log 2>&1
echo "Exit status is:$?" >> $log 2>&1
#
ufsdump ${1}uf $localmnt/$global/$global.var.$date.ufs${2} /var >> $log 2>&1
echo "Exit status is:$?" >> $log 2>&1
#
ufsdump ${1}uf $localmnt/$global/$global.usr.$date.ufs${2} /usr >> $log 2>&1
echo "Exit status is:$?" >> $log 2>&1
#
ufsdump ${1}uf $localmnt/$global/$global.export.$date.ufs${2} /export >> $log 2>&1
echo "Exit status is:$?" >> $log 2>&1
#
echo "Dump Done" >> $log
#
else
echo "Making directory on NFS mount" >> $log 2>&1
mkdir -p $localmnt/$global
echo "Dumping vtoc" >> $log 2>&1
if [ -f /$localmnt/$global/*.vtoc ]
then
echo "vtoc exists"  >> /dev/null
else 
prtvtoc /dev/dsk/c0t0d0s2 > /$localmnt/$global/$global.$date.vtoc
fi
#
echo "Dumping filesystem" >> $log 2>&1
ufsdump ${1}uf $localmnt/$global/$global.root.$date.ufs${2} / >> $log 2>&1
echo "Exit status is:$?" >> $log 2>&1
#
ufsdump ${1}uf $localmnt/$global/$global.var.$date.ufs${2} /var >> $log 2>&1
echo "Exit status is:$?" >> $log 2>&1
#
ufsdump ${1}uf $localmnt/$global/$global.usr.$date.ufs${2} /usr >> $log 2>&1
echo "Exit status is:$?" >> $log 2>&1
#
ufsdump ${1}uf $localmnt/$global/$global.export.$date.ufs${2} /export >> $log 2>&1
echo "Exit status is:$?" >> $log 2>&1
#
echo "Dump Done" >> $log
fi
cd /
umount /ufsbackup
exit

Thanks

Last edited by tuxtutorials; 02-12-2009 at 12:08 PM.
 
  


Reply



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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Backup Shell Script soad789 Programming 6 12-08-2007 06:35 AM
shell backup script help needed Quakeboy02 Linux - Software 4 04-26-2007 05:20 PM
shell backup script xtremeclones Linux - Software 3 10-03-2006 02:13 PM
Shell Script for backup BBQ_Matt Linux - Software 7 06-30-2005 05:19 PM
Incremental Backup shell script. datadriven Linux - General 3 06-02-2004 09:19 AM

LinuxQuestions.org > Forums > Other *NIX Forums > Solaris / OpenSolaris

All times are GMT -5. The time now is 09:46 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration