Deploy Static Website - Rsync on Windows
Rsync almost a standard for remote syncing, but on Linux. The VPS this site is on is Linux, but I work on Windows 8 which in the end made syncing a bit more complicated to set up. The post is for everyone who will also want to sync his generated static website synchronized from Windows to Linux.
Hexo - static blog generator that I use - has built in support for rsync, but it will now work properly from Windows machine out of the box. The problem is that on Windows the rsync command must be a little different to work properly (not to mention you have to install rsync).
Preparations
In the description I assume you use Putty to communicate with your VPS or similar system and you use a SSH key. Putty and plink.exe are de facto standard on Windows when dealing with SSH.
Download and Install rsync
Rsync for Windows is from this location. The site is in German but you will find there a link to rsync.zip. Unpack the archive to any directory. As I use it to only to sync the blog, I’ve put it with all other blog generation files.
Download and Install ssh
As I mentioned before if you already have SSH keys set up with plink.exe and pagent.exe, it would be nice to just ose them with rsync. The problem is that rsync asks for ssh
executable. Ths solution is to use a special ssh that in reality uses Putty’s toolchain. Download the ssh.exe file, put it in Windows folder and run it with administrative privileges (it is required only for the first time as it creates additional file). From now you get something that behaves like standard ssh from Linux but under the hood uses plink.exe.
Make the Sync
After all the preparations synchronizing with remote directory on Linux server is just a one line of code:
rsync --delete-delay --chmod=ugo+rx -rtv public/ user@host:folder
Now I can get to the part why rsync command from Hexo is not working. Rsync when used with default switch -a
tries to copy privileges, but on Windows they do not exist and they are nulled by default making the directory completely unavailable on Linux. That is why you see the override with --chmod=ugo+rx
(please change it to what you need, as example have a very generic version). The public/
is the folder that will be synchronized (it should contain generated website). change the last part to your username, your hostname and after :
the sync destination.
If you use Hexo as static blog generator, do not forget to run hexo generate
before, ot create small two line script:
call node_modules\.bin\hexo.cmd generate
rsync --delete-delay --chmod=ugo+rx -rtv public/ user@host:folder