2

I would like to know best way to copy directory structure from one server(Unix) to another (Linux):

  • without root user
  • servers are not connected (e.g. can't use SSH directly between them)
  • I need to copy only folders and subfolders, without files
  • permissions on folders must also bi transferred

So i have user@server1 with some directory structure. I need to copy this structure to user@server2 without files, with same permissions. Users on both servers have same permissions and are in the same group, servers are not connected.

Edit: I forgot to mention that server1 is Unix, and server 2 is Linux. So when I try to execute proycon's code on Unix server I got message: tar: Not a recognized flag: z When I try Tom Hunt's option I got message: -printf is not a valid option. Also, worth to mention, user have different names, although they have same rights and are in same group. So I have user_xy@server1 and user_zx@server2

1
  • Not connected so you're looking for some offline approach (e.g. create tar file) ?
    – steve
    Sep 25, 2015 at 20:50

2 Answers 2

3

Ideally you'd do something like rsync or scp, but then the machines would indeed have to be connected. I'd go for using tar with find instead if you have no means of direct transfer, it can preserve users, permissions, and symlinks.

On one host:

$ find yourdirectory/ -type d | tar -cvzf archive.tar.gz --no-recursion --files-from -

Transfer the archive by any means (ftp? USB stick? smoke signals?)

On target host:

$ tar -xvzf archive.tar.gz
2

On server1:

find . -type d -printf '%p\n%m\n' >dir_list

Transfer the file dir_list from server1 to server2 however you see fit.

On server2:

while read -r filename; do
    read -r perms
    mkdir -p "$filename"
    chmod "$perms" "$filename"
done <dir_list

This will create all the directories owned by the user you run as on server2. Changing the ownership cannot be done without superuser.

2
  • 1
    True. If handling this is necessary, you can use -printf '%p\0%m\0' and read -d ''.
    – Tom Hunt
    Sep 25, 2015 at 21:44
  • Hi, thanks for answers. Yes, both answers would be what I need. I forgot to mention that server1 is Unix, and server 2 is Linux. So when I try to execute proycon's code on Unix server I got message: tar: Not a recognized flag: z When I try Tom Hunt's option I got message: -printf is not a valid option. Also, worth to mention, user have different names, although they have same rights and are in same group. So I have user_xy@server1 and user_zx@server2
    – botafogo
    Sep 27, 2015 at 14:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .