2

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 ?

lonerunner
  • 124
  • 1
  • 4
  • 16

4 Answers4

6

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.

Sven
  • 98,649
  • 14
  • 180
  • 226
4

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?

TomOnTime
  • 7,945
  • 6
  • 32
  • 52
0

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

cd /var
tar zcf allmycircuits.tgz www
Kondybas
  • 6,964
  • 2
  • 20
  • 24
0

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?

Hauke Laging
  • 5,285
  • 2
  • 24
  • 40
  • 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. – lonerunner Feb 10 '13 at 14:57