1828490 Members
2668 Online
109978 Solutions
New Discussion

bkup script

 
SOLVED
Go to solution
Jennifer Lam
Advisor

bkup script

Hello All,
I have a working backup script just access for only one system when I do cront backup. Would you help me to have a variable set in the script that can work / apply for other system when I have a variable defined on crontab command! Thank you

This is a cront bkup command:
Ex. 0 0 * * 6 /70gig/ASI/bkscript_ravenp3 (I would like to have the ravenp3 (is a hostname) to be a variable that can apply for any system hostname when I run the script)


This is the script

#! /bin/ksh

# File: /70gig/ASI/bkscript_ravenp3
# Purpose: save all files & directories under directory /usr/ferrari, /usr/local/si,
# /usr/local/si_log, /usr/local/bin

DATE="`date`"
#SYS_NAME="ravenp3"
DESTFILE="/70gig/ASI/ravenp3/ravenp3.bk.tar"
ERROR="/70gig/ASI/error.logs"
MOUNT1="/backup_si"
MOUNT2="/backup_ferrari"
BKLOGS="/70gig/ASI/bk.logs"

# check error.log file for network no connection.

if
ping ravenp3 -n 3 | grep '3 packets transmitted, 3 packets received, 0% packet loss'
then
echo "$DATE; the system is connecting \n " >> $ERROR
else
echo "$DATE; the system is NO connecting \n " >> $ERROR
exit
fi


# check the system is mounting to the previuos system, so it needs to umount the previous syst before
# mount to the system.

if bdf | grep $MOUNT1
bdf | grep $MOUNT2
then
echo "$DATE; filesystem already mount to the previous system \n " >> $ERROR
umount $MOUNT1
umount $MOUNT2
echo "$DATE filesystem already Un-mount \n " >> $ERROR
fi

# mounting nft then tar & gzip the bkup files, finaly umount nfs

mount -F nfs ravenp3:/usr/local $MOUNT1
mount -F nfs ravenp3:/usr/ferrari $MOUNT2
tar -cvf $DESTFILE $MOUNT1/si $MOUNT1/si_logs $MOUNT1/bin $MOUNT2
/usr/contrib/bin/gzip -f $DESTFILE
umount $MOUNT1
umount $MOUNT2

echo "This is a bkscrip for ravenp3 on `date` \n " >> $BKLOGS
3 REPLIES 3
Mark Grant
Honored Contributor
Solution

Re: bkup script

I might be being a bit simple here but it looks like you are backing up by NFS mounting the required filesystems from a machine and then using tar.

If this is all you want, then the solution to your problem is really simple.

Replace the string "ravenp3" with "$1" thougout the script. Then call the scripts as
"bkscript_ravenp3 ". If this does do what you need then it might be worth renaming the script to just "bkscript"
Never preceed any demonstration with anything more predictive than "watch this"
Jennifer Lam
Advisor

Re: bkup script

Hello Mark,
Thank you for help, you give me the solution; you are a life saver. I got it work now :o).
Thanks again
Jen
Dani Seely
Valued Contributor

Re: bkup script

Great answer Mark. Sounds like you are all set Jennifer, but thought I'd throw in my 2 cents. You asked about a variable to use for your hostname. You could use $(uname -n) to print the machine's hostname. This would replace ravenp3 (your hostname that's hardcoded in your script) with the hostname that is being backed up.

Any rate, glad you got your script working.
Together We Stand!