Sync one directory on one machine to another

From Klaus' wiki
Revision as of 11:23, 4 July 2016 by Klaus (Talk | contribs)

Jump to: navigation, search

Now you may be in the situation that you want to keep two directories in sync. In my example it was a virtual Fedora that I wanted keep a copy of in another place. My virtual is running on my home laptop and the work I do here I want to copy to a network connected drive out on the university.

Luckely one good hearted soul invented lsyncd. See github for more details and the manual.

What I did was to install lsyncd, which is a part of one of the Fedora repositories I have installed, in fact the default Fedora repository.

So, as root, issue:

dnf install lsyncd

then enable the lsyncd daemon

systemctl enable lsyncd.service

next edit the configuration file

sync{
        default.rsyncssh,
        source="/home/klaus/workspaces",
        host="klaus@192.168.0.183",
        targetdir="/home/klaus/mounts/au-herning/m/mounts/uni/2016/E3ISD1/workspaces"
}

From this you can see that I want to copy whatever exists in /home/klaus/workspaces to my laptop, identified by the login name and the IP address. The destination is my sshFS mounted remote filesystem on the university network.

Just before starting the lsyncd do ensure that your root account can login on the remote computer by issuing

ssh-copy-id -i ~/.ssh/id_rsa.pub klaus@192.168.0.183

test that you can login without using password.

Finally let the daemon loose

systemctl start lsyncd.service

In a few seconds you'll wee that the local directory structur and files are rsync'ed to the remote destination. Take a look on the man page for rsync - it's a pretty neat tool for synchronising computers and other stuff. lsync just builds an easy interface for using rsync.