1

I have been given the task of transferring a large (Thousands of Files) Magento Installation to a different server. Being native to Windows, I simply downloaded the files to my pc and FTP'd them back in.

However, I now realise that the permissions are all incorrect, and I can't simply do each file one by one.

Is there any way to sync/copy file permissions? I'm not sure if the users/groups must be set up the same? From the appearance I simply need the Numberical permissions to be correct.

They are completely separate Servers, and the files/folders will be identical. Ubuntu 12.04 is the OS on the "new" server.

1
  • You may be interested in taking a look at the result of this command. man cp
    – user147505
    Feb 9, 2016 at 12:10

3 Answers 3

2

On Linux, you can back up and restore ownership and permissions (including access control lists but not SELinux contexts) with the ACL tools. Run getfacl -R >permissions.txt in the toplevel directory on the machine with the correct permissions. Copy over the output file to the target machine and run setfacl --restore=permissions.txt in the toplevel target directory.

If you need to copy ownership as well as permissions, you'll need to do the restore part as root.

1

You probably want to use rsync. To get that to work, you need to install it on both machines (if it's not installed already). After that, simply run (as root):

rsync -avrHP root@source-host:/path/to/source-directory/ /path/to/destination

this assumes that:

  • You run the command on the destination host. If you want to run it on the source host, just remove the root@source-host: part from the first argument, and add a root@destination-host: argument to the second one. Note: it is not possible to run rsync with two remote hosts; only one of the ends can be a "remote" end.
  • Logging in over ssh as root is at all possible. The common thing to do these days is to disable such access, for reasons of security. However, in order for rsync to be able to actually copy permissions, it needs to run as root on both ends. If it is disabled, check out /etc/ssh/sshd_config, looking for PermitRootLogin. If it is set to no, switch it to yes and restart sshd. Don't forget to disable it again after copying the files!
  • The users who have ownership on files in the source host all exist on the destination host. If not, some permission bits may be copied incorrectly.

Note that you do not need to remove your already-copied files first. Rsync will detect that the files exist, but synchronize the permissions. If there are some files which have changed since they were copied, rsync will also synchronize their contents.

1
  • Brilliant Answer, only problem is is that the original files are on a Shared box to which I have no SSH access. I will have to speak to the host company or think of a alternative somehow. Thanks for all the information anyway! Feb 9, 2016 at 12:15
0

Run as root rsync -og maybe this is what you are looking for.

From manpage:

-o, --owner
              This option causes rsync to set the owner of the destination file to be the same as the source file, but only if the receiving rsync is being run as the super-user (see also the --super and --fake-super options).  Without this option,  the  owner  of
              new and/or transferred files are set to the invoking user on the receiving side.

              The preservation of ownership will associate matching names by default, but may fall back to using the ID number in some circumstances (see also the --numeric-ids option for a full discussion).

       -g, --group
              This option causes rsync to set the group of the destination file to be the same as the source file.  If the receiving program is not running as the super-user (or if --no-super was specified), only groups that the invoking user on the receiving side
              is a member of will be preserved.  Without this option, the group is set to the default group of the invoking user on the receiving side.

              The preservation of group information will associate matching names by default, but may fall back to using the ID number in some circumstances (see also the --numeric-ids option for a full discussion).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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