Solved

Script to copy files from one AIX server to another

Posted on 2004-09-16
5
21,281 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

In tuning file systems on the Solaris Operating System, changing some parameters of a file system usually destroys the data on it. For instance, changing the cache segment block size in the volume of a T3 requires that you delete the existing volu…
My previous tech tip, Installing the Solaris OS From the Flash Archive On a Tape (http://www.experts-exchange.com/articles/OS/Unix/Solaris/Installing-the-Solaris-OS-From-the-Flash-Archive-on-a-Tape.html), discussed installing the Solaris Operating S…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

786 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