<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Linux Admin Zone</title>
	
	<link>http://linuxadminzone.com</link>
	<description>Adding more reasons to celebrate Open Source.</description>
	<lastBuildDate>Wed, 09 May 2012 10:17:54 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/LinuxAdminZone" /><feedburner:info uri="linuxadminzone" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><feedburner:emailServiceId>LinuxAdminZone</feedburner:emailServiceId><feedburner:feedburnerHostname>http://feedburner.google.com</feedburner:feedburnerHostname><item>
		<title>Simple and efficient MongoDB Backup using script</title>
		<link>http://feedproxy.google.com/~r/LinuxAdminZone/~3/cBWoPTq6CMo/</link>
		<comments>http://linuxadminzone.com/simple-and-efficient-mongodb-backup-using-script/#comments</comments>
		<pubDate>Wed, 09 May 2012 10:17:54 +0000</pubDate>
		<dc:creator>jagbir</dc:creator>
				<category><![CDATA[database]]></category>
		<category><![CDATA[nosql]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[mongodb]]></category>
		<category><![CDATA[mongodump]]></category>
		<category><![CDATA[script]]></category>

		<guid isPermaLink="false">http://linuxadminzone.com/?p=511</guid>
		<description><![CDATA[MongoDB Backup types and strategies are neatly explained in its documentation, which you can check here. In case you are not familiar with MongoDB backup types and strategies, please have a look at its documentation. What I am describing here is a simple script which we are using since months to take MongoDB backup and [...]]]></description>
			<content:encoded><![CDATA[<p>MongoDB Backup types and strategies are neatly explained in its documentation, which you can check <a href="http://www.mongodb.org/display/DOCS/Backups" target="_blank">here</a>. In case you are not familiar with MongoDB backup types and strategies, please have a look at its documentation.</p>
<p>What I am describing here is a simple script which we are using since months to take MongoDB backup and transfer it over to our Backup server. Here are few things its doing:</p>
<ul>
<li>As we have multiple MongoDB Replica Sets, the script identify current replica set and check whether current server is Master or Slave, exit if its Master. We take backup only from Slave host.</li>
<li>Take Backup using mongodump command.</li>
<li>Upon successful completion of dump, transfer that to our Backup server. Ensure that ssh key based authentication is setup between both servers to implement seamless and secure transfer. It creates new directory based on current timestamp under replicaset directory in specified path at Backup server and transfer dump there.</li>
<li>Log each steps described above, send alert mail if any step fail with description or send confirmation mail upon successful execution with essential details.</li>
<li>Sample confirmation mail is below:</li>
</ul>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">Subject: Backup <span style="color: #000000; font-weight: bold;">for</span>  <span style="color: #000000; font-weight: bold;">done</span> on  at 09<span style="color: #000000; font-weight: bold;">/</span>May<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">12</span> 08:00:01 AM
Body: Mongo Backup Status <span style="color: #000000; font-weight: bold;">for</span>  on 09<span style="color: #000000; font-weight: bold;">/</span>May<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">12</span> 08:00:01 AM. 
&nbsp;
08:00:01 AM:  is slave and looks OK.
08:00:01 AM: Starting Dump, executing <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>mongodb<span style="color: #000000; font-weight: bold;">/</span>mongo<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>mongodump <span style="color: #660033;">--out</span> <span style="color: #000000; font-weight: bold;">/</span>databases<span style="color: #000000; font-weight: bold;">/</span>dump <span style="color: #660033;">--host</span> ...
08:<span style="color: #000000;">34</span>:06 AM: Mongodump <span style="color: #7a0874; font-weight: bold;">command</span> completed. Backup <span style="color: #c20cb9; font-weight: bold;">size</span> is 25G. 
08:<span style="color: #000000;">34</span>:<span style="color: #000000;">10</span> AM: Directory created on backup server, copying data using scp...
08:<span style="color: #000000;">57</span>:00 AM: Copied dump to backup server <span style="color: #000000; font-weight: bold;">in</span> directory <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>backup<span style="color: #000000; font-weight: bold;">/</span>Mongodump<span style="color: #000000; font-weight: bold;">/</span>replicaset<span style="color: #000000; font-weight: bold;">/</span>datestamp<span style="color: #000000; font-weight: bold;">/</span>.
08:<span style="color: #000000;">57</span>:00 AM: Mongo Backup process completed successfully.</pre></div></div>

<p>Here is the full bash script, please note that you need to update variables properly and have to check and update it to run in your environment which can be entirely different from mine. Its just an idea to automate MongoDB backup:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">##</span>
<span style="color: #666666; font-style: italic;"># Script to take mongo backup using mongodump and store it in Backup Server</span>
<span style="color: #666666; font-style: italic;">##</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#!/bin/bash</span>
&nbsp;
<span style="color: #666666; font-style: italic;">## Set variables</span>
<span style="color: #007800;">TodayDate</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">date</span> +<span style="color: #ff0000;">&quot;%d/%b/%g %r&quot;</span><span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #007800;">DateStamp</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">date</span> +<span style="color: #000000; font-weight: bold;">%</span>d<span style="color: #000000; font-weight: bold;">%</span>m<span style="color: #000000; font-weight: bold;">%</span>y<span style="color: #000000; font-weight: bold;">%</span>H<span style="color: #000000; font-weight: bold;">%</span>M<span style="color: #000000; font-weight: bold;">%</span>S<span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #007800;">CurrentTime</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">date</span> +<span style="color: #ff0000;">&quot;%r&quot;</span><span style="color: #000000; font-weight: bold;">`</span>
&nbsp;
<span style="color: #007800;">MongoBinPath</span>=<span style="color: #ff0000;">&quot;/usr/local/mongodb/mongo/bin&quot;</span>
<span style="color: #007800;">ReplicaSet</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">'rs.status()'</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #007800;">$MongoBinPath</span><span style="color: #000000; font-weight: bold;">/</span>mongo <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">egrep</span> <span style="color: #ff0000;">&quot;set&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #660033;">-F</span> <span style="color: #000000; font-weight: bold;">\&quot;</span> <span style="color: #ff0000;">'{print $4}'</span><span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #007800;">MongoHost</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">hostname</span><span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #007800;">LocalBackupPath</span>=<span style="color: #ff0000;">&quot;/databases/dump&quot;</span>
&nbsp;
<span style="color: #007800;">LogFile</span>=<span style="color: #ff0000;">&quot;/var/log/mongo-backup.log&quot;</span>
<span style="color: #007800;">IsOK</span>=<span style="color: #000000;">0</span>
<span style="color: #007800;">CmdStatus</span>=<span style="color: #ff0000;">&quot;&quot;</span>
&nbsp;
<span style="color: #007800;">BackupHost</span>=xx.xx.xx.xx
<span style="color: #007800;">BackupHostPath</span>=<span style="color: #ff0000;">&quot;/home/backup/mongobackup&quot;</span>
<span style="color: #007800;">BackupHostPort</span>=<span style="color: #000000;">22</span>
&nbsp;
<span style="color: #007800;">MailNotification</span>=<span style="color: #ff0000;">&quot;admin@domain.com anotheradmin@domain.com&quot;</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;Mongo Backup Status for <span style="color: #007800;">$ReplicaSet</span> on <span style="color: #007800;">$TodayDate</span>. <span style="color: #000099; font-weight: bold;">\n</span>&quot;</span> <span style="color: #000000; font-weight: bold;">&amp;</span>gt; <span style="color: #007800;">$LogFile</span>
&nbsp;
<span style="color: #666666; font-style: italic;">## Check whether host is slave and in good state for backup</span>
<span style="color: #000000; font-weight: bold;">for</span> i <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;rs.status()&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #007800;">$MongoBinPath</span><span style="color: #000000; font-weight: bold;">/</span>mongo <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">egrep</span> <span style="color: #ff0000;">&quot;name&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #660033;">-F</span> <span style="color: #000000; font-weight: bold;">\&quot;</span> <span style="color: #ff0000;">'{print $4}'</span><span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">cut</span> <span style="color: #660033;">-f</span> <span style="color: #000000;">1</span> <span style="color: #660033;">-d</span> :<span style="color: #000000; font-weight: bold;">`</span>; <span style="color: #000000; font-weight: bold;">do</span>
 <span style="color: #007800;">IsMaster</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;db.isMaster()&quot;</span><span style="color: #000000; font-weight: bold;">|</span> <span style="color: #007800;">$MongoBinPath</span><span style="color: #000000; font-weight: bold;">/</span>mongo <span style="color: #660033;">--host</span> <span style="color: #007800;">$i</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> ismaster<span style="color: #000000; font-weight: bold;">|</span><span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #660033;">-F</span> <span style="color: #ff0000;">&quot;:&quot;</span> <span style="color: #ff0000;">'{print $2}'</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">cut</span> <span style="color: #660033;">-f</span> <span style="color: #000000;">1</span> <span style="color: #660033;">-d</span> ,<span style="color: #000000; font-weight: bold;">`</span>;
 <span style="color: #007800;">TheState</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;rs.status()&quot;</span><span style="color: #000000; font-weight: bold;">|</span> <span style="color: #007800;">$MongoBinPath</span><span style="color: #000000; font-weight: bold;">/</span>mongo <span style="color: #660033;">--host</span> <span style="color: #007800;">$i</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-i</span> mystate <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #660033;">-F</span> <span style="color: #ff0000;">&quot;:&quot;</span> <span style="color: #ff0000;">'{print $2}'</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">cut</span> <span style="color: #660033;">-f</span> <span style="color: #000000;">1</span> <span style="color: #660033;">-d</span> ,<span style="color: #000000; font-weight: bold;">`</span>;
 <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$IsMaster</span> == <span style="color: #ff0000;">&quot;false&quot;</span> <span style="color: #660033;">-a</span> <span style="color: #007800;">$TheState</span> <span style="color: #660033;">-eq</span> <span style="color: #000000;">2</span>  <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
  <span style="color: #007800;">MongoHost</span>=<span style="color: #007800;">$i</span>
  <span style="color: #007800;">IsOK</span>=<span style="color: #000000;">1</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$CurrentTime</span>: <span style="color: #007800;">$MongoHost</span> is slave and looks OK.&quot;</span> <span style="color: #000000; font-weight: bold;">&amp;</span>gt;<span style="color: #000000; font-weight: bold;">&amp;</span>gt; <span style="color: #007800;">$LogFile</span>
  <span style="color: #7a0874; font-weight: bold;">break</span>
 <span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #000000; font-weight: bold;">done</span>
&nbsp;
<span style="color: #007800;">CurrentTime</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">date</span> +<span style="color: #ff0000;">&quot;%r&quot;</span><span style="color: #000000; font-weight: bold;">`</span>
&nbsp;
<span style="color: #666666; font-style: italic;">## Exit if not good</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$IsOK</span> <span style="color: #660033;">-eq</span> <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
   <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$CurrentTime</span>: Error: Either <span style="color: #007800;">$MongoHost</span> is not slave or not in good state. Aborting Backup, Please check!&quot;</span> <span style="color: #000000; font-weight: bold;">&amp;</span>gt;<span style="color: #000000; font-weight: bold;">&amp;</span>gt; <span style="color: #007800;">$LogFile</span>
   mail <span style="color: #660033;">-s</span> <span style="color: #ff0000;">&quot;Backup error for <span style="color: #007800;">$ReplicaSet</span> from <span style="color: #007800;">$MongoHost</span> on <span style="color: #007800;">$TodayDate</span>&quot;</span> <span style="color: #007800;">$MailNotification</span> <span style="color: #000000; font-weight: bold;">&amp;</span>lt; <span style="color: #007800;">$LogFile</span>    <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">1</span>; <span style="color: #000000; font-weight: bold;">fi</span> <span style="color: #666666; font-style: italic;">## Remove earlier backup CmdStatus=$(rm -rf $LocalBackupPath/*) ## Start backup process echo &quot;$CurrentTime: Starting Dump, executing $MongoBinPath/mongodump --out $LocalBackupPath --host $MongoHost...&quot; &amp;gt;&amp;gt; $LogFile</span>
&nbsp;
<span style="color: #007800;">CmdStatus</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #007800;">$MongoBinPath</span><span style="color: #000000; font-weight: bold;">/</span>mongodump <span style="color: #660033;">--out</span> <span style="color: #007800;">$LocalBackupPath</span> <span style="color: #660033;">--host</span> <span style="color: #007800;">$MongoHost</span><span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$?</span> <span style="color: #660033;">-ne</span> <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$CurrentTime</span>: There is an issue while trying to take dump in <span style="color: #007800;">$MongoHost</span>. Aborting dump process, please check! &quot;</span> <span style="color: #000000; font-weight: bold;">&amp;</span>gt;<span style="color: #000000; font-weight: bold;">&amp;</span>gt; <span style="color: #007800;">$LogFile</span>
  <span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #007800;">$CmdStatus</span> <span style="color: #000000; font-weight: bold;">&amp;</span>gt;<span style="color: #000000; font-weight: bold;">&amp;</span>gt; <span style="color: #007800;">$LogFile</span>
  mail <span style="color: #660033;">-s</span> <span style="color: #ff0000;">&quot;Backup error for <span style="color: #007800;">$ReplicaSet</span> from <span style="color: #007800;">$MongoHost</span> on <span style="color: #007800;">$TodayDate</span>&quot;</span> <span style="color: #007800;">$MailNotification</span> <span style="color: #000000; font-weight: bold;">&amp;</span>lt; <span style="color: #007800;">$LogFile</span>   <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000; font-weight: bold;">fi</span> <span style="color: #007800;">CurrentTime</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">date</span> +<span style="color: #ff0000;">&quot;%r&quot;</span><span style="color: #000000; font-weight: bold;">`</span> <span style="color: #007800;">BackupSize</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">du</span> <span style="color: #660033;">-sh</span> <span style="color: #007800;">$LocalBackupPath</span><span style="color: #000000; font-weight: bold;">/</span>. <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{ print $1 }'</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$CurrentTime</span>: Mongodump command completed. Backup size is <span style="color: #007800;">$BackupSize</span>. &quot;</span> <span style="color: #000000; font-weight: bold;">&amp;</span>gt;<span style="color: #000000; font-weight: bold;">&amp;</span>gt; <span style="color: #007800;">$LogFile</span>
&nbsp;
<span style="color: #666666; font-style: italic;">## dump is fine then scp it to backup server</span>
<span style="color: #666666; font-style: italic;">## create directory first</span>
<span style="color: #007800;">CmdStatus</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">ssh</span> <span style="color: #660033;">-p</span> <span style="color: #007800;">$BackupHostPort</span> <span style="color: #007800;">$BackupHost</span> <span style="color: #ff0000;">&quot;mkdir -p  <span style="color: #007800;">$BackupHostPath</span>/<span style="color: #007800;">$ReplicaSet</span>/<span style="color: #007800;">$DateStamp</span>&quot;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$?</span> <span style="color: #660033;">-ne</span> <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$CurrentTime</span>: Either failing to connect Backup server using ssh or destination directory already exist!&quot;</span> <span style="color: #000000; font-weight: bold;">&amp;</span>gt;<span style="color: #000000; font-weight: bold;">&amp;</span>gt; <span style="color: #007800;">$LogFile</span>
  <span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #007800;">$CmdStatus</span> <span style="color: #000000; font-weight: bold;">&amp;</span>gt;<span style="color: #000000; font-weight: bold;">&amp;</span>gt; <span style="color: #007800;">$LogFile</span>
  mail <span style="color: #660033;">-s</span> <span style="color: #ff0000;">&quot;Backup error for <span style="color: #007800;">$ReplicaSet</span> from <span style="color: #007800;">$MongoHost</span> on <span style="color: #007800;">$TodayDate</span>&quot;</span> <span style="color: #007800;">$MailNotification</span> <span style="color: #000000; font-weight: bold;">&amp;</span>lt; <span style="color: #007800;">$LogFile</span>   <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000; font-weight: bold;">fi</span> <span style="color: #007800;">CurrentTime</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">date</span> +<span style="color: #ff0000;">&quot;%r&quot;</span><span style="color: #000000; font-weight: bold;">`</span> <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$CurrentTime</span>: Directory created on backup server, copying data using scp...&quot;</span> <span style="color: #000000; font-weight: bold;">&amp;</span>gt;<span style="color: #000000; font-weight: bold;">&amp;</span>gt; <span style="color: #007800;">$LogFile</span>
&nbsp;
<span style="color: #007800;">CmdStatus</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">scp</span> <span style="color: #660033;">-P</span> <span style="color: #007800;">$BackupHostPort</span> <span style="color: #660033;">-r</span> <span style="color: #007800;">$LocalBackupPath</span><span style="color: #000000; font-weight: bold;">/*</span> <span style="color: #007800;">$BackupHost</span>:<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$BackupHostPath</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$ReplicaSet</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$DateStamp</span><span style="color: #000000; font-weight: bold;">/`</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$?</span> <span style="color: #660033;">-ne</span> <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$CurrentTime</span>: Unable to scp dump to <span style="color: #007800;">$BackupHost</span>:/<span style="color: #007800;">$BackupHostPath</span>/<span style="color: #007800;">$ReplicaSet</span>/<span style="color: #007800;">$DateStamp</span> using port <span style="color: #007800;">$BackupHostPort</span>. &quot;</span> <span style="color: #000000; font-weight: bold;">&amp;</span>gt;<span style="color: #000000; font-weight: bold;">&amp;</span>gt; <span style="color: #007800;">$LogFile</span>
  <span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #007800;">$CmdStatus</span> <span style="color: #000000; font-weight: bold;">&amp;</span>gt;<span style="color: #000000; font-weight: bold;">&amp;</span>gt; <span style="color: #007800;">$LogFile</span>
  mail <span style="color: #660033;">-s</span> <span style="color: #ff0000;">&quot;Backup error for <span style="color: #007800;">$ReplicaSet</span> from <span style="color: #007800;">$MongoHost</span> on <span style="color: #007800;">$TodayDate</span>&quot;</span> <span style="color: #007800;">$MailNotification</span> <span style="color: #000000; font-weight: bold;">&amp;</span>lt; <span style="color: #007800;">$LogFile</span>   <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000; font-weight: bold;">fi</span> <span style="color: #007800;">CurrentTime</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">date</span> +<span style="color: #ff0000;">&quot;%r&quot;</span><span style="color: #000000; font-weight: bold;">`</span> <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$CurrentTime</span>: Copied dump to backup server in directory <span style="color: #007800;">$BackupHost</span><span style="color: #007800;">$BackupHostPath</span>/<span style="color: #007800;">$ReplicaSet</span>/<span style="color: #007800;">$DateStamp</span>/.&quot;</span> <span style="color: #000000; font-weight: bold;">&amp;</span>gt;<span style="color: #000000; font-weight: bold;">&amp;</span>gt; <span style="color: #007800;">$LogFile</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$CurrentTime</span>: Mongo Backup process completed successfully.&quot;</span> <span style="color: #000000; font-weight: bold;">&amp;</span>gt;<span style="color: #000000; font-weight: bold;">&amp;</span>gt; <span style="color: #007800;">$LogFile</span>
mail <span style="color: #660033;">-s</span> <span style="color: #ff0000;">&quot;Backup for <span style="color: #007800;">$ReplicaSet</span> done on <span style="color: #007800;">$MongoHost</span> at <span style="color: #007800;">$TodayDate</span>&quot;</span> <span style="color: #007800;">$MailRecipients</span> <span style="color: #007800;">$MailNotification</span> <span style="color: #000000; font-weight: bold;">&amp;</span>lt; <span style="color: #007800;">$LogFile</span></pre></div></div>

<p>Its just a basic script and may needs further enhancements. In case you have suggestion/queries, please put it below in comments.</p>
<p><span style="text-decoration: underline;">More Related and helpful articles:</span></p>
<ul>
<li><a href="http://linuxadminzone.com/optimize-mysql-on-a-large-database-server/"> Setup multiple MySQL database servers in a single Linux host</a></li>
<li><a href="http://linuxadminzone.com/optimize-mysql-on-a-large-database-server/">Optimize MySQL on a large Database Server </a></li>
<li><a href="http://linuxadminzone.com/recover-or-reset-root-password-of-mysql-and-postgresql-servers/">Recover or reset root password of MySQL and PostgreSQL Servers </a></li>
<li><a href="http://linuxadminzone.com/optimize-and-fix-mysql-server-running-slow-without-any-load/"> Optimize and fix MySQL Server running slow without any load </a></li>
<li><a href="http://linuxadminzone.com/find-out-the-clients-of-your-mysql-server/"> How to find out the clients connecting to your MySQL server </a></li>
<li><a href="http://linuxadminzone.com/quickly-repair-a-huge-corrupted-or-crashed-table-in-mysql/"> Quickly repair huge corrupted or crashed table in MySQL </a></li>
<li><a href="http://linuxadminzone.com/install-and-configure-phpmyadmin-to-manage-multiple-mysql-servers/"> Install and configure PhpMyAdmin to manage multiple MySQL Servers </a></li>
</ul>
<p>&nbsp;</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/LinuxAdminZone?a=cBWoPTq6CMo:WCWSrFL6_8A:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/LinuxAdminZone?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/LinuxAdminZone?a=cBWoPTq6CMo:WCWSrFL6_8A:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/LinuxAdminZone?i=cBWoPTq6CMo:WCWSrFL6_8A:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/LinuxAdminZone?a=cBWoPTq6CMo:WCWSrFL6_8A:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/LinuxAdminZone?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/LinuxAdminZone?a=cBWoPTq6CMo:WCWSrFL6_8A:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/LinuxAdminZone?i=cBWoPTq6CMo:WCWSrFL6_8A:D7DqB2pKExk" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/LinuxAdminZone/~4/cBWoPTq6CMo" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://linuxadminzone.com/simple-and-efficient-mongodb-backup-using-script/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://linuxadminzone.com/simple-and-efficient-mongodb-backup-using-script/</feedburner:origLink></item>
		<item>
		<title>A very small bash script challenge</title>
		<link>http://feedproxy.google.com/~r/LinuxAdminZone/~3/h3j1MpxjD08/</link>
		<comments>http://linuxadminzone.com/a-very-small-bash-script-challenge/#comments</comments>
		<pubDate>Wed, 25 Apr 2012 10:35:52 +0000</pubDate>
		<dc:creator>jagbir</dc:creator>
				<category><![CDATA[bash]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[bash if]]></category>

		<guid isPermaLink="false">http://linuxadminzone.com/?p=501</guid>
		<description><![CDATA[*Kind Note*: This was written with a sense of humor to allow visitors quickly discover code anomaly and suggests fixes but if it is not up to your mark, please close your browser tab instead of making unnecessary noise. Thanks You! I am putting a damn small thing here regarding bash script for fun. Here [...]]]></description>
			<content:encoded><![CDATA[<p><strong>*Kind Note*: This was written with a sense of humor to allow visitors quickly discover code anomaly and suggests fixes but if it is not up to your mark, please close your browser tab instead of making unnecessary noise. Thanks You!</strong><br />
I am putting a damn small thing here regarding bash script for fun.</p>
<p>Here it goes: Need to create a bash script which asks for a word from user, say either &#8220;one&#8221;, &#8220;two&#8221; or &#8220;three&#8221; and then check in single if statement (no else if section) that if its not &#8220;one&#8221; or &#8220;two&#8221; or &#8220;three&#8221; then print Not OK otherwise print OK.</p>
<p>Further, here is a snippet, check and figure out why its not working as expected:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-n</span> Enter a word:
<span style="color: #c20cb9; font-weight: bold;">read</span> myword
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$myword</span> <span style="color: #000000; font-weight: bold;">!</span>= <span style="color: #ff0000;">&quot;one&quot;</span> <span style="color: #000000; font-weight: bold;">||</span> <span style="color: #007800;">$myword</span> <span style="color: #000000; font-weight: bold;">!</span>= <span style="color: #ff0000;">&quot;two&quot;</span> <span style="color: #000000; font-weight: bold;">||</span> <span style="color: #007800;">$myword</span> <span style="color: #000000; font-weight: bold;">!</span>= <span style="color: #ff0000;">&quot;three&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
 <span style="color: #7a0874; font-weight: bold;">echo</span> Not OK
<span style="color: #000000; font-weight: bold;">else</span>
 <span style="color: #7a0874; font-weight: bold;">echo</span> OK
<span style="color: #000000; font-weight: bold;">fi</span></pre></div></div>

<p>Please put your suggestion/solution script in comments. </p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/LinuxAdminZone?a=h3j1MpxjD08:Q-qWce-z1xY:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/LinuxAdminZone?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/LinuxAdminZone?a=h3j1MpxjD08:Q-qWce-z1xY:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/LinuxAdminZone?i=h3j1MpxjD08:Q-qWce-z1xY:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/LinuxAdminZone?a=h3j1MpxjD08:Q-qWce-z1xY:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/LinuxAdminZone?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/LinuxAdminZone?a=h3j1MpxjD08:Q-qWce-z1xY:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/LinuxAdminZone?i=h3j1MpxjD08:Q-qWce-z1xY:D7DqB2pKExk" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/LinuxAdminZone/~4/h3j1MpxjD08" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://linuxadminzone.com/a-very-small-bash-script-challenge/feed/</wfw:commentRss>
		<slash:comments>34</slash:comments>
		<feedburner:origLink>http://linuxadminzone.com/a-very-small-bash-script-challenge/</feedburner:origLink></item>
		<item>
		<title>How to setup Git http authentication using LDAP in Apache</title>
		<link>http://feedproxy.google.com/~r/LinuxAdminZone/~3/Ev3T66UEr4M/</link>
		<comments>http://linuxadminzone.com/how-to-setup-git-http-authentication-using-ldap-in-apache/#comments</comments>
		<pubDate>Wed, 18 Apr 2012 13:05:37 +0000</pubDate>
		<dc:creator>jagbir</dc:creator>
				<category><![CDATA[apache]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[Web Server]]></category>
		<category><![CDATA[git http ldap]]></category>

		<guid isPermaLink="false">http://linuxadminzone.com/?p=495</guid>
		<description><![CDATA[In earlier article, I have described setting up git server with gitolite, gitweb, ssh and http auth using passwd file. Here as an extension of that article, I am describing how to do authentication using LDAP so that authentication become more seamless and avoid any sort of manual work for managing access when you have [...]]]></description>
			<content:encoded><![CDATA[<p>In <a href="http://linuxadminzone.com/quickly-setup-git-server-with-gitolite-gitweb-ssh-and-http-auth/" target="_blank">earlier article</a>, I have described setting up git server with gitolite, gitweb, ssh and http auth using passwd file. Here as an extension of that article, I am describing how to do authentication using LDAP so that authentication become more seamless and avoid any sort of manual work for managing access when you have LDAP for authenticating users. </p>
<p>Before proceeding for change in config, you should confirm that ldap and authnz_ldap modules are there in Apache. You can check that using <strong>httpd -M</strong> command, following should be there in output:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ httpd <span style="color: #660033;">-M</span> 
..
 ldap_module <span style="color: #7a0874; font-weight: bold;">&#40;</span>shared<span style="color: #7a0874; font-weight: bold;">&#41;</span>
 authnz_ldap_module <span style="color: #7a0874; font-weight: bold;">&#40;</span>shared<span style="color: #7a0874; font-weight: bold;">&#41;</span>
..</pre></div></div>

<p>If this is not the case, then please install these modules and make sure you load them in your Apache config (usually <strong>/etc/httpd/conf/httpd.conf</strong>) like this:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">LoadModule ldap_module modules<span style="color: #000000; font-weight: bold;">/</span>mod_ldap.so
LoadModule authnz_ldap_module modules<span style="color: #000000; font-weight: bold;">/</span>mod_authnz_ldap.so</pre></div></div>

<p>After having these modules to facilitate authentication, we need to remove or comment out following lines in our git config file <strong>/etc/httpd/conf.d/git.conf</strong>:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;</span>Location <span style="color: #000000; font-weight: bold;">/&gt;</span>
    AuthType Basic
    AuthName <span style="color: #ff0000;">&quot;Private Git Access&quot;</span>
    Require valid-user
    AuthUserFile <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>www<span style="color: #000000; font-weight: bold;">/</span>gitweb<span style="color: #000000; font-weight: bold;">/</span>passfile
<span style="color: #000000; font-weight: bold;">&lt;/</span>Location<span style="color: #000000; font-weight: bold;">&gt;</span></pre></div></div>

<p>After removing or commenting out above lines, put these lines in the file:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;</span>Location <span style="color: #ff0000;">&quot;/&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span>
    AuthType Basic
    AuthName <span style="color: #ff0000;">&quot;Git Authentication&quot;</span>
    AuthBasicProvider ldap
    AuthzLDAPAuthoritative off
    AuthLDAPURL <span style="color: #ff0000;">&quot;ldap://&lt;my ad server&gt;:389/ou=xx,dc=xx,dc=xx,dc=com?sAMAccountName?sub?(objectClass=user)&quot;</span>
    AuthLDAPBindDN <span style="color: #000000; font-weight: bold;">&lt;</span>user<span style="color: #000000; font-weight: bold;">&gt;@&lt;</span>mydomain<span style="color: #000000; font-weight: bold;">&gt;</span>
    AuthLDAPBindPassword <span style="color: #000000; font-weight: bold;">&lt;</span>user password<span style="color: #000000; font-weight: bold;">&gt;</span>
    Require valid-user
<span style="color: #000000; font-weight: bold;">&lt;/</span>Location<span style="color: #000000; font-weight: bold;">&gt;</span></pre></div></div>

<p>Here make sure to supply correct LDAP url and provide info of one user and its password so that Apache can contact LDAP to retrieve authentication information. You also needs to update <strong>gitolite.conf</strong> to manage authorization for git repositories for LDAP user. </p>
<p>Reload Apache to apply new settings and you should be able to access Git repository over http using LDAP user.</p>
<p><strong>Common issues:</strong><br />
If authentication not working, put &#8220;<strong>Loglevel Debug</strong>&#8221; option in your Apache VirtualHost and check Apache error logs. In case you notice following error:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">&#91;</span>Wed Apr <span style="color: #000000;">18</span> <span style="color: #000000;">15</span>:02:<span style="color: #000000;">13</span> <span style="color: #000000;">2012</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>debug<span style="color: #7a0874; font-weight: bold;">&#93;</span> mod_authnz_ldap.c<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">454</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>: <span style="color: #7a0874; font-weight: bold;">&#91;</span>client xx.xx.xx.xx<span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">25749</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> auth_ldap authenticate: accepting user.name
<span style="color: #7a0874; font-weight: bold;">&#91;</span>Wed Apr <span style="color: #000000;">18</span> <span style="color: #000000;">15</span>:02:<span style="color: #000000;">13</span> <span style="color: #000000;">2012</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>debug<span style="color: #7a0874; font-weight: bold;">&#93;</span> mod_authnz_ldap.c<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">821</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>: <span style="color: #7a0874; font-weight: bold;">&#91;</span>client xx.xx.xx.xx<span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">25749</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> auth_ldap authorise: declining to authorise</pre></div></div>

<p>Then make sure <strong>AuthzLDAPAuthoritative off</strong> entry is there in Apache git config file, I have already mentioned it above just in case if you missed it.</p>
<p>In case you notice &#8220;<strong>[User Not Found]</strong>&#8221; in error log, then check your user name again and make sure the user exist in correct OU/group specified in ldap url.</p>
<p>Related articles:<br />
* <a href="http://linuxadminzone.com/quickly-setup-git-server-with-gitolite-gitweb-ssh-and-http-auth/" target="_blank"> Quickly setup Git server with gitolite, gitweb, ssh and http auth </a><br />
* <a href="http://linuxadminzone.com/configure-password-based-subversion-access-via-http-for-multiple-users/" target="_blank"> Configure password based subversion access via http </a><br />
* <a href="http://linuxadminzone.com/download-install-and-configure-viewvc-for-subversion/" target="_blank"> Download, install and configure ViewVC for Subversion </a></p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/LinuxAdminZone?a=Ev3T66UEr4M:6uqi_EKhaDc:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/LinuxAdminZone?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/LinuxAdminZone?a=Ev3T66UEr4M:6uqi_EKhaDc:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/LinuxAdminZone?i=Ev3T66UEr4M:6uqi_EKhaDc:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/LinuxAdminZone?a=Ev3T66UEr4M:6uqi_EKhaDc:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/LinuxAdminZone?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/LinuxAdminZone?a=Ev3T66UEr4M:6uqi_EKhaDc:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/LinuxAdminZone?i=Ev3T66UEr4M:6uqi_EKhaDc:D7DqB2pKExk" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/LinuxAdminZone/~4/Ev3T66UEr4M" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://linuxadminzone.com/how-to-setup-git-http-authentication-using-ldap-in-apache/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://linuxadminzone.com/how-to-setup-git-http-authentication-using-ldap-in-apache/</feedburner:origLink></item>
		<item>
		<title>Quickly setup git server with gitolite, gitweb, ssh and http auth</title>
		<link>http://feedproxy.google.com/~r/LinuxAdminZone/~3/2maJg-vi1a4/</link>
		<comments>http://linuxadminzone.com/quickly-setup-git-server-with-gitolite-gitweb-ssh-and-http-auth/#comments</comments>
		<pubDate>Fri, 30 Mar 2012 08:26:17 +0000</pubDate>
		<dc:creator>jagbir</dc:creator>
				<category><![CDATA[apache]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[gitolite]]></category>
		<category><![CDATA[gitweb]]></category>

		<guid isPermaLink="false">http://linuxadminzone.com/?p=482</guid>
		<description><![CDATA[As per the official definition, Git is a free &#38; open source, distributed version control system designed to handle everything from small to very large projects with speed and efficiency. I am describing here steps which I followed to setup a Git server along with Gitolite, Gitweb, ssh and http auth in RHEL5 machine. I [...]]]></description>
			<content:encoded><![CDATA[<p>As per the official definition, <a href="http://git-scm.com/" target="_blank">Git</a> is a <strong>free &amp; open source, distributed version control system</strong> designed to handle everything from small to very large projects with speed and efficiency. I am describing here steps which I followed to setup a Git server along with Gitolite, Gitweb, ssh and http auth in RHEL5 machine. I have done the installations using RPMs (lazy men&#8217;s method) which I got from here: <a href="http://pkgs.repoforge.org/git/">http://pkgs.repoforge.org/git/</a></p>
<p><strong>Step 1: Download the required RPMs or install using source</strong></p>
<p>Here are the RPMs I downloaded from source mentioned above (of course, download the latest version of these RPMs when you wants to do installation):</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">git-1.7.8.2-<span style="color: #000000;">2</span>.el5.rf.x86_64.rpm
gitolite-1.5.9.1-<span style="color: #000000;">2</span>.el5.noarch.rpm
gitweb-1.7.8.2-<span style="color: #000000;">2</span>.el5.rf.x86_64.rpm</pre></div></div>

<p>You may also need to have some perl dependencies which you can install through CPAN or can also download the RPMs for them, I needed below ones:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">perl-DBI-<span style="color: #000000;">1.617</span>-<span style="color: #000000;">1</span>.el5.rfx.x86_64.rpm
perl-Git-1.7.8.2-<span style="color: #000000;">2</span>.el5.rf.x86_64.rpm
perl-TermReadKey-<span style="color: #000000;">2.30</span>-<span style="color: #000000;">3</span>.el5.rf.x86_64.rpm <span style="color: #7a0874; font-weight: bold;">&#40;</span>Optional<span style="color: #7a0874; font-weight: bold;">&#41;</span>
perl-Error-<span style="color: #000000;">0.17017</span>-<span style="color: #000000;">1</span>.el5.rf.noarch.rpm <span style="color: #7a0874; font-weight: bold;">&#40;</span>Optional<span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></div></div>

<p><strong>Step 2: Install the RPMs:</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ rpm <span style="color: #660033;">-ivh</span> perl-DBI-<span style="color: #000000;">1.617</span>-<span style="color: #000000;">1</span>.el5.rfx.x86_64.rpm perl-TermReadKey-<span style="color: #000000;">2.30</span>-<span style="color: #000000;">3</span>.el5.rf.x86_64.rpm perl-Error-<span style="color: #000000;">0.17017</span>-<span style="color: #000000;">1</span>.el5.rf.noarch.rpm git-1.7.8.2-<span style="color: #000000;">2</span>.el5.rf.x86_64.rpm perl-Git-1.7.8.2-<span style="color: #000000;">2</span>.el5.rf.x86_64.rpm  gitolite-1.5.9.1-<span style="color: #000000;">2</span>.el5.noarch.rpm gitweb-1.7.8.2-<span style="color: #000000;">2</span>.el5.rf.x86_64.rpm</pre></div></div>

<p>We have Git, Gitolite and Gitweb installed now.</p>
<p><strong>Step 3: Configure Gitolite for authentication/authorization: </strong></p>
<p>We need to configure Gitolite and the information for that is already described <a href="http://sitaramc.github.com/gitolite/rpmdeb.html" target="_blank">here</a> so I am skipping that part.</p>
<p><strong>Step 4: (Optional) Test Git with Gitolite:</strong></p>
<p>Its worth a try to quickly test Git with Gitolite you just installed/configured. Jump to your pc and if you have Linux, generate public/private keys using ssh-keygen utility in case you already don’t have, for testing purposes, you can use following command:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">ssh-keygen</span> <span style="color: #660033;">-N</span> <span style="color: #ff0000;">''</span> <span style="color: #660033;">-t</span> rsa <span style="color: #660033;">-f</span> <span style="color: #000000; font-weight: bold;">/</span>root<span style="color: #000000; font-weight: bold;">/</span>.ssh<span style="color: #000000; font-weight: bold;">/</span>id_rsa</pre></div></div>

<p>In case you are using Windows (which unfortunately I am using as of now), you can use puttygen utility and can refer a good tutorial <a href="http://sshcontrol.com/help/puttygen_keys" target="_blank">here</a> for exact process.</p>
<p>Copy your public key file to Git server, rename it to yourname.pub and put it in this directory so that Gitolite can refer/read them when needed: /var/lib/gitolite/.gitolite/keydir/</p>
<p>Time to clone gitolite-admin repository now, for Linux, just use:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">git</span> clone <span style="color: #c20cb9; font-weight: bold;">git</span><span style="color: #000000; font-weight: bold;">@</span>serverip:gitolite-admin</pre></div></div>

<p>For Windows, you can install <a href="http://code.google.com/p/msysgit/downloads/detail?name=Git-1.7.9-preview20120201.exe&amp;can=2&amp;q" target="_blank">msysgit</a> and optionally you can install a cool Git client like TortoiseGit from <a href="http://code.google.com/p/tortoisegit/downloads/detail?name=TortoiseGit-1.7.7.0-32bit.msi&amp;can=2&amp;q" target="_blank">here</a>. To Clone the gitolite-admin repository now, browse any directory, right click, choose <strong>Git Clone…</strong> and put required information. A sample screenshot is below:</p>
<p>Clone should get successful and you will get gitolite-admin repository in your pc. Go inside and update gitolite.conf to add new repositories/users. This process is described <a href="http://sitaramc.github.com/gitolite/pictures.html#1000_words_adding_users_to_gitolite_" target="_blank">here</a> if you want to continue testing.</p>
<p><strong>Step 5: Configure Gitweb, http access of Git</strong></p>
<p>This process is also documented by original author <a href="http://sitaramc.github.com/gitolite/ggshb.html" target="_blank">here</a> but that is for OpenSuSE and while following that, I ran in some issues, so here posting information to setup this in RHEL machine which is working for me. You may want to refer that documentation in case things are not very clear reading my instructions because I am not diving in details and focus is more on practical execution.</p>
<p>Add following line in <strong>/var/lib/gitolite/.gitolite.rc</strong> file:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #007800;">$GL_GITCONFIG_KEYS</span> = <span style="color: #ff0000;">&quot;gitweb.url receive.denyNonFastforwards receive.denyDeletes&quot;</span>;</pre></div></div>

<p>Add some config entries in gitolite.conf file along with entry for daemon user. My gitolite.conf looks like below:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>gitolite<span style="color: #000000; font-weight: bold;">/</span>.gitolite<span style="color: #000000; font-weight: bold;">/</span>conf<span style="color: #000000; font-weight: bold;">/</span>gitolite.conf
repo    gitolite-admin
RW+     =   <span style="color: #c20cb9; font-weight: bold;">git</span> daemon
&nbsp;
repo    tproject
RW      = <span style="color: #c20cb9; font-weight: bold;">git</span> jagbir daemon
R       = <span style="color: #000000; font-weight: bold;">@</span>all
config  gitweb.url = <span style="color: #c20cb9; font-weight: bold;">git</span><span style="color: #000000; font-weight: bold;">@</span>serverip:tproject
config  receive.denyNonFastforwards = <span style="color: #c20cb9; font-weight: bold;">true</span>
config  receive.denyDeletes         = <span style="color: #c20cb9; font-weight: bold;">true</span>
&nbsp;
repo    <span style="color: #000000; font-weight: bold;">@</span>all
R       =   daemon gitweb</pre></div></div>

<p>Don’t forget to add daemon in all repositories, whether for Read write or just read to enabling browsing through http.</p>
<p><strong>Step 6: Configure Apache under SuExec:</strong><br />
Apache runs under <strong>Apache</strong> user while our Git repositories are under <strong>Gitolite</strong> user. We have to use <strong>SuExec</strong> module in Apache so that it will also run under <strong>Gitolite</strong> user and be able to update information in repositories. Confirm that SuExec module is there in you Apache by running: <strong>$ httpd –M</strong> command and you should have <strong>suexec_module (shared)</strong> line in output.</p>
<p>Update permissions of suexec program. We also needs to have a wrapper script and to know where to put it check options of suexec, here are commands:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">chgrp</span> apache <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>sbin<span style="color: #000000; font-weight: bold;">/</span>suexec
$ <span style="color: #c20cb9; font-weight: bold;">chmod</span> <span style="color: #000000;">4750</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>sbin<span style="color: #000000; font-weight: bold;">/</span>suexec
$ <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>sbin<span style="color: #000000; font-weight: bold;">/</span>suexec <span style="color: #660033;">-V</span>
<span style="color: #660033;">-D</span> <span style="color: #007800;">AP_DOC_ROOT</span>=<span style="color: #ff0000;">&quot;/var/www&quot;</span>
<span style="color: #660033;">-D</span> <span style="color: #007800;">AP_GID_MIN</span>=<span style="color: #000000;">100</span>
<span style="color: #660033;">-D</span> <span style="color: #007800;">AP_HTTPD_USER</span>=<span style="color: #ff0000;">&quot;apache&quot;</span>
<span style="color: #660033;">-D</span> <span style="color: #007800;">AP_LOG_EXEC</span>=<span style="color: #ff0000;">&quot;/var/log/httpd/suexec.log&quot;</span>
<span style="color: #660033;">-D</span> <span style="color: #007800;">AP_SAFE_PATH</span>=<span style="color: #ff0000;">&quot;/usr/local/bin:/usr/bin:/bin&quot;</span>
<span style="color: #660033;">-D</span> <span style="color: #007800;">AP_UID_MIN</span>=<span style="color: #000000;">500</span>
<span style="color: #660033;">-D</span> <span style="color: #007800;">AP_USERDIR_SUFFIX</span>=<span style="color: #ff0000;">&quot;public_html&quot;</span></pre></div></div>

<p>So path for our wrapper script and Gitweb is /var/www as shown above in AP_DOC_ROOT value. Create a wrapper script in /var/www/bin/ directory (create bin directory first). My script looks like below which you can copy as is:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>www<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>gitolite-suexec-wrapper.sh
<span style="color: #666666; font-style: italic;">#!/bin/bash</span>
&nbsp;
<span style="color: #007800;">USER</span>=<span style="color: #007800;">$1</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">GIT_PROJECT_ROOT</span>=<span style="color: #ff0000;">&quot;/var/lib/gitolite/repositories&quot;</span>
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">GITOLITE_HTTP_HOME</span>=<span style="color: #ff0000;">&quot;/var/lib/gitolite&quot;</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">exec</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>gl-auth-command <span style="color: #007800;">$USER</span></pre></div></div>

<p>Because Gitweb will also runs under gitolite user, copy all of its files to /var/www directory and make sure the owner of /var/www directory (along with all subdirectories/files should be gitolite user), here are commands:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">cp</span> <span style="color: #660033;">-r</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>gitweb <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>www
$ <span style="color: #c20cb9; font-weight: bold;">chown</span> –R gitolite.gitolite <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>www</pre></div></div>

<p>Update gitweb.conf file to point to gitolite directory where all repositories are there, below line should be there in <strong>/etc/gitweb.conf</strong> file:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">our <span style="color: #007800;">$projectroot</span> = <span style="color: #ff0000;">&quot;/var/lib/gitolite&quot;</span>;</pre></div></div>

<p><strong>Step 7: Configure Virtualhost in Apache:</strong><br />
Here is my apache virtual host file, which you can copy as is (of course, change ServerName, Alias etc as per your values):</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$  <span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>httpd<span style="color: #000000; font-weight: bold;">/</span>conf.d<span style="color: #000000; font-weight: bold;">/</span>git.conf
&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;</span>VirtualHost <span style="color: #000000; font-weight: bold;">*</span>:<span style="color: #000000;">80</span><span style="color: #000000; font-weight: bold;">&gt;</span>
&nbsp;
ServerName  git.mydomain.com
ServerAlias <span style="color: #c20cb9; font-weight: bold;">git</span>
&nbsp;
DocumentRoot <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>www<span style="color: #000000; font-weight: bold;">/</span>gitweb
&nbsp;
SuexecUserGroup gitolite gitolite
&nbsp;
SetEnv GIT_PROJECT_ROOT <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>gitolite<span style="color: #000000; font-weight: bold;">/</span>projects
SetEnv GIT_HTTP_EXPORT_ALL
&nbsp;
SetEnv GITOLITE_HTTP_HOME <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>gitolite
&nbsp;
ScriptAliasMatch \
<span style="color: #ff0000;">&quot;(?x)^/(.*/(HEAD | <span style="color: #000099; font-weight: bold;">\
</span>info/refs | <span style="color: #000099; font-weight: bold;">\
</span>objects/(info/[^/]+ | <span style="color: #000099; font-weight: bold;">\
</span>[0-9a-f]{2}/[0-9a-f]{38} | <span style="color: #000099; font-weight: bold;">\
</span>pack/pack-[0-9a-f]{40}\.(pack|idx)) | <span style="color: #000099; font-weight: bold;">\
</span>git-(upload|receive)-pack))$&quot;</span> \
<span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>www<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>gitolite-suexec-wrapper.sh<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$1</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;</span>Directory <span style="color: #ff0000;">&quot;/var/www/gitweb&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span>
Options ExecCGI
AllowOverride None
AddHandler cgi-script .cgi
DirectoryIndex gitweb.cgi
Order allow,deny
Allow from all
<span style="color: #000000; font-weight: bold;">&lt;/</span>Directory<span style="color: #000000; font-weight: bold;">&gt;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;</span>Directory <span style="color: #ff0000;">&quot;/var/www/bin&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;</span>Files <span style="color: #ff0000;">&quot;gitolite-suexec-wrapper.sh&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span>
Order allow,deny
Allow from all
<span style="color: #000000; font-weight: bold;">&lt;/</span>Files<span style="color: #000000; font-weight: bold;">&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;/</span>Directory<span style="color: #000000; font-weight: bold;">&gt;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;</span>Location <span style="color: #000000; font-weight: bold;">/&gt;</span>
AuthType Basic
AuthName <span style="color: #ff0000;">&quot;Git Access&quot;</span>
Require valid-user
AuthUserFile <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>www<span style="color: #000000; font-weight: bold;">/</span>gitweb<span style="color: #000000; font-weight: bold;">/</span>authfile
<span style="color: #000000; font-weight: bold;">&lt;/</span>Location<span style="color: #000000; font-weight: bold;">&gt;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;/</span>VirtualHost<span style="color: #000000; font-weight: bold;">&gt;</span></pre></div></div>

<p>As you can see we are using basic authentication here and for that, you need to create file which will have auth information, create file and sample user (gitolite) to test it:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ htpasswd <span style="color: #660033;">-cmd</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>gitolite<span style="color: #000000; font-weight: bold;">/</span>authfile gitolite
New password:
Re-type new password:
Adding password <span style="color: #000000; font-weight: bold;">for</span> user gitolite
&nbsp;
$ <span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>gitolite<span style="color: #000000; font-weight: bold;">/</span>authfile
gitolite:wG7<span style="color: #000000; font-weight: bold;">/</span>EAcl9kdvU</pre></div></div>

<p>Make sure you have initialize the repository to enable its access via http, let&#8217;s prepare testing repository for this purpose:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>gitolite<span style="color: #000000; font-weight: bold;">/</span>repositories<span style="color: #000000; font-weight: bold;">/</span>testing.git
$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #660033;">-u</span> gitolite <span style="color: #c20cb9; font-weight: bold;">git</span> <span style="color: #660033;">--bare</span> init
$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #660033;">-u</span> gitolite <span style="color: #c20cb9; font-weight: bold;">git</span> update-server-info
$ <span style="color: #c20cb9; font-weight: bold;">mv</span> hooks<span style="color: #000000; font-weight: bold;">/</span>post-update.sample hooks<span style="color: #000000; font-weight: bold;">/</span>post-update
$ <span style="color: #c20cb9; font-weight: bold;">chmod</span> +x hooks<span style="color: #000000; font-weight: bold;">/</span>post-update</pre></div></div>

<p>The above steps are needed for http access otherwise you will get error like below in your apache error logs when trying to clone:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">&#91;</span>Tue Apr <span style="color: #000000;">10</span> <span style="color: #000000;">15</span>:<span style="color: #000000;">34</span>:<span style="color: #000000;">16</span> <span style="color: #000000;">2012</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>error<span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>client <span style="color: #000000;">10.100</span>.xx.xx<span style="color: #7a0874; font-weight: bold;">&#93;</span> Repository not exported: <span style="color: #ff0000;">'/var/lib/gitolite/repositories/testing'</span></pre></div></div>

<p>All files under /var/www should have gitolite as owner, let’s update permissions once more:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$  <span style="color: #c20cb9; font-weight: bold;">chown</span> <span style="color: #660033;">-R</span> gitolite:gitolite <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>www</pre></div></div>

<p><strong>Step 7: Test it out: </strong><br />
Restart apache and try to browse your server now: <a href="http://serverip">http://serverip</a>. It should ask username/password and after supply correct, you should be able to see gitweb interface showing your repositories where you can traverse in them.</p>
<p>In case you see a blank page, then it might be issue with SuExec. Check suexec log file:  /var/log/httpd/suexec.log. You may see a message like:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">2012</span>-03-<span style="color: #000000;">30</span> 04:<span style="color: #000000;">14</span>:<span style="color: #000000;">26</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>: cannot run <span style="color: #c20cb9; font-weight: bold;">as</span> forbidden uid <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">100</span><span style="color: #000000; font-weight: bold;">/</span>gitweb.cgi<span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></div></div>

<p>This means suexec won’t execute under user/group have userid/groupid less than 500 (system). In this case you can change this id for our gitolite user as per below:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ usermod <span style="color: #660033;">-u</span> <span style="color: #000000;">650</span> gitolite
$ groupmod <span style="color: #660033;">-g</span> <span style="color: #000000;">650</span> gitolite</pre></div></div>

<p>650 is just an example here, you can use any value above 500 in case 650 is already used by existing user/group. As user/group id get changed, you need to set permissions again for your directories:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">chown</span> –R gitolite:gitolite <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>www</pre></div></div>

<p>Try now and you should be able to browse smoothly. Please put a comment below if you are still facing any issues, I would try to help you out.</p>
<p>Update: If you want to perform authentication using LDAP for git which I have described in next article, you can access it using below link: </p>
<p>* <a href="http://linuxadminzone.com/how-to-setup-git-http-authentication-using-ldap-in-apache/" target="_blank"> Setup Git auth using LDAP </a></p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/LinuxAdminZone?a=2maJg-vi1a4:ieyV5ENOJwc:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/LinuxAdminZone?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/LinuxAdminZone?a=2maJg-vi1a4:ieyV5ENOJwc:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/LinuxAdminZone?i=2maJg-vi1a4:ieyV5ENOJwc:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/LinuxAdminZone?a=2maJg-vi1a4:ieyV5ENOJwc:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/LinuxAdminZone?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/LinuxAdminZone?a=2maJg-vi1a4:ieyV5ENOJwc:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/LinuxAdminZone?i=2maJg-vi1a4:ieyV5ENOJwc:D7DqB2pKExk" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/LinuxAdminZone/~4/2maJg-vi1a4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://linuxadminzone.com/quickly-setup-git-server-with-gitolite-gitweb-ssh-and-http-auth/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://linuxadminzone.com/quickly-setup-git-server-with-gitolite-gitweb-ssh-and-http-auth/</feedburner:origLink></item>
		<item>
		<title>Fix mysql memory table error: The table xtable is full</title>
		<link>http://feedproxy.google.com/~r/LinuxAdminZone/~3/HB7pnh_mCE0/</link>
		<comments>http://linuxadminzone.com/fix-mysql-memory-table-error-the-table-xtable-is-full/#comments</comments>
		<pubDate>Mon, 20 Feb 2012 08:34:55 +0000</pubDate>
		<dc:creator>jagbir</dc:creator>
				<category><![CDATA[database]]></category>
		<category><![CDATA[memory table]]></category>
		<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://linuxadminzone.com/?p=474</guid>
		<description><![CDATA[Replication just stopped in one Slave server with error: The table xtable is full which means no more records are permitted to insert in this table by MySQL and hence this has broken the replication. I checked that xtable is having storage engine as Memory. In such tables, the max. no. of records you can [...]]]></description>
			<content:encoded><![CDATA[<p>Replication just stopped in one Slave server with error: The table xtable is full which means no more records are permitted to insert in this table by MySQL and hence this has broken the replication. </p>
<p>I checked that xtable is having storage engine as Memory. In such tables, the max. no. of records you can insert is controlled by variable <a href="http://dev.mysql.com/doc/refman/5.1/en/server-system-variables.html#sysvar_max_heap_table_size" target="_blank">max_heap_table_size</a>. When checking the size of this variable, I found that this is having default value:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">mysql<span style="color: #000000; font-weight: bold;">&gt;</span> show variables like <span style="color: #ff0000;">'max_heap_table_size'</span>;
+---------------------+----------+
<span style="color: #000000; font-weight: bold;">|</span> Variable_name       <span style="color: #000000; font-weight: bold;">|</span> Value    <span style="color: #000000; font-weight: bold;">|</span>
+---------------------+----------+
<span style="color: #000000; font-weight: bold;">|</span> max_heap_table_size <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000;">16777216</span> <span style="color: #000000; font-weight: bold;">|</span>
+---------------------+----------+
<span style="color: #000000;">1</span> row <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000; font-weight: bold;">set</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">0.00</span> sec<span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></div></div>

<p>So we need to increase the value of this variable and then issue Alter Table command to make it effective. Also do not forget to add variable with new value in your my.cnf. </p>
<p>Change the variable value:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">mysql<span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">set</span>  <span style="color: #007800;">max_heap_table_size</span>=<span style="color: #000000;">268435456</span>;
Query OK, <span style="color: #000000;">0</span> rows affected <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">0.00</span> sec<span style="color: #7a0874; font-weight: bold;">&#41;</span>
&nbsp;
mysql<span style="color: #000000; font-weight: bold;">&gt;</span> show variables like <span style="color: #ff0000;">'max_heap_table_size'</span>;
+---------------------+-----------+
<span style="color: #000000; font-weight: bold;">|</span> Variable_name       <span style="color: #000000; font-weight: bold;">|</span> Value     <span style="color: #000000; font-weight: bold;">|</span>
+---------------------+-----------+
<span style="color: #000000; font-weight: bold;">|</span> max_heap_table_size <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000;">268435456</span> <span style="color: #000000; font-weight: bold;">|</span>
+---------------------+-----------+
<span style="color: #000000;">1</span> row <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000; font-weight: bold;">set</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">0.00</span> sec<span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></div></div>

<p>Now let&#8217;s truncate the table and issue Alter table on it to make the value effective for this table:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">mysql<span style="color: #000000; font-weight: bold;">&gt;</span> truncate table xtable;
Query OK, <span style="color: #000000;">0</span> rows affected <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">0.00</span> sec<span style="color: #7a0874; font-weight: bold;">&#41;</span>
&nbsp;
mysql<span style="color: #000000; font-weight: bold;">&gt;</span> alter table xtable <span style="color: #007800;">ENGINE</span>=MEMORY;
Query OK, <span style="color: #000000;">88</span> rows affected <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">0.06</span> sec<span style="color: #7a0874; font-weight: bold;">&#41;</span>
Records: <span style="color: #000000;">88</span>  Duplicates: <span style="color: #000000;">0</span>  Warnings: <span style="color: #000000;">0</span></pre></div></div>

<p>After this fix, the issue has been resolved. Make sure that you do not run the truncate command on table which have important data. I have issued truncate because it contains temporary/transactional data so we are fine with removing all records here.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/LinuxAdminZone?a=HB7pnh_mCE0:pRyk2fmOR2c:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/LinuxAdminZone?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/LinuxAdminZone?a=HB7pnh_mCE0:pRyk2fmOR2c:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/LinuxAdminZone?i=HB7pnh_mCE0:pRyk2fmOR2c:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/LinuxAdminZone?a=HB7pnh_mCE0:pRyk2fmOR2c:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/LinuxAdminZone?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/LinuxAdminZone?a=HB7pnh_mCE0:pRyk2fmOR2c:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/LinuxAdminZone?i=HB7pnh_mCE0:pRyk2fmOR2c:D7DqB2pKExk" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/LinuxAdminZone/~4/HB7pnh_mCE0" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://linuxadminzone.com/fix-mysql-memory-table-error-the-table-xtable-is-full/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://linuxadminzone.com/fix-mysql-memory-table-error-the-table-xtable-is-full/</feedburner:origLink></item>
	</channel>
</rss>

