Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 21597
  • Last Modified:

Script to copy files from one AIX server to another

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
amd2002a
Asked:
amd2002a
  • 2
  • 2
1 Solution
 
tfewsterCommented:
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
 
yuzhCommented:
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
 
GnsCommented:
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
 
yuzhCommented:
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
 
GnsCommented:
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

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now