Need to copy a directory structure from one server to another


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need to copy a directory structure from one server to another
# 1  
Old 03-08-2011
Error 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 :-
Code:
.
./vio
./vio/common
./vio/common/esr_begin
./vio/common/esr_end

.... and so on .. D server contains directories like :-
Code:
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 :-
Code:
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

Last edited by Franklin52; 03-08-2011 at 03:10 AM.. Reason: Please use code tags, thank you
# 2  
Old 03-08-2011
Quote:
Originally Posted by Renjesh
So I need to create files and directories (with same content)as we can see in D server to P server.
The tar command is your friend. No need to elaborate a bunch of scripts for this task.
# 3  
Old 03-08-2011
on D server got to place where you did find command
Code:
$ 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.

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

now on production server

Code:
$ 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 ...
# 4  
Old 03-08-2011
Code:
mkdir -p

your full path of directories
# 5  
Old 03-08-2011
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.

Last edited by Renjesh; 03-08-2011 at 05:49 AM..
# 6  
Old 03-08-2011
Only copy a directory structure

on D server:

Code:
find . -type d > folder.list

on P server:

Code:
cd /DIR
cat folder.list |xargs mkdir -p

This User Gave Thanks to rdcwayx For This Post:
# 7  
Old 03-08-2011
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

Last edited by Renjesh; 03-08-2011 at 09:50 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Copy Directory Tree from one Server to Another

Hi, I have a serverA with Directory "/opt/app/myfiles" which is 8.5GB with more than 40000 files and 45 folders in it. I wish to transfer the folder "/opt/app/myfiles" tree structure with all the sub-directories and skip all files to another serverB. I would appreciate a command that... (4 Replies)
Discussion started by: mohtashims
4 Replies

2. Shell Programming and Scripting

Copy a directory from a server (UNIX) to a PC (Windows)

Hello, I already do some question about this topic. I already establish the conection from the server (Centus) whit the windows PC using SSH. Now I have two problems: 1- The server always ask me about a password to copy the files to the windows pc, I don't know how to avoid this, if someone can... (2 Replies)
Discussion started by: yeestrada
2 Replies

3. UNIX for Dummies Questions & Answers

Linux Server Network Settings - Share Directory Structure

Hello Unix Gurus Who I Hope Reads This, I have quasi-inherited control over a Linux cluster at a university research lab. The post-doc that set it up is gone, and the person in charge of administering the cluster doesn't know a ton about Linux. Amongst other things, I want to use the cluster... (0 Replies)
Discussion started by: mbl
0 Replies

4. Shell Programming and Scripting

copy the latest file in the remote server's directory

Hi Expert Team, I performed the below piece of code to copy the latest file in the remote server's directory to the same server's other directory. But it is not working properly. How can i handle this? Can you please help me..? ssh ${REMOTE_USERID}@${REMOTE_HOSTNAME} "cp -p `ssh... (3 Replies)
Discussion started by: spkandy
3 Replies

5. Shell Programming and Scripting

copy directory structure to a system on the network

I am trying to write a script which has to copy the directory structure from my system to another system on the network. But I dont want the files to be copied. I think I have to start with copying all subdirectories names in a directory to a system on the network. Here's the case: Source... (1 Reply)
Discussion started by: firefox211
1 Replies

6. Shell Programming and Scripting

Recursion to Copy a Directory structure

I have the below code to recurse through a given file path. I am able to go to the leaf level once recursively but traversing out is not possible as the required varaibles don't have the values on return. Both typeset and local don't work for my variable definitions. I have the o/p of the sample... (2 Replies)
Discussion started by: avrkiran
2 Replies

7. UNIX for Dummies Questions & Answers

copy files with directory structure

i have a text file as. /database/sp/NTR_Update_Imsi_List.sql /database/sp/NTR_Update_Imsi_Range_List.sql /database/sp/NTR_Vlr_Upload.sql /database/tables/StatsTables.sql /mib/ntr.mib /mib/ntr.v2.mib /scripts/operations/ntr/IMSITracer.ph /scripts/operations/ntr/IMSITracer.pl ... (3 Replies)
Discussion started by: adddy
3 Replies

8. UNIX for Advanced & Expert Users

MV files from one directory structure(multiple level) to other directory structure

Hi, I am trying to write a script that will move all the files from source directory structure(multiple levels might exist) to destination directory structure. If a sub folder is source doesnot exist in destination then I have to skip and goto next level. I also need to delete the files in... (4 Replies)
Discussion started by: srmadab
4 Replies

9. UNIX for Dummies Questions & Answers

Copying a Directory Structure to a new structure

Hi all Is it possible to copy a structure of a directory only. e.g. I have a file with the following entries that is a result of a find :- /dir1/dir2/file.dbf /dir1/dir2/dir3/file1.dbf /dir1/file.dbf I want to copy these to a directory and keep the structure however starting at a new dir... (8 Replies)
Discussion started by: jhansrod
8 Replies

10. UNIX for Dummies Questions & Answers

any idea to copy directory structure

I want to copy the durectory structure having subdirectories in it ... would be greatful if anyone could let me know .. thanks in advance (6 Replies)
Discussion started by: myelvis
6 Replies
Login or Register to Ask a Question