<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Blog dot Melimato dot Com &#187; unison</title>
	<atom:link href="http://blog.melimato.com/tag/unison/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.melimato.com</link>
	<description>Those things we do</description>
	<lastBuildDate>Thu, 24 Dec 2009 11:58:58 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=abc</generator>
		<item>
		<title>Keeping directories in sync with unison</title>
		<link>http://blog.melimato.com/keeping-directories-in-sync-with-unison/</link>
		<comments>http://blog.melimato.com/keeping-directories-in-sync-with-unison/#comments</comments>
		<pubDate>Fri, 08 May 2009 23:24:09 +0000</pubDate>
		<dc:creator>pablo</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[sync]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[rsync]]></category>
		<category><![CDATA[unison]]></category>

		<guid isPermaLink="false">http://blog.melimato.com/?p=104</guid>
		<description><![CDATA[As opposed to rsync, unison is a two way file synchronizer. Similar to MySQL&#8217;s master to master replication. To set it up in Ubuntu (Intrepid) keep on reading&#8230; 1. Install unison on both servers apt-get install unison 2. Create a script to add to crontab to call unison periodically unison -numericids -owner -silent -times -contactquietly [...]]]></description>
			<content:encoded><![CDATA[<p>As opposed to rsync, unison is a two way file synchronizer. Similar to MySQL&#8217;s master to master replication. To set it up in Ubuntu (Intrepid) keep on reading&#8230;</p>
<p><span id="more-104"></span></p>
<p>1. Install unison on both servers</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> unison</pre></div></div>

<p>2. Create a script to add to crontab to call unison periodically</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">unison <span style="color: #660033;">-numericids</span> <span style="color: #660033;">-owner</span> <span style="color: #660033;">-silent</span> <span style="color: #660033;">-times</span> <span style="color: #660033;">-contactquietly</span> <span style="color: #660033;">-batch</span> <span style="color: #660033;">-auto</span> <span style="color: #660033;">-log</span> <span style="color: #660033;">-logfile</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>log<span style="color: #000000; font-weight: bold;">/</span>unison.log profile_file <span style="color: #000000;">2</span><span style="color: #000000; font-weight: bold;">&gt;&amp;</span><span style="color: #000000;">1</span></pre></div></div>

<p>3. Create the above mentioned profile file on ~/.unison/profile_file.prf</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">root = <span style="color: #c20cb9; font-weight: bold;">ssh</span>:<span style="color: #000000; font-weight: bold;">//</span>server_ip<span style="color: #000000; font-weight: bold;">//</span>path<span style="color: #000000; font-weight: bold;">/</span>to<span style="color: #000000; font-weight: bold;">/</span>root<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">dir</span>
root = <span style="color: #000000; font-weight: bold;">/</span>path<span style="color: #000000; font-weight: bold;">/</span>to<span style="color: #000000; font-weight: bold;">/</span>root<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">dir</span>
ignore = Regex .<span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>cache<span style="color: #000000; font-weight: bold;">|</span>Cache<span style="color: #000000; font-weight: bold;">|</span>te?mp<span style="color: #000000; font-weight: bold;">|</span>logs?<span style="color: #7a0874; font-weight: bold;">&#41;</span>.<span style="color: #000000; font-weight: bold;">*</span> <span style="color: #666666; font-style: italic;"># ignore log and cache files</span></pre></div></div>

<p>That&#8217;s it! Now add the following line to your crontab to execute it every 5min</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">*/</span><span style="color: #000000;">5</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">/</span>path<span style="color: #000000; font-weight: bold;">/</span>to<span style="color: #000000; font-weight: bold;">/</span>my_unison_script.sh</pre></div></div>

<p>After a few days of running this I found that sometimes one unison execution would overlap another. To resolve this I found a little tool called <a href="http://unixwiz.net/tools/lockrun.html">lockrun</a></p>
<p>To get it to work I did:</p>
<p>1. Download the source code from the official <a href="http://unixwiz.net/tools/lockrun.c">lockrun website</a></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">wget</span> http:<span style="color: #000000; font-weight: bold;">//</span>unixwiz.net<span style="color: #000000; font-weight: bold;">/</span>tools<span style="color: #000000; font-weight: bold;">/</span>lockrun.c</pre></div></div>

<p>2. Build/install as shown in <a href="http://unixwiz.net/tools/lockrun.html">http://unixwiz.net/tools/lockrun.html</a></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">gcc</span> lockrun.c <span style="color: #660033;">-o</span> lockrun
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">cp</span> lockrun <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span></pre></div></div>

<p>3. Change the previous crontab line to use lockrun</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">*/</span><span style="color: #000000;">5</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>lockrun <span style="color: #660033;">--lockfile</span>=<span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>hosting.lockrun <span style="color: #660033;">--</span> <span style="color: #000000; font-weight: bold;">/</span>path<span style="color: #000000; font-weight: bold;">/</span>to<span style="color: #000000; font-weight: bold;">/</span>my_unison_script.sh</pre></div></div>

<p>All done!!!</p>
<div id="wherego_related"> </div>]]></content:encoded>
			<wfw:commentRss>http://blog.melimato.com/keeping-directories-in-sync-with-unison/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
