Difference between revisions of "Sync one directory on one machine to another"

From Klaus' wiki
Jump to: navigation, search
Line 38: Line 38:
  
 
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.
 
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.
 +
 +
===What if the network is dealyed===
 +
 +
If your network is taking it time to get up an being stable you can modify the control file that starts up the lsync daemon.
 +
 +
<source lang=bash>
 +
vi /etc/systemd/system/multi-user.target.wants/lsyncd.service
 +
</source>
 +
 +
Add a line
 +
Requires=network.target NetworkManager.service network-online.target
 +
in the Unit section.

Revision as of 09:07, 8 July 2016

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

vi /etc/lsyncd.conf

to have a similar content as shown below. Modify for your need.

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.

What if the network is dealyed

If your network is taking it time to get up an being stable you can modify the control file that starts up the lsync daemon.

vi /etc/systemd/system/multi-user.target.wants/lsyncd.service

Add a line

Requires=network.target NetworkManager.service network-online.target

in the Unit section.