Solved

Script to copy files from one AIX server to another

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

When you do backups in the Solaris Operating System, the file system must be inactive. Otherwise, the output may be inconsistent. A file system is inactive when it's unmounted or it's write-locked by the operating system. Although the fssnap utility…
FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
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.
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

758 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

22 Experts available now in Live!

Get 1:1 Help Now