Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

can anyone help me in making a unix script for this

Status
Not open for further replies.

bhasin

Technical User
Jul 2, 2003
2
AU
i am having 5 solaris 2.6 workstations , out of these i want to use one as a back workstation for some important files , those ment to be backuped weeky from other 4 workstations. i am able to telnet all these workstations. can anyone help me in making a unix script using telnet for these purose which automatically run once a week and copy the particular files on the required station.
 
Better to use ftp to copy files to workstation 5.

Greg.
 
Grega's right. I don't know how detailed you need this to be.

Assuming the files you want to send to the backup workstation are always the same or always in the same directory, you could write a very simple script to tar the files you want to back up and then compress the tar file. Then you can ftp the compressed tar file to the backup workstation.

The part for the ftp would be:

ftp -n {ipaddress or name of backup workstation} <<EOF
user {username on workstation} {password of username}
cd {/directory to hold the compressed files}
binary
put {name of compressed tar file}
EOF


 
Try to do that by cron job. It may has a security issue to provide the password in a file for ftp.

In Host:
su - root
crontab -e
#Add a routine job as follows:
#Copy files from 4 clients to local at 1:00am every Sunday
0 1 * * 0 rcp [client1 IP]:/tmp /tmp/backup1
0 1 * * 0 rcp [client2 IP]:/tmp /tmp/backup2
0 1 * * 0 rcp [client3 IP]:/tmp /tmp/backup3
0 1 * * 0 rcp [client4 IP]:/tmp /tmp/backup4

In all Clients:
su - root
vi /.rhosts
[Host IP] root
 
Tikul,
Thanks for paying your attention as I am very new to solaris and scripting , Infact there is particular directory in all the 4 workstations to be backed up. How i can give the tar command at each workstation and if you can be more discriptive it will be highly appriciable.
Like what I presume in your hint HOST means the 5th workstation where I am storing the backup. and root means its password is it ?
What and where I have to write the indivisual scripts in all the 4 workstations to TAR the directory fortnightly in those workstations .Can u please help me out in step by step procedure , that will be very easy for me.
 
Try


Assume you have five work satations a, b, c, d, e

Your backup server is 'e'

Make 4 directories in the host 'e'(backupserver)

Example:#/backup/aback
#/bcakup/bback
#/backup/cback
#/backup/dback

Write a script to copy files from host 'a'

rcp -r source hostname:destination
Example:
rcp -r /a/file1 e:/backup/aback/
rcp -r /a/file2 e:/backup/aback/
rcp -r /a/file3 e:/backup/aback/
...............................
...............................
rcp -r /d/file3 e:/backup/dback/

Where -r option copies recursively.

schedule this script into crontab file.
Do same for remaining workstations.

Can you do rsh to all systems?


Hope this helps..


 
You can also create a cron job in 4 clients then back it up to the host as previous method.

Example:

su - root

1) In 4 clients (Do it in the machines respectively)
#Any directory you like to store the content file.
vi /usr/local/bin/filecontent
#Name of file/directory that you wanted to backup. One per line.
/tmp/abc.txt
/export/home/myhome

2) In 4 clients (Do it in the machines respectively)

vi /usr/local/bin/tarfile.sh
#This simple shell script helps you to tar the file named as 'hostname.tar.date' format. e.g. if the hostname of client is &quot;client1&quot;. Then the filename will be &quot;client1.tar.04Jul&quot;
BASEDIR=/usr/local/bin

/usr/bin/tar cf /tmp/`hostname`.tar.`date +%d%b` -I $BASEDIR/filecontent

#Remove the tar files over 30 days. Because you should aware the directory full!!

find /tmp -name &quot;`hostname`.tar*&quot; -mtime +30 -exec rm {} \;

######After created this file, run 'chmod 744 tarfile.sh' ######


3) In Host
vi /usr/local/bin/get_all_file.sh
#Get the latest tar file from client and then store it to local /tmp directory.
for i in [client1 IP] [client2 IP] [client3 IP] [client4 IP] [client5 IP]
do
y=$(rsh ${i} ls -t1 /tmp/client1.tar* | head -1)
rcp ${i}:${y} /tmp
done

#You may add a 'find' method to housekeep the directory too. Let it done by yourself.

######After created this file, run 'chmod 744 tarfile.sh' ######

4) In Host
#The following cron job will run the script every Sunday and provides a log for your reference.
0 1 * * 0 /usr/local/bin/get_all_file.sh > /tmp/logfile.`date +%d%b` 2>&1


End
 
oh sorry, missed one point between point 2 and point 3.

You need to create a cron job in 4 machines respectively. But I think that you are able to do it by yourself now.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top