Sign up ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

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

  • 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.

share|improve this question
    
Not connected so you're looking for some offline approach (e.g. create tar file) ? –  steve yesterday

2 Answers 2

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
share|improve this answer

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.

share|improve this answer
    
This breaks if there is a directory with a carriage return in its name, though that's probably rare enough it can be handled manually. –  drewbenn yesterday
1  
True. If handling this is necessary, you can use -printf '%p\0%m\0' and read -d ''. –  Tom Hunt yesterday

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.