How to set up automatic sync of a folder on a remote server

in #howto7 years ago

For


web developers, the business of having to manually upload changed files to a server to have the server run them leads to some irritating makeshifts, such as running a local development server, or usually dumb filesystem interfaces in file managers or in the editor/IDE itself. Well, of course the latter does make it easier, but you can do this a better way.

I have searched for a tool to do this for a very long time, and I found Inosync, which is written in python, but I could never get it to work properly. There is also Syncthing. This is too complicated also. Today, by chance I managed to find something far better, that is the next best thing to having direct access to the folder where your server's scripts and configurations are stored on your PC.

lsyncd

The page for the project can be found here:

https://github.com/axkibe/lsyncd

But it exists also as a package in Ubuntu 16.04, you can just

sudo apt install lsyncd

and have it.

The best thing about lsyncd is it automatically runs in the background by default (you can disable this), and it has a delay function to leave some time between changes and when it uploads the change. For my purpose, developing a Django/Nginx powered website, now I can edit and save my files locally in a prescribed folder, and moments later it is on the server and the server will serve the files for me.

The command I use, and I have made it into a custom command in my /usr/local/bin/ folder and I just run that to have this execute:

lsyncd -delay 0 -rsyncssh /home/loki/inception projectinception.lt /home/loki/inception

As simply as that, now it is as though my local folder is the same as the one on the server, including ownership and permissions. You should therefore have the same user on your own machine as the target so the permissions are correct.

😎


We can't code here! This is Whale country!

Written with StackEdit.

Sort:  

Thank you for posting l0k1. This one does seem to be working for you. Appreciate your perseverance. Hope others will find it of use as well.

All the best. Cheers.

Coin Marketplace

STEEM 0.19
TRX 0.14
JST 0.029
BTC 64063.06
ETH 3144.15
USDT 1.00
SBD 2.55