Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Im migrating to new server and i need to move few websites but i need to have same read/write permissions to new serves as they were on old server.

I don't need to keep group and owner id's same but it would be very hard if i have to go through all files on old server and check what are read/write permissions on folders and files than to set on new server.

My idea is to pack files copy to new server and unpack, but that somehow reset all permissions to default with 644 to files and 755 to folders. Can i somehow transfer files and folders with same permissions as they were on old server ?

share|improve this question
    
rsync could do this and I think scp do the same thing. –  user21485 Feb 10 '13 at 14:19
add comment

4 Answers

up vote 2 down vote accepted

Just use rsync:

rsync -avz /path/to/files newserver:/path_to_files 

This will recursively copy all files from /path/to/files on the old server to /path_to_files on the new server and keep permissions and owner informations. For more informations, see man rsync.

share|improve this answer
    
Yes this is exactly what i needed rsync copy all files with right permissions. Thanks for your answer. –  Aleksandar Đorđević Feb 10 '13 at 15:02
add comment

Before rsync existed here's a trick that is worth knowing. Sometimes you find yourself on a system without rsync.

The trick is to make a tar file of the files, copy the file to the new server, then extract the tar file with -p to preserve the file permissions.

"But wait!" you ask. "That temporary file might be huge! Bigger than the free space that I have!" Don't worry. You can write connect the two tars by a pipe and you don't need a temporary file, nor the disk space! To specify stdin or stdout specify the file name - (hyphen).

Putting that all together:

cd $SRCDIR
tar -c -v -f - . | ssh $DEST_HOST "mkdir -p $DESTDIR && cd $DESTDIR && tar -x -p -f -"

For example:

cd /home/user12
tar -c -v -f - . | ssh other.example.com "mkdir -p $DESTDIR && cd /home/user12 && tar -x -p -v f -"

The && is like ; (semicolon) but it means "only execute the next command if this one was successful."

Remember that you have to do this as root if you want to copy the file owner:group too. Your normal user account usually can't chown a file, so neither can tar. The command will work even if ssh is going to ask for a password because ssh is smart enough to not connect the pipe until the login is complete.

Note: tar will update the permissions on all files except the root directory because it didn't create it. You created it with the mkdir -p. You can fix this if you use tar to capture the directory instead of ".". Here's the last example repeated in a way that will update the permissions on "user12":

cd /home
tar -c -v -f - user12 | ssh other.example.com "mkdir -p /home && cd /home && tar -x -p -v f -"

See the difference?

share|improve this answer
add comment

If you have linux/unix you can use tar that effectively store file permissions, ownership and softlinks.

cd /var
tar zcf allmycircuits.tgz www
share|improve this answer
add comment

My idea is to pack files copy to new server and unpack, but that somehow reset all permissions to default with 644 to files and 755 to folders.

Have you experienced that permissions are set to 644/755 or are you just afraid of that? If the former: What have you done?

BTW: If such a problem has occurred: It is possible to just replace access rights:

getfacl --recursive . > acl.txt
# and then on the other system or at the other path
setfacl --restore=acl.txt

Do you know how to correct the UIDs/GIDs?

share|improve this answer
    
I have experienced permissions set to defaults i used tar and zip options to pack files copy to new server and unpack and permissions and owners are set to defaults of new server. SvenW option to use rsync is good, now i just set owner rights of new server user. –  Aleksandar Đorđević Feb 10 '13 at 14:57
add comment

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.