Sie sind auf Seite 1von 4

MANUAL FOR AUTOMATED BACKUP THROUGH NFS

---------------------------------------

Things to Do:-
Here are two script file coding is given you have to
copy its content to a new file with server_copy.sh
and client_copy.sh respectively..

Scripts :-
1. server_copy.sh
2. client_copy.sh

NOTE
-----
- During script execution pay special attention to the output.
- Jot down all the enteries which you enter during the script running
as undoing is not possible after any entered text
- Do not rename client_copy.sh
- Do not confuse with Client or Slave keywords both reference to the
Second machine
- This script is made to take backup hourly...

NEED
-----
The basic need for this type of backup is concerned for few machines.
Where Server will be your main Machine which has important data and
Slave(Client) machine which will required when main machine some how
stop working.

DISCLMAIR
----------
I have run these scripts on RHEL5 machines and never got stuck, but i'm
not guranteed with other Linux machines so i will not be responsible
for any damage to your machine or leak of data. So you have to run
these scripts on your own risk.

For any suggestion, queries and bugs you are always welcomed at
sachan13b.piyush@gmail.com

HOW TO START
------------
- Copy both .sh files to the main server then execute server_copy.sh
# sh server_copy.sh
or,
# ./server_copy.sh

---------------------------------
SCRIPTS
-----------------------------------
--
----------------------------------------

----------------------------------------
---------------------------------
server_copy.sh
-------------------------------------

#!/bin/bash
#Date : 14-Sep-2009
#email: sachan13b.piyush@gmail.com
#
#Sharing data in network
#
DEFPERM=755
echo -e "Note: Use absolute path\n\tEnter the path of your backup
folder : \c"
read NFS

until echo $NFS | grep -v /$ > /dev/null


do
echo -e "Do not use '/' at the end of backup folder name.."
echo -e "Again enter the path of your backup folder : \c"
read NFS
done

echo -e "\tAllowing a single machine for nfs share give ip : \c"


read CIP
if [ -z "$CIP" ]; then
CIP='*'
fi

echo -e "$NFS\t$CIP(ro,sync)" >> /etc/exports

echo -e "Default persmission $NFS will change to 755 \n\tEnter


permission to modify : \c"
read NFSPERM
if [ -n "$NFSPERM" ]; then
DEFPERM=$NFSPERM
fi
chmod $DEFPERM $NFS
#
#This will start all services related to NFS
#
exportfs -a
chkconfig nfs on
chkconfig portmap on
service portmap restart
service nfs restart
#
#Check status of nfs share
#
showmount -e
showmount -e | grep $NFS > /dev/null
STATUS=$?
if [ "$STATUS" -eq 0 ]; then
echo -e "NFS share is correct Now we r going to login in Slave machine"
else
echo -e "NFS share enteries are somehow wrong ...Program Exiting
..\nRe-run the script...!"
exit
fi
#
#Copy client_copy.sh to slave server
#
echo -e "Note: For this 'sshd' service must be on slave server\n\tEnter
ip of slave machine : \c"
read SLIP
scp client_copy.sh $SLIP:/root/
echo -e "Now you are going to login in Slave server - After login run
'sh client_copy.sh'\nType Ctrl+D to exit from Slave Server"
ssh $SLIP

----------------------------------------
---------------------------------
client_copy.sh
-------------------------------------

#!/bin/bash
#Automated backup - Slave machine
#Date : 14-Sep-2009
#email: sachan13b.piyush@gmail.com
#
echo -e "Note: Use absolute path\n\tType the folder name to access
backup : \c"
read CDIR
mkdir -p $CDIR
#
#Adding entry in /etc/fstab file
#
echo -e "\tType the nfs server IP : \c"
read SIP
echo -e "\tType the Server's nfs share path :\c"
read NFSHARE
echo -e "$SIP:$NFSHARE\t$CDIR\tnfs\tdefaults\t0 0" >> /etc/fstab
#
#This will start all services related to NFS
#
chkconfig netfs on
chkconfig nfslock on
chkconfig portmap on
service netfs restart
service nfslock restart
service portmap restart
#
#mount NFS folder - I guess it already mount the folder of /etc/fstab
after restarting nfs services but to sure use this command
#
#mount $CDIR
#
#Create Backup folder or specify an existing one, don't bother on error
if folder exists
#
echo -e "Note: Use absolute path\n\tEnter the folder name where backup
to be taken : \c"
read CCP
mkdir -p $CCP
#
#Setting crontab in /etc/cron.hourly/
#
echo -e "\tType a new name for your crontab file : \c"
read CRONFILE
echo $CDIR | grep /$ > /dev/null
STATUS=$?
if [ "$STATUS" -eq 0 ]; then
echo -e "cp\t-arf\t$CDIR.\t$CCP" >> `echo "/etc/cron.hourly/$CRONFILE"`
else
echo -e "cp\t-arf\t$CDIR/.\t$CCP" >> `echo "/etc/cron.hourly/$CRONFILE"`
fi

chmod 755 /etc/cron.hourly/$CRONFILE


#
#Restarting cron daemon services
#
chkconfig crond on
service crond restart

Das könnte Ihnen auch gefallen