<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Not Really a Blog &#187; tricks</title>
	<atom:link href="http://blog.notreally.org/tag/tricks/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.notreally.org</link>
	<description>or is it?</description>
	<lastBuildDate>Tue, 13 Jul 2010 09:48:09 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='blog.notreally.org' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://1.gravatar.com/blavatar/93018cad14db97a3057eb332c3ba920a?s=96&#038;d=http://s2.wp.com/i/buttonw-com.png</url>
		<title>Not Really a Blog &#187; tricks</title>
		<link>http://blog.notreally.org</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://blog.notreally.org/osd.xml" title="Not Really a Blog" />
	<atom:link rel='hub' href='http://blog.notreally.org/?pushpress=hub'/>
		<item>
		<title>Tired of remembering complicated passwords?</title>
		<link>http://blog.notreally.org/2009/11/25/tired-of-remembering-complicated-passwords/</link>
		<comments>http://blog.notreally.org/2009/11/25/tired-of-remembering-complicated-passwords/#comments</comments>
		<pubDate>Wed, 25 Nov 2009 16:41:31 +0000</pubDate>
		<dc:creator>jroncero</dc:creator>
				<category><![CDATA[Computers]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[password]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[tricks]]></category>
		<category><![CDATA[unix]]></category>

		<guid isPermaLink="false">http://blog.notreally.org/?p=182</guid>
		<description><![CDATA[My colleague Mat showed me a nice little trick today. Say you are bored or tired of using different password in all your websites you use, or maybe you don&#8217;t want to use the same password on these sites. Simple and easy if you use a Linux computer. You only have to use, and more [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.notreally.org&amp;blog=8911601&amp;post=182&amp;subd=blognotreally&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>My colleague <a href="http://cyberfish.org">Mat</a> showed me a nice little trick today. Say you are bored or tired of using different password in all your websites you use, or maybe you don&#8217;t want to use the same password on these sites. Simple and easy if you use a Linux computer. You only have to use, and more importantly remember, simple words or combination and a little command in the shell to generate a really difficult to guess password.</p>
<p>Say you want to access your <a href="http://www.google.com">Google</a> account and you want to use <span style="color:#ff6600;"><strong>google</strong></span> as the password. So I&#8217;ll go and use the <a href="http://en.wikipedia.org/wiki/SHA_hash_functions">SHA hash algorithm</a> to generate an interesting password like:</p>
<pre class="brush: bash;">

% echo &quot;google&quot; | sha1sum
d662cc72cfed7244a88a7360add85d5627b9cd6c  -
</pre>
<p>Or just go and use your hash algorithm of choice. And if it&#8217;s too long for the website you want to use, get the 10 first characters or something.</p>
<pre class="brush: bash;">

% echo &quot;google&quot; | sha1sum | cut -c1-10
d662cc72cf
</pre>
<p>And that&#8217;s it, copy and paste and you are done. Yes, it&#8217;s a bit of a <a href="http://www.urbandictionary.com/define.php?term=faff">faff</a>, but, well, you want something secure, don&#8217;t you?</p>
<p>Simply brilliant. Thanks Mat.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/blognotreally.wordpress.com/182/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/blognotreally.wordpress.com/182/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/blognotreally.wordpress.com/182/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/blognotreally.wordpress.com/182/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/blognotreally.wordpress.com/182/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/blognotreally.wordpress.com/182/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/blognotreally.wordpress.com/182/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/blognotreally.wordpress.com/182/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/blognotreally.wordpress.com/182/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/blognotreally.wordpress.com/182/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/blognotreally.wordpress.com/182/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/blognotreally.wordpress.com/182/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/blognotreally.wordpress.com/182/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/blognotreally.wordpress.com/182/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.notreally.org&amp;blog=8911601&amp;post=182&amp;subd=blognotreally&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.notreally.org/2009/11/25/tired-of-remembering-complicated-passwords/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e39e820dfad61c10be3c1f2c7f9c2747?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">golan</media:title>
		</media:content>
	</item>
		<item>
		<title>Tricks to diagnose processes blocked on strong I/O in linux</title>
		<link>http://blog.notreally.org/2008/02/10/tricks-to-diagnose-processes-blocked-on-strong-io-in-linux/</link>
		<comments>http://blog.notreally.org/2008/02/10/tricks-to-diagnose-processes-blocked-on-strong-io-in-linux/#comments</comments>
		<pubDate>Sun, 10 Feb 2008 23:59:14 +0000</pubDate>
		<dc:creator>jroncero</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[System Administration]]></category>
		<category><![CDATA[hackers]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[tricks]]></category>

		<guid isPermaLink="false">http://blog.notreally.org/articles/2008/02/10/tricks-to-diagnose-processes-blocked-on-strong-io-in-linux/</guid>
		<description><![CDATA[There&#8217;s one aspect of the Linux kernel and the GNU operating system and related tools in which it might be lacking behind, specially with kernel 2.4 series. I&#8217;m talking about I/O accounting or how to know what&#8217;s going on with the hard disk or other devices which are used to write and read data. The [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.notreally.org&amp;blog=8911601&amp;post=53&amp;subd=blognotreally&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>There&#8217;s one aspect of the Linux kernel and the GNU operating system and related tools in which it might be lacking behind, specially with kernel 2.4 series. I&#8217;m talking about I/O accounting or how to know what&#8217;s going on with the hard disk or other devices which are used to write and read data.</p>
<p>The thing is that Linux provides you with a few tools with which you can tell what&#8217;s going on with the box and its set of disks. Say <strong>vmstat</strong> provides you with a lot of information and various other files scattered in the <tt>/proc</tt> filesystem. But that information only tells us about the system globally, so it&#8217;s good for diagnosing if a high load on a box is due to some process chewing CPU cycles away or because of the hard disk being hammered and being painfully slow. But what about if you want to know what exactly is going on, which process or processes are responsible for the situation, how do you know? The answer is that Linux doesn&#8217;t provide you with tools for that, as far as I know (If you know of any, please leave a comment). There&#8217;s no such thing as a top utility for process I/O accounting. The situation is better in Linux 2.6 provided you activate the <a href="http://www.mjmwired.net/kernel/Documentation/accounting/taskstats.txt">taskstats accounting module</a> with which you can query information about the processes. The user-space utilities are <a href="http://search.cpan.org/~scottw/Linux-Taskstats-Read-4.00/">somewhat scarce</a>, but at least there&#8217;s something with which you can start playing.</p>
<p>However there are some tricks you can use to try to find out which process is the culprit when things go wrong. As usually, many of these tricks come from work where I keep learning from my colleagues, who, by the way, are  much more intelligent than I am <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> , when things go wrong and some problem arises that needs immediate action.</p>
<p>So, let&#8217;s define the typical scenario on which we could apply these tricks. You&#8217;ve got a Linux box which has a high load average. Say 15, 20, etc. As you may know, the load average measures the number of processes that are waiting to be executed on the process queue. That doesn&#8217;t necessarily mean that the CPU is loaded when, for example, processes are blocked because of I/O, say a read from the disk because this is slow or something. The CPU would just sit there most of the time being idle. This number makes sense when you know the number of CPU the box has. If you have a <em>loadavg</em> of 2 in a two-CPU box, then you are just fine, ideally.</p>
<p>The number one tool for  identifying what&#8217;s going on is <a href="http://gd4.tuwien.ac.at/.vhost/linuxcommand.org/man_pages/vmstat8.html">vmstat</a>, which would tell you a lot of things going on in the box, specially when you execute it periodically as <tt>vmstat 1</tt>. If you read the man page (and I do recommend you to read it), you can get an idea of all the information what would be going through the screen <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> . <a href="http://www.flickr.com/photos/golan/464063579/sizes/o/">Click here to see a screen shot of the output of <em>vmstat</em> on 4 different boxes</a>. Almost all of its output is useful for diagnosis, except the last column in the case of a Linux 2.4 box (that value is added to the idle column).</p>
<p>With this tool we can find out if the system is busy on I/O and how. For example by looking at the <strong>bo</strong> and <strong>bi</strong> columns. Swapping, when it&#8217;s happening, could also imply that the hard disk is being hammered but that would also mean that there&#8217;s not enough memory in the system for all the processes running at that very moment. Well, all of its output can be useful for identifying what&#8217;s going on.</p>
<p>Ok, so back to our problem, how do we start? Well, the first thing to do is to try to find out what&#8217;s on execution that could be causing this. Who are the usual suspects. By looking at <tt>ps</tt> output we could get an idea of which processes and/or application could be causing the disk I/O. The problem with this is that sometimes an application runs tens or hundreds of processes, each of which is serving a remote client (say Apache prefork) and maybe only some of them are causing the havoc, so killing all possible processes is not an option in a production environment (possibly killing the processes causing the problem is feasible because they might be wedged or something).</p>
<p><strong>Finding the suspects</strong></p>
<p>One way to find what processes are causing the writes and reads  is to have a look at the processes in  <a href="http://en.wikipedia.org/wiki/Uninterruptible_sleep">uninterruptible sleep</a> state. As the box has a high load average because of I/O, surely there must be processes in such a state because they are waiting for the disk to return back the data and return from their system calls. And these processes are likely to be involved in the high load of the system. If you think that uninterruptible sleep processes cannot be killed you are right, but we are assuming that they are in this state briefly again and again because of reading and writing to the disk non-stop. If you have read the vmstat man page, you must have noticed that the column <strong>b</strong> tells us the number of processes in such a state.</p>
<pre>golan@kore:~$ ps aux | grep " D"
root     27351  2.9  0.2 11992 9160 ?        DN   23:06   0:08 /usr/bin/python /usr/bin/rdiff-backup -v 5 --restrict-read-only /disk --server
mail     28652  0.5  0.0  4948 1840 ?        D    23:11   0:00 exim -bd -q5m
golan    28670  0.0  0.0  2684  804 pts/23   S+   23:11   0:00 grep --color  D</pre>
<p>Here we can see two processes in such a state (noted by <strong>D </strong>on ps output). Normally we don&#8217;t get to see many of these at the same time and if we issue the same command again, we are probably not going to see it again unless there is a problem which is why I&#8217;m writing this in the first place <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> .</p>
<p><strong>Examining the suspects</strong></p>
<p>Well, we now need to examine the suspects and filter them, because there might be perfectly valid processes that are in uninterruptible sleep state but are not responsible of the high load, so we need to find out. One thing that we could do is attach <a href="http://sourceforge.net/projects/strace/">strace</a> to a specific process and see how it&#8217;s doing. This can be easily achieved this way:</p>
<pre>golan@kore:~$ strace -p 12766
Process 12766 attached - interrupt to quit
write(1, "y\n", 2)                      = 2</pre>
<p>Here we see the output of a process executing <strong>yes</strong>. So, what does this output tell us? It shows us all the system calls that the process is doing, so we can effectively see if it is reading or writing.</p>
<p>But all this can be very time consuming if we have quite a few processes to examine. What we could do is strace all of them and save their output to different files and then check them later:</p>
<p>If what we are examining is a process called <strong>command</strong>, we could  do it this way:</p>
<pre># mkdir /tmp/strace
# cd /tmp/strace
# for i in `ps axuwf | grep command | awk '{ print $2 }'`; do (strace -p $i &gt; command-$i.strace 2&gt;&amp;1)&amp;  done</pre>
<p>What this would do is create a series of files called <tt>command-PID-strace</tt>, one for each of the processes that match the regular expression in the grep command. If we set this running for a while, we can now examine the contents of all the files. Even better if we display the files ordered by <strong>size</strong> we would have a pointer to the process that are doing the most system calls. All we would need to do is verify that those system calls are actually read and write system calls. And also, don&#8217;t forget to kill all the strace processes that we sent to the background by issuing a <tt>killall strace</tt> <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>So now we have a list of processes that are causing lots of reads and writes in the hard disk. What to do next depends on the situation and what you want to do. You might want to kill the processes, or find who (the person) who started them, in case they were started by someone. Or which network connection, IP address, etc. There are a bunch of utilities that you can use including strace, <a href="http://en.wikipedia.org/wiki/Netstat">netstat</a>, <a href="http://en.wikipedia.org/wiki/Lsof">lsof</a>, etc. It&#8217;s up to you what to do next.</p>
<p><strong>And&#8230;</strong></p>
<p>Well, This is me learning from my colleagues and from problems that arise when you don&#8217;t expect them. My understanding of the Linux kernel is not that good, but now many of the things that I studied in the Operating System class start to make a little bit more sense. So please, if you have experience with this, know of other ways to get this kind of information, please share it with me (as a comment or otherwise). I&#8217;m still learning <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/blognotreally.wordpress.com/53/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/blognotreally.wordpress.com/53/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/blognotreally.wordpress.com/53/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/blognotreally.wordpress.com/53/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/blognotreally.wordpress.com/53/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/blognotreally.wordpress.com/53/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/blognotreally.wordpress.com/53/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/blognotreally.wordpress.com/53/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/blognotreally.wordpress.com/53/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/blognotreally.wordpress.com/53/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/blognotreally.wordpress.com/53/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/blognotreally.wordpress.com/53/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/blognotreally.wordpress.com/53/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/blognotreally.wordpress.com/53/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/blognotreally.wordpress.com/53/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/blognotreally.wordpress.com/53/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.notreally.org&amp;blog=8911601&amp;post=53&amp;subd=blognotreally&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.notreally.org/2008/02/10/tricks-to-diagnose-processes-blocked-on-strong-io-in-linux/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e39e820dfad61c10be3c1f2c7f9c2747?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">golan</media:title>
		</media:content>
	</item>
		<item>
		<title>Speeding up trac&#8217;s response time</title>
		<link>http://blog.notreally.org/2006/12/04/speeding-up-tracs-response-time/</link>
		<comments>http://blog.notreally.org/2006/12/04/speeding-up-tracs-response-time/#comments</comments>
		<pubDate>Mon, 04 Dec 2006 18:30:44 +0000</pubDate>
		<dc:creator>jroncero</dc:creator>
				<category><![CDATA[Internet]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[program]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[trac]]></category>
		<category><![CDATA[tricks]]></category>

		<guid isPermaLink="false">http://blognotreally.wordpress.com/2006/12/04/speeding-up-tracs-response-time/</guid>
		<description><![CDATA[I&#8217;ve been trying to speed up an installation of trac over the last few days. The web interface took ages to display each of the directories or files within the subversion repository. But this one wasn&#8217;t too big. The only change to the subversion repository is that we started using a vendor branch imported into [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.notreally.org&amp;blog=8911601&amp;post=40&amp;subd=blognotreally&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been trying to speed up an installation of <a href="http://trac.edgewall.org/">trac</a> over the last few days. The web interface took ages to display each of the directories or files within the subversion repository. But this one wasn&#8217;t too big. The only change to the subversion repository is that we started using a vendor branch imported into our main repository using <a href="http://search.cpan.org/~clkao/SVN-Mirror-0.72/bin/svm">svm</a></p>
<p>So, after a few hours trying different solutions, and reading trac&#8217;s source code, I think I got where the bottleneck was.Well, it was <a href="sqlite">http://www.sqlite.org/download.html</a> which was causing the bottleneck. Trac uses an object <em>CachedRepository</em> to access the repositories. Whenever we want to get the <em>chagesets</em>, a function to synchronize the repository is called:</p>
<pre class="brush: python;">
class CachedRepository(Repository):
  def get_changeset(self, rev):
    if not self.synced:
      self.sync()
      self.synced = 1
      return CachedChangeset(self.repos.normalize_rev(rev), self.db, self.authz)
</pre>
<p>and such method, sync(), makes a call to:</p>
<pre class="brush: python;">
youngest_stored = self.repos.get_youngest_rev_in_cache(self.db)
</pre>
<p>which is all this:</p>
<pre class="brush: python;">
def get_youngest_rev_in_cache(self, db):
    &quot;&quot;&quot;Get the latest stored revision by sorting the revision strings
    numerically
    &quot;&quot;&quot;
    cursor = db.cursor()
    cursor.execute(&quot;SELECT rev FROM revision ORDER BY -LENGTH(rev), rev DESC LIMIT 1&quot;)
    row = cursor.fetchone()
    return row and row[0] or None
</pre>
<p>And that SQL query was taking around 1-2 seconds each time it was executed. It happened that we were running an old version of <a href="http://www.sqlite.org/">sqlite</a> and <a href="http://www.initd.org/pub/software/pysqlite/">pysqlite</a>, so a <strong>./cofigure &amp;&amp; make &amp;&amp; make install</strong> using the recommended installation saved my day <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>Hope it is useful to anybody if it gets indexed by <a href="http://www.google.com">Google</a>.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/blognotreally.wordpress.com/40/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/blognotreally.wordpress.com/40/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/blognotreally.wordpress.com/40/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/blognotreally.wordpress.com/40/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/blognotreally.wordpress.com/40/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/blognotreally.wordpress.com/40/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/blognotreally.wordpress.com/40/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/blognotreally.wordpress.com/40/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/blognotreally.wordpress.com/40/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/blognotreally.wordpress.com/40/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/blognotreally.wordpress.com/40/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/blognotreally.wordpress.com/40/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/blognotreally.wordpress.com/40/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/blognotreally.wordpress.com/40/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/blognotreally.wordpress.com/40/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/blognotreally.wordpress.com/40/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.notreally.org&amp;blog=8911601&amp;post=40&amp;subd=blognotreally&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.notreally.org/2006/12/04/speeding-up-tracs-response-time/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e39e820dfad61c10be3c1f2c7f9c2747?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">golan</media:title>
		</media:content>
	</item>
		<item>
		<title>Setting up a subversion mirror repository using svnsync</title>
		<link>http://blog.notreally.org/2006/11/30/setting-up-a-subversion-mirror-repository-using-svnsync/</link>
		<comments>http://blog.notreally.org/2006/11/30/setting-up-a-subversion-mirror-repository-using-svnsync/#comments</comments>
		<pubDate>Thu, 30 Nov 2006 01:48:36 +0000</pubDate>
		<dc:creator>jroncero</dc:creator>
				<category><![CDATA[Internet]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[program]]></category>
		<category><![CDATA[subversion]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[tricks]]></category>

		<guid isPermaLink="false">http://blognotreally.wordpress.com/2006/11/30/setting-up-a-subversion-mirror-repository-using-svnsync/</guid>
		<description><![CDATA[With the new version of subversion 1.4 you have a new tool called svnsync with which you can maintain mirror repositories quite easily. I&#8217;ve been working on one at work and would like to share with you my findings in case it interests anyone Understanding the problem In order to have a mirror repository, it [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.notreally.org&amp;blog=8911601&amp;post=39&amp;subd=blognotreally&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>With the new version of <a href="http://subversion.tigris.org">subversion 1.4</a> you have a new tool called <a href="http://svn.collab.net/repos/svn/trunk/notes/svnsync.txt">svnsync</a> with which you can maintain mirror repositories quite easily. I&#8217;ve been working on one at work and would like to share with you my findings in case it interests anyone <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<h3>Understanding the problem</h3>
<p>In order to have a mirror repository, it is important that commits only happen on the master and then they are synchronized to the mirror using the svnsync program. Then, the mirror repository can be used for whatever you may think of but for committing: backup, high speed checkouts, web front-ends, etc.</p>
<p>So, svnsync must be the only &#8220;one&#8221; able to commit to the repository. If we use the apache integration, there are various ways to do this. Let&#8217;s say we are using svn+ssh for authentication, in which case it is more complicated as ssh access usually grants writing access to the file system. So creating a different user is going to be handy.</p>
<h3>Creating and populating the repository</h3>
<p>So, let&#8217;s say that we created a user called svnsync on the target machine and that we are going to create a new subversion repository in its home directory:</p>
<p>svnadmin create /home/svnsync/svn</p>
<p>Now, we need to set up a hook to let svnsync change the properties. For this, we create /home/svnsync/svn/hooks/pre-revprop-change with:</p>
<pre class="brush: bash;">
#!/bin/sh
USER=&quot;$3&quot;

if [ &quot;$USER&quot; = &quot;svnsync&quot; ]; then exit 0; fi

echo &quot;Only the svnsync user can change revprops&quot; &gt;&amp;2
exit 1
</pre>
<p>We will grant access to the user running svnsync on the main machine by copying its ssh key to .ssh/authorized_keys. And now, we only need to initialize the remote repository. Note that we can run svnsync from where ever we want, but for the sake of simplicity, we will run it on the main machine, where the original repository resides.</p>
<pre class="brush: bash;">
$ svnsync init --username svnsync \
      svn+ssh://svnsync@remote/home/svnsync/svn \
      file:///source-svn
</pre>
<p>Note:</p>
<ul>
<li>The syntax is
<pre>svnsync init DEST SOURCE</pre>
<p>That&#8217;s it, the destination repository goes before the source  repository.</li>
<li> There is no &#8220;:&#8221; between the host name and the path to the remote repository.</li>
</ul>
<p>With this command, we will have initialized the destination repository and now we are ready to populate the destination repository. We can do it with this command:</p>
<pre class="brush: bash;">
svnsync synchronize --username svnsync \
       svn+ssh://svnsync@remote/home/svnsync/svn
</pre>
<p>And, as we already initialized the repository, there is no need to specify the source repository. This will take more or less time depending on how big you repository is and how fast your network connection is. Hopefully it will have finished after you take a coffee <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<h3>Creating another user to let users access the repository</h3>
<p>So, we will now create an user called svn which will be used to access the repository using the subversion client. As we are using svn+ssh, all we need is to grant access to such user to all the users that have access to the main repository. If we are using ssh keys it&#8217;s as easy as copying all the allowed keys to the /home/svn/.ssh/authorized_keys file.<br />
Also, if we change the permissions to the repository at /home/svnsync/svn (and its parent) to be something like</p>
<pre>drwxr-xr-x  7 svnsync users 4096 2006-11-28 17:30 svn/</pre>
<p>we will let svnsync (and the svnsync user) be the owner and have write permissions to the repository and let svn (and all the users ssh&#8217;ing) have read access only to the repository (provided both belong to the users group).</p>
<pre class="brush: bash;">
$ svn co svn+ssh://svn@remote/home/svnsync/svn/test
A    test/trunk
[...]
A    test/trunk/readme
Checked out revision 2.
$ echo &quot;test&quot; &gt;&gt; test/trunk/readme
$ cd test/
$ svn -m &quot;test commit&quot; ci
Sending        trunk/readme
Transmitting file data .svn: Commit failed (details follow):
svn: Can't create directory '/home/svnsync/svn/db/transactions/2-1.txn':
Permission denied
</pre>
<p>And that&#8217;s all.</p>
<h3>Commiting to the master respository</h3>
<p>In case you want to commit back to the master respository, you need to do a &#8220;svn switch &#8211;relocate&#8221; to point to the master repository, but for that to work, it needs to have the same <a href="http://en.wikipedia.org/wiki/UUID">UUID</a> if we don&#8217;t want it to fail.</p>
<ol>
<li>To get the UUID on the main machine:
<pre class="brush: bash;">
svnadmin dump -r0 /source-svn | head -n 3 &gt; saved-uuid
</pre>
</li>
<li>Copy the file saved-uuid to the remote machine and do a
<pre class="brush: bash;">
svnadmin load --force-uuid /home/svnsynd/svn &lt; saved-uuid
</pre>
</li>
</ol>
<p>So, thins to take into account:</p>
<ol>
<li> When populating the repository, we use the svnsync user who has write permissions to the repository (svn+ssh://svnsync@&#8230;)</li>
<li>When checking out, we use the svn user (svn+ssh://svn@&#8230;)</li>
<h3>Automatization</h3>
<p>If we want to keep both repositories synchronized, we need to set up a couple of hooks on the source repository.</p>
<h4>post-commit</h4>
<p>Add this to such hook (it needs to be executable and not have the .tmpl extension)</p>
<pre class="brush: bash;">
# Propagate the data to the remote repository
/usr/local/bin/svnsync synchronize --username svnsync
        svn+ssh://svnsync@remote/home/svnsync/svn &amp;
</pre>
<h4>post-rev-changes</h4>
<p>We also want the properties changes to be present at the remote repository:</p>
<pre class="brush: bash;">
# Propagating changes to the remote repository.
/usr/local/bin/svnsync copy-revprops --username svnsync
       svn+ssh://svnsync@remote/home/svnsync/svn $REV  &amp;
</pre>
<p>Note that we put them to the background to let the user go on with what he was doing.</p>
<h3>Final notes</h3>
<p>This is a quick guide on how to set things to have a remote repository. There is much more than this and I recommend you to read the documentation and, obviously, do a backup. Doing a &#8220;svnadmin dump&#8221; only takes a while a it´s really worth it.</p>
<p>In any case, just let me know if you find any errors or typos.</ol>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/blognotreally.wordpress.com/39/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/blognotreally.wordpress.com/39/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/blognotreally.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/blognotreally.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/blognotreally.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/blognotreally.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/blognotreally.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/blognotreally.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/blognotreally.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/blognotreally.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/blognotreally.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/blognotreally.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/blognotreally.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/blognotreally.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/blognotreally.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/blognotreally.wordpress.com/39/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.notreally.org&amp;blog=8911601&amp;post=39&amp;subd=blognotreally&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.notreally.org/2006/11/30/setting-up-a-subversion-mirror-repository-using-svnsync/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e39e820dfad61c10be3c1f2c7f9c2747?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">golan</media:title>
		</media:content>
	</item>
	</channel>
</rss>