Solved

Script to copy files from one AIX server to another

Posted on 2004-09-16
5
21,270 Views
Last Modified: 2013-11-17
I am looking for an easy script that I can use to copy all of the files and folders in a directory on one server to a directory on another server. The script will be run on the destination and will be invoked by an ANT script. The script can use ftp or any secure medium (scp etc.). Rsync is not an option because it is not installed on either server. The script should be able to accept username, password, server, destination folder, and source folder from the command line. Transfer must be done in binary mode (ftp). The first answer that works in my ant script will get the points. I'm not a AIX/Unix head so forgive me if any of my terminology is off.
0
Comment
Question by:amd2002a
  • 2
  • 2
5 Comments
 
LVL 20

Accepted Solution

by:
tfewster earned 250 total points
ID: 12078902
Automating ftp - See
http://www.experts-exchange.com/Programming/Programming_Platforms/Unix_Programming/Q_10292843.html

Create a tar file on the source server by cd'ing to the source directory, then using `tar -cvf tarfile.tar .`
(This bit can be automated too, if it has to be driven from the target server)

On the target server:
#!/bin/sh
echo "Enter source server"
read SOURCESERVER
echo "Enter source folder"
read SOURCEDIR
echo "Enter target folder"
read TARGETDIR
echo "enter username"
read USERNAME
echo "enter password"
read PASSWORD

ftp -n $SOURCESERVER <<!
     quote user $USERNAME
     quote pass $PASSWORD
     binary
     cd $SOURCEDIR
     lcd $TARGETDIR
     get tarfile.tar
     quit
!

cd $TARGETDIR
tar -xvf  tarfile.tar .
0
 
LVL 38

Expert Comment

by:yuzh
ID: 12082212
why not just simply use ssh + tar:

eg. copy files under /data in remote box to your local machine:

cd /backup-dir
ssh user@remote "(cd /data; tar cf - .) | tar xvf -

you can setup ssh login without password, or use "expect" to handle the job,
please have a look at:
http:Q_20473712.html

setup ssh without password:
http://linuxproblem.org/art_9.html
http://www.cvrti.utah.edu/~dustman/no-more-pw-ssh/
http://www.csua.berkeley.edu/ssh-howto.html
0
 
LVL 20

Expert Comment

by:Gns
ID: 12083848
Ehm Greg, with that reasoning... what's wrong with scp directly?
scp -rp user@sourcehost:/path/to/source [possibly_user@destinationhost:]/path/to/destination
would perhaps be all that's needed:-). True, the source owner.group would not survive, but then, it's very possible that it woulödn't eb valid on destination anyway.

Or am I being unbearably dense here?

-- Glenn
0
 
LVL 38

Expert Comment

by:yuzh
ID: 12099078
Hi Glenn,

    It is personal preference. I prefer to use tar OVER cp/rcp/scp commands for backup files
it keep the file permisions, this will become very handy when you need to put the files back
to where it come from (restore!).
 
   >>"the source owner.group would not survive"
    the answer is "Yes" and "No", if the user ID is differ between two box, then the file
permission will not make much sense for the backup machine, if you need to tar it back
to the source machine it make sense.

    I used to NIS/NIS+ LDAP, it make sense in NIS/NIS+ LDAP ENV.

    BTW, if it is a on going backup, use rsync instead of tar, please have a look at:
    http://rsync.samba.org/

0
 
LVL 20

Expert Comment

by:Gns
ID: 12100682
Good to see we agree (although reach slightly different results:) Greg. In this particular case the detour over tar isn't really necessary, but I generally would agree that tar is the better tool for storing backups;-).
Rsync was disqualified from the outset.

-- Glenn
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A metadevice consists of one or more devices (slices). It can be expanded by adding slices. Then, it can be grown to fill a larger space while the file system is in use. However, not all UNIX file systems (UFS) can be expanded this way. The conca…
I have been running these systems for a few years now and I am just very happy with them.   I just wanted to share the manual that I have created for upgrades and other things.  Oooh yes! FreeBSD makes me happy (as a server), no maintenance and I al…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now