Need to copy a directory structure from one server to another

Hello All,

I have got a dev server and a production server will call it as D server and P server.

I have a dir structure in my D server and i need to create the same dir structure in P server also using a shell script.

If i do a find . in my D server, i am getting an o/p like :-

.
./vio
./vio/common
./vio/common/esr_begin
./vio/common/esr_end

.... and so on .. D server contains directories like :-

drwxrwxr-x  23 smbnull    sys           4096 Feb 23 03:13 aix
drwxrwxr-x   3 smbnull    sys           4096 Feb 22 04:52 hpux
drwxrwxr-x   3 smbnull    sys           4096 Feb 22 05:02 linux
drwxrwxr-x   3 smbnull    sys           4096 Feb 23 09:41 vio

Inside this lot of other dir/files ..

So I need to create files and directories (with same content)as we can see in D server to P server. I am using a mail parsing mechanism to create files and directories in P server. It is like :-

cat default.cfg | mailx -s "ESR MANIFEST /scripts/sys/hostupd/ESR10.2/aix/default.cfg" mailid

My worry is how will i create the exact file/dir structure ..?

Thanks in advance
Renjesh

The tar command is your friend. No need to elaborate a bunch of scripts for this task.

on D server got to place where you did find command

$ tar zcvf  vio.tgz vio/

if you have scp/rcp/ftp allowed it is much easier
copy all the files to P server

if you have to mail ... remember you cannot mail like you do for text file.
you need to encode the file before you email.

uuencode vio.tgz vio.tgz  | mail chakrapani@newsasnow.com -s "Dev dump" 

now on production server

$ tar zxvf  vio.tgz

Please note command carefully
tar - create tar archive
z - Gzip it
c - CREATE (which is done on DEV D server)
v - verify show what it has done ...
f -- file to be used
x - extract (which is done on PROD server)

if you need a script decide how files are compressed and rcvd on production. also verify userid permission etc before you copy etc ...

there are easier ways like rsync to copy files and cvs/version control etc to make it structured ...

Let me know if you need more help ...

mkdir -p

your full path of directories

No, I have to do email parsing since i dont have access to P server. I can only use email parsing...

I have got the idea but dont know how to implement ..

Algorithm will be like :-

1) find . will give all the files and dir in the desired location
2) store the o/p to an array
3) if it is a dir --> use parsing method to create dir
4) if it is a file --> use parsing method to create file

and so on ..

This is the logic i want ..
Please help me out to complete this since i am not familiar with array and all ....

Thanks
Renjesh.

Only copy a directory structure

on D server:

find . -type d > folder.list

on P server:

cd /DIR
cat folder.list |xargs mkdir -p
1 Like

It is not possible since i dont have access to create folders or dir in P server...

Please tell me how to read entries into an array .
Example :-

/opt/src
/etc/sys
...
...
I need to store "/opt/src" as first element in the array and "/etc/sys" as second and so on ..
Then I need to check if the first element in the array is a dir .. then i will use email parsing to create the same in p server ..

Please suggest ..

Thanks
Renjesh Raju

How you can create as you stated above,in this case as well if you don't have permissions on Production server?

I just want to thank to rdcwayx because his response was great for me.

Further to the good point made by "panyam".

Do you have unrestricted "root" access to Shell on both servers? If not, what access do you have?

What is the full hierarchial directory of the "vio" directory mentioned in post #1 ? Can you create directories and files under the parent directory on the target computer?

What in unix command terms is "email parsing".

Are you using some sort of enhanced unix mail on both servers? This question is about whether you can save a file attachment directly to the target server or have some other method in mind.

How big is the "vio" directory?

Does every file and directory owner have the same unix UID and GID on the source and target computers? This is so important when moving archives from one unix server to another. There are advanced techniques which include sorting out the UID and GID issues before creating the archive.

What Operating System and version are the source and target computers?
What Shell do you use on the source and target computers?

Footnote: Depending on what Operating Systems are revealed I'd be more likely to use "cpio" than "tar" because "cpio" will archive any type of file.