0

I read the word

rsync

for the first time today after looking here on sueperuser for a solution to only transfer files which have been changed.

I am working on a website with this environment:

  • local Website running with xampp (Tracked with Git & remote repo for cooperation)
  • staging website on Apache server (no git available)
  • live website on same A. server (no git)

I am just figuring out my workflow which would be something like this:

  1. pull from remote repo
  2. make changes locally
  3. upload to staging server
  4. upload to live server
  5. push to remote Repository

Now the problem is, that downloading & uploading the files takes a lot of time if I transfer the whole wordpress installation.

Is rsync the right choice as there is no GIT available? I have SSH access but really dont know what I am doing. Can somebody give hints how to set this up? I installed PuTTY a few days ago, could that help?

0

Rsync will definitely solve your problem. If you run rsync using -e "ssh <ssh params>" then it will run via an ssh connection, and under the hood, what rsync does, is it (locally) generates the file list and the delta for each of the files in that list, before comparing it against a remotely generated list, and sending files. It means even on a fast connection, it can be slow to get started, but once it's going it's quick.

I believe there is a windows cli version of rsync and ssh, if not you may want to try installing cygwin with bash/rsync/ssh. It's not a big install if you don't want much. The trick with rsync is getting the right options for what you want.

So in your example, you have stagingserver.local and remoteserver.local. Lets say your access to remoteserver is as user releaseuser. Firstly ensure you can ssh to releaseuser@remoteserver.local using putty (I suggest you setup ~releaseuser/.ssh/authorized_keys on remoteserver.local to permit you login as releaseuser using the public version of a local ssh key localkey.pub, you can set that up by creating a private key in putty-keygen and saving a openssh private/public keys as localkey and localkey.pub, then upload the public one to remoteserver.local).

Ok, so to rsync the local directory localdirectory to the remote remotedirectory, using the above:-

rsync -rave "ssh -i localkey" localdirectory/ releaseuser@remoteserver.local:/remotedirectory/

The trailing slash on each of the directory names, tells it to copy the contents of localdirectory to the directory remotedirectory rather than copy the directory itself. If you miss the trailing slash, you'll get remotedirectory/localdirectory created on the remote server

So to explain a little the options I used there were -rave (which I always find easy to remember). The -r means recursive, so descend into directories. The -a means archive, which is the same as -rlptgoD, which means basically send everything (links, permissions, times, groups, owners, Devices, but not hard-links, acls or xattrs). -v means verbose, so echo to screen what it's sending and -e specifies the rsh command (in our case ssh -i, which tells ssh which key file to use).

Hope that helps

5
  • hey sibaz thanks for your detailed answer. I just figured out that this hosting environment does only allow ssh login via username/password... But I'll give you credits anyway. – user411138 Feb 12 '16 at 22:25
  • wait.. I can do this with user/pass as well right. Dont I have to install rsync on the server first? Probably that host doesnt support that as well... *edit: They do support rsync, how do I know if I have to install it? – user411138 Feb 12 '16 at 22:32
  • rsync is an application, so that needs to exist on both sides. However, rsync can also be a protocol, but if you're using the ssh approach, then you don't need a listening rsync service (the ssh connection will run rsync if it can). You can test by ssh-ing to the target server and run rsync -h. If you get an error it might not be there (try /usr/bin/rsync before you giveup hope as the path might be wrong). – sibaz Feb 15 '16 at 12:41
  • hey sibaz, i was busy with other topics the last weeks but now I am trying it again. Actually I found out they do not support ssh via publickey so I guess I have to login with user/pass each time I connect via ssh. Could you help me set up the proper code again? – user411138 Mar 15 '16 at 16:53
  • I'm not sure how you disable ssh key login, but ok. Did you try running rsync with the above option, but with "ssh" (ie drop the -i option). If that doesn't work, I'm not sure what your hosting environment looks like, to make this work. – sibaz Mar 16 '16 at 12:17

Your Answer

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