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

<channel>
	<title>chrisadams.me.uk &#187; sysadmin</title>
	<atom:link href="http://chrisadams.me.uk/tag/sysadmin/feed/" rel="self" type="application/rss+xml" />
	<link>http://chrisadams.me.uk</link>
	<description>Hoping to think more clearly, through thinking out loud</description>
	<lastBuildDate>Sun, 29 Aug 2010 09:29:20 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>Looking for the best way to keep data on servers safe</title>
		<link>http://chrisadams.me.uk/2010/07/16/looking-for-the-best-way-to-keep-data-on-servers-safe/</link>
		<comments>http://chrisadams.me.uk/2010/07/16/looking-for-the-best-way-to-keep-data-on-servers-safe/#comments</comments>
		<pubDate>Fri, 16 Jul 2010 23:33:42 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[sysadmin]]></category>
		<category><![CDATA[backups]]></category>
		<category><![CDATA[cloud]]></category>

		<guid isPermaLink="false">http://chrisadams.me.uk/?p=345</guid>
		<description><![CDATA[We know we should all be doing it, but most of us don't do it enough. I put out a request today to my followers Twitter asking this question: I've had the following services recommended to me by a number of fellow developers whose opinions I have a lot of respect for: A couple of [...]]]></description>
			<content:encoded><![CDATA[<p>We know we should all be doing it, but most of us don't do it enough.</p>
<p>I put out a request today to my followers Twitter asking this question:</p>
<p>I've had the following services recommended to me by a number of fellow developers whose opinions I have a lot of respect for:</p>
<p>A couple of ex-Headshifters pointed me to <a href="http://duplicity.nongnu.org/" title="duplicity: Main">Duplicity</a>, a free tool that also looks very promising. Using it looks pretty straight forward.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">    duplicity <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>my_directory <span style="color: #c20cb9; font-weight: bold;">scp</span>:<span style="color: #000000; font-weight: bold;">//</span>backup<span style="color: #000000; font-weight: bold;">@</span>other.host<span style="color: #000000; font-weight: bold;">//</span>usr<span style="color: #000000; font-weight: bold;">/</span>backup</pre></div></div>

<p>A variant of it can be used to backup to Amazon S3 too, and <a href="http://blog.damontimm.com/how-to-automated-secure-encrypted-incremental-backups-amazon-s3-duplicity-os-x-or-ubuntu" title="How To: Automated Encrypted Incremental Backups on Amazon S3 with Duplicity (OS X or Ubuntu) &laquo;  damontimm.com">there's a helpful blog post to show how to do this here</a>, if you use Ubuntu or OSX.</p>
<p><a href="http://twitter.com/kalv/status/18672139356">Kalv</a> recommended <a href="[http://github.com/astrails/safe]" title="astrails's safe at master - GitHub">Safe</a>, a clever Ruby gem by the Astrails crew that was originally designed to automate the backing up of Rails projects in a simple fashion.</p>
<p>One service that looks really interesting is though is Tarsnap, as recommended by [Jon Gilbrath][]. It's similarly simple to use, but takes care of the some of the more awkwards backup issues, and saves you having to setup your own S3 account.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">  <span style="color: #666666; font-style: italic;"># Create an archive named &quot;mybackup&quot; containing /usr/home and /other/stuff:</span>
  tarsnap <span style="color: #660033;">-c</span> <span style="color: #660033;">-f</span> mybackup <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>home <span style="color: #000000; font-weight: bold;">/</span>other<span style="color: #000000; font-weight: bold;">/</span>stuff</pre></div></div>

<p>The developer, Colin Percival also has written quite extensively <a href="http://www.daemonology.net/blog/2008-12-14-how-tarsnap-uses-aws.html" title="How Tarsnap uses Amazon Web Services">about how it works on his own blog</a> - he's only making a few cents per gigabyte on providing this service for people, yet it still looks to be something viable for him to run - amazing.</p>
<p>It looks like it's almost exactly what I'm after - the only thing missing is the option to back up storage inside the EU. This requirement is mainly one coming from data protection concerns from previous clients, because rules for processing data and storing in in the EU are different to that in the US, but given the strength of encryption, I'm not sure how much of an issue this really is, these days.</p>
<p>I'd really appreciate some light shed on this actually - technology is moving so much faster than law these days, it's frustrating not being able to take advantage of these kinds of services.</p>
<p>Anyway that's what I've found. What do you use, and why?</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://chrisadams.me.uk/wordpress/wp-content/plugins/add-to-any/share_save_171_16.gif" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://chrisadams.me.uk/2010/07/16/looking-for-the-best-way-to-keep-data-on-servers-safe/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Tar is not zip</title>
		<link>http://chrisadams.me.uk/2010/05/17/tar-is-not-zip/</link>
		<comments>http://chrisadams.me.uk/2010/05/17/tar-is-not-zip/#comments</comments>
		<pubDate>Mon, 17 May 2010 01:40:54 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Journal]]></category>
		<category><![CDATA[commandline]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[sysadmin]]></category>
		<category><![CDATA[tar]]></category>
		<category><![CDATA[zip]]></category>

		<guid isPermaLink="false">http://chrisadams.me.uk/?p=284</guid>
		<description><![CDATA[Today, I had to package up some code that was residing on a remote server that I had ssh access to, to send to someone who was probably on a windows box. This meant I had to use the zip tool, which I can never remember how to use, hence this memory jogging post. Now [...]]]></description>
			<content:encoded><![CDATA[<p>Today, I had to package up some code that was residing on a remote server that I had ssh access to, to send to someone who was probably on a windows box.</p>
<p>This meant I had to use the <code>zip</code> tool, which I can never remember how to use, hence this memory jogging post.</p>
<p>Now if someone's using a Mac or is on Linux, the normal command line approach to to tar up a directory to send to someone goes like this:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">tar</span> <span style="color: #660033;">-cvzf</span> my_tarfile.tar.gz a_directory_to_tar and_otherone_here</pre></div></div>

<p>We're calling <code>tar</code> here, with the -create <em>(c)</em>, file <em>(f)</em>, compress <em>(z)</em> oh, and the verbose <em>(f)</em>, flag. Think of that string like saying to the computer: "create the tarfile <code>my_tarfile</code> putting it into a file we just created, verbosely, while compressing it, from <code>a_directory_to_tar</code> and <code>and_otherone_here</code>".</p>
<p>As commands go, the order feels a bit weird at first, but you get the hang eventually.</p>
<h4>Where zip is different</h4>
<p>Using <code>zip</code> isn't too different really, but it you need to remember to tell it to zip recursively (why is this not default behaviour?). If we call command:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">zip</span> archive a_directory_to_tar and_otherone_here</pre></div></div>

<p>We'll end up with an rather useless empty file called <code>archive.zip</code>. We need to pass in the recursive flag</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">zip</span> <span style="color: #660033;">-r</span> archive a_directory_to_tar and_otherone_here</pre></div></div>

<p>There's also no need to add the <code>.zip</code> file extension - this is added for you as a courtesy. Well, after that ridiculous non-recursive default shenanigans, frankly that's the least it could do...</p>
<p>Anyway, there you have it. The differences you between them if you don't want to dive into the manpages just to package up a folder for somebody, or look at this <a href="http://linux.about.com/od/commands/a/blcmdl1_zipx.htm" title="Example uses of the Linux Command zip">linux.about.com</a>.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://chrisadams.me.uk/wordpress/wp-content/plugins/add-to-any/share_save_171_16.gif" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://chrisadams.me.uk/2010/05/17/tar-is-not-zip/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to fix a WordPress site when the database corrupts on you.</title>
		<link>http://chrisadams.me.uk/2010/05/16/how-to-fix-a-wordpress-site-when-the-database-corrupts-on-you/</link>
		<comments>http://chrisadams.me.uk/2010/05/16/how-to-fix-a-wordpress-site-when-the-database-corrupts-on-you/#comments</comments>
		<pubDate>Sun, 16 May 2010 23:43:47 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Journal]]></category>
		<category><![CDATA[meta]]></category>
		<category><![CDATA[sysadmin]]></category>
		<category><![CDATA[fix]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[scares]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://chrisadams.me.uk/?p=280</guid>
		<description><![CDATA[Phew! ... and as soon as I say this, the database powering this site corrupts on me - charming! For one awful moment I thought I had lost everything (I hadn't set up a regular mysql backup task for this blog), but thankfully, bringing this blog back from the dead was surprisingly straight forward. Here's [...]]]></description>
			<content:encoded><![CDATA[<p>Phew!</p>
<p>... and as soon as I say this, the database powering this site corrupts on me - charming!</p>
<p>For one awful moment I thought I had lost everything (I hadn't set up a regular mysql backup task for this blog), but thankfully, bringing this blog back from the dead was surprisingly straight forward.</p>
<p>Here's what happened, and what I did to fix it.</p>
<p>Yesterday when writing a post about how there's a mobile missing tariff that should exist but doesn't, when I posted, <a href="http://wordpress.org" title="WordPress &#8250; Blog Tool and Publishing Platform">WordPress</a> would accept my post; those pretty git spinners just kept spinning on the text page.</p>
<p>I didn't think too much of it, at the time, as I was heading out to meet James to work on some top sekrit project, based around <a href="http://nodejs.org/" title="node.js">node.js</a>, <a href="http://www.mongodb.org/" title="MongoDB">mongodb</a>, and doing something strange yet hopefully useful with wifi, so I just saved it locally on my mac, and headed out on my bike.</p>
<p>This evening though, I tried again, and I had the same error. "Ah," I thought, "maybe I just need to restart the database on this box - it's been going for ages anyway". So I ssh'd into the server running the system, and called the usual <a href="http://centos.org/" title="www.centos.org - The Community ENTerprise Operating System">CentOS</a> restart command</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">  service mysql restart</pre></div></div>

<p>This took nearly two minutes to stop, then spat out this response when restarting:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">&#91;</span>chris<span style="color: #000000; font-weight: bold;">@</span>stemcaa2 ~<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #666666; font-style: italic;"># service mysql restart</span>
Shutting down MySQL........................................<span style="color: #7a0874; font-weight: bold;">&#91;</span>  OK  <span style="color: #7a0874; font-weight: bold;">&#93;</span>.......
Starting MySQL...........................................................................................................................................................................................................................................<span style="color: #000000; font-weight: bold;">/</span>sbin<span style="color: #000000; font-weight: bold;">/</span>service: line <span style="color: #000000;">66</span>: <span style="color: #000000;">27651</span> Terminated              <span style="color: #c20cb9; font-weight: bold;">env</span> <span style="color: #660033;">-i</span> <span style="color: #007800;">LANG</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$LANG</span>&quot;</span> <span style="color: #007800;">PATH</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$PATH</span>&quot;</span> <span style="color: #007800;">TERM</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$TERM</span>&quot;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">${SERVICEDIR}</span>/<span style="color: #007800;">${SERVICE}</span>&quot;</span> <span style="color: #800000;">${OPTIONS}</span></pre></div></div>

<p>Okay, slight panic now - lets check the disk, to see if there's space for the database to write, with <code>df -h</code></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">&nbsp;
<span style="color: #7a0874; font-weight: bold;">&#91;</span>chris<span style="color: #000000; font-weight: bold;">@</span>stemcaa2 ~<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #666666; font-style: italic;"># df -h</span>
Filesystem            Size  Used Avail Use<span style="color: #000000; font-weight: bold;">%</span> Mounted on
<span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>sda1             9.9G  9.4G     <span style="color: #000000;">0</span> <span style="color: #000000;">100</span><span style="color: #000000; font-weight: bold;">%</span> <span style="color: #000000; font-weight: bold;">/</span>
tmpfs                 129M     <span style="color: #000000;">0</span>  129M   <span style="color: #000000;">0</span><span style="color: #000000; font-weight: bold;">%</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>shm
<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>tmpDSK           485M   11M  449M   <span style="color: #000000;">3</span><span style="color: #000000; font-weight: bold;">%</span> <span style="color: #000000; font-weight: bold;">/</span>tmp</pre></div></div>

<p>Ah, that's not good. Disk space is like oxygen for servers, and without it, things break quickly.</p>
<p>The quickest way to make some breathing space fast is to clear the <code>yum</code> cache, like so:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">yum clean headers packages</pre></div></div>

<p>Okay, lets try restart again:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">&#91;</span>chris<span style="color: #000000; font-weight: bold;">@</span>stemcaa2 ~<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #666666; font-style: italic;"># service mysql restart</span>
Shutting down MySQL.                                       <span style="color: #7a0874; font-weight: bold;">&#91;</span>  OK  <span style="color: #7a0874; font-weight: bold;">&#93;</span>
Starting MySQL.                                            <span style="color: #7a0874; font-weight: bold;">&#91;</span>  OK  <span style="color: #7a0874; font-weight: bold;">&#93;</span></pre></div></div>

<p>Sweet! It worked! But hang on... now wordpress isn't showing any posts! This <em>really</em> isn't good.</p>
<p>So lets check the database;</p>

<div class="wp_syntax"><div class="code"><pre class="mysql" style="font-family:monospace;"><span style="color: #FF00FF;">&#91;</span>root@stemcaa2 <span style="color: #CC0099;">~</span><span style="color: #FF00FF;">&#93;</span><span style="color: #808080; font-style: italic;"># mysql</span>
Welcome <span style="color: #990099; font-weight: bold;">to</span> the MySQL monitor.  Commands <span style="color: #009900;">end</span> <span style="color: #990099; font-weight: bold;">with</span> <span style="color: #000033;">;</span> <span style="color: #CC0099; font-weight: bold;">or</span> \g.
Your MySQL <span style="color: #FF9900; font-weight: bold;">connection</span> id <span style="color: #CC0099; font-weight: bold;">is</span> <span style="color: #008080;">11</span>
Server <span style="color: #000099;">version</span>: 5.0.90<span style="color: #CC0099;">-</span>community MySQL Community Edition <span style="color: #FF00FF;">&#40;</span>GPL<span style="color: #FF00FF;">&#41;</span>
&nbsp;
<span style="color: #990099; font-weight: bold;">Type</span> <span style="color: #008000;">'help;'</span> <span style="color: #CC0099; font-weight: bold;">or</span> <span style="color: #008000;">'<span style="color: #004000; font-weight: bold;">\h</span>'</span> for <span style="color: #990099; font-weight: bold;">help</span>. <span style="color: #990099; font-weight: bold;">Type</span> <span style="color: #008000;">'<span style="color: #004000; font-weight: bold;">\c</span>'</span> <span style="color: #990099; font-weight: bold;">to</span> clear the current input statement.
&nbsp;
mysql<span style="color: #CC0099;">&gt;</span> <span style="color: #990099; font-weight: bold;">show</span> <span style="color: #990099; font-weight: bold;">databases</span><span style="color: #000033;">;</span>
<span style="color: #CC0099;">+--------------------+</span>
<span style="color: #CC0099;">|</span> <span style="color: #990099; font-weight: bold;">Database</span>           <span style="color: #CC0099;">|</span>
<span style="color: #CC0099;">+--------------------+</span>
<span style="color: #CC0099;">|</span> information_schema <span style="color: #CC0099;">|</span> 
<span style="color: #CC0099;">|</span> antia_wordpress    <span style="color: #CC0099;">|</span> 
<span style="color: #CC0099;">|</span> chris_wordpress    <span style="color: #CC0099;">|</span> 
<span style="color: #CC0099;">|</span> cphulkd            <span style="color: #CC0099;">|</span> 
<span style="color: #CC0099;">|</span> deadonim_wordpress <span style="color: #CC0099;">|</span> 
<span style="color: #CC0099;">|</span> dov_wordpress      <span style="color: #CC0099;">|</span> 
<span style="color: #CC0099;">|</span> eximstats          <span style="color: #CC0099;">|</span> 
<span style="color: #CC0099;">|</span> horde              <span style="color: #CC0099;">|</span> 
<span style="color: #CC0099;">|</span> leechprotect       <span style="color: #CC0099;">|</span> 
<span style="color: #CC0099;">|</span> modsec             <span style="color: #CC0099;">|</span> 
<span style="color: #CC0099;">|</span> mysql              <span style="color: #CC0099;">|</span> 
<span style="color: #CC0099;">|</span> roundcube          <span style="color: #CC0099;">|</span> 
<span style="color: #CC0099;">+--------------------+</span>
<span style="color: #008080;">12</span> rows <span style="color: #990099; font-weight: bold;">in</span> <span style="color: #990099; font-weight: bold;">set</span> <span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">0.16</span> sec<span style="color: #FF00FF;">&#41;</span></pre></div></div>

<p>Okay the database is there. What about the tables though?</p>

<div class="wp_syntax"><div class="code"><pre class="mysql" style="font-family:monospace;">&nbsp;
<span style="color: #990099; font-weight: bold;">Database</span> changed
mysql<span style="color: #CC0099;">&gt;</span> <span style="color: #990099; font-weight: bold;">show</span> <span style="color: #990099; font-weight: bold;">tables</span><span style="color: #000033;">;</span>
<span style="color: #CC0099;">+---------------------------+</span>
<span style="color: #CC0099;">|</span> Tables_in_chris_wordpress <span style="color: #CC0099;">|</span>
<span style="color: #CC0099;">+---------------------------+</span>
<span style="color: #CC0099;">|</span> wp_ak_twitter             <span style="color: #CC0099;">|</span> 
<span style="color: #CC0099;">|</span> wp_commentmeta            <span style="color: #CC0099;">|</span> 
<span style="color: #CC0099;">|</span> wp_comments               <span style="color: #CC0099;">|</span> 
<span style="color: #CC0099;">|</span> wp_links                  <span style="color: #CC0099;">|</span> 
<span style="color: #CC0099;">|</span> wp_options                <span style="color: #CC0099;">|</span> 
<span style="color: #CC0099;">|</span> wp_postmeta               <span style="color: #CC0099;">|</span> 
<span style="color: #CC0099;">|</span> wp_posts                  <span style="color: #CC0099;">|</span> 
<span style="color: #CC0099;">|</span> wp_term_relationships     <span style="color: #CC0099;">|</span> 
<span style="color: #CC0099;">|</span> wp_term_taxonomy          <span style="color: #CC0099;">|</span> 
<span style="color: #CC0099;">|</span> wp_terms                  <span style="color: #CC0099;">|</span> 
<span style="color: #CC0099;">|</span> wp_usermeta               <span style="color: #CC0099;">|</span> 
<span style="color: #CC0099;">|</span> wp_users                  <span style="color: #CC0099;">|</span> 
<span style="color: #CC0099;">+---------------------------+</span>
<span style="color: #008080;">12</span> rows <span style="color: #990099; font-weight: bold;">in</span> <span style="color: #990099; font-weight: bold;">set</span> <span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">0.00</span> sec<span style="color: #FF00FF;">&#41;</span></pre></div></div>

<p>Hmm.. they're there too. Maybe the tables?</p>

<div class="wp_syntax"><div class="code"><pre class="mysql" style="font-family:monospace;">&nbsp;
mysql<span style="color: #CC0099;">&gt;</span> <span style="color: #990099; font-weight: bold;">select</span> <span style="color: #CC0099;">*</span> <span style="color: #990099; font-weight: bold;">from</span> wp_posts
    <span style="color: #CC0099;">-&gt;</span> <span style="color: #000033;">;</span>
ERROR <span style="color: #008080;">145</span> <span style="color: #FF00FF;">&#40;</span>HY000<span style="color: #FF00FF;">&#41;</span>: <span style="color: #990099; font-weight: bold;">Table</span> <span style="color: #008000;">'./chris<span style="color: #008080; font-weight: bold;">_</span>wordpress/wp<span style="color: #008080; font-weight: bold;">_</span>posts'</span> <span style="color: #CC0099; font-weight: bold;">is</span> marked <span style="color: #990099; font-weight: bold;">as</span> crashed <span style="color: #CC0099; font-weight: bold;">and</span> should be repaired</pre></div></div>

<p><em>Uh-oh.</em> I think this is going to be ugly. And yet...</p>
<h3>The magic fix</h3>
<p>...a quick check here on google gleaned the fix - MySQL's got a tool for just this occasion, and you call it like  <code>mysqlcheck broken_database</code> from the command line:</p>

<div class="wp_syntax"><div class="code"><pre class="mysql" style="font-family:monospace;"><span style="color: #FF00FF;">&#91;</span>root@stemcaa2 <span style="color: #CC0099;">~</span><span style="color: #FF00FF;">&#93;</span><span style="color: #808080; font-style: italic;"># mysqlcheck chris_wordpress</span>
chris_wordpress.wp_ak_twitter                      OK
chris_wordpress.wp_commentmeta                     OK
chris_wordpress.wp_comments                        OK
chris_wordpress.wp_links                           OK
chris_wordpress.wp_options                         OK
chris_wordpress.wp_postmeta                        OK
chris_wordpress.wp_posts
warning  : <span style="color: #990099; font-weight: bold;">Table</span> <span style="color: #CC0099; font-weight: bold;">is</span> marked <span style="color: #990099; font-weight: bold;">as</span> crashed
error    : Size of datafile <span style="color: #CC0099; font-weight: bold;">is</span>: <span style="color: #008080;">745472</span>         Should be: <span style="color: #008080;">745692</span>
error    : Corrupt
chris_wordpress.wp_term_relationships              OK
chris_wordpress.wp_term_taxonomy                   OK
chris_wordpress.wp_terms                           OK
chris_wordpress.wp_usermeta                        OK
chris_wordpress.wp_users                           OK</pre></div></div>

<p>The fix was trivial from here - just pass in an <code>auto-repair</code> flag:</p>

<div class="wp_syntax"><div class="code"><pre class="mysql" style="font-family:monospace;">&nbsp;
<span style="color: #FF00FF;">&#91;</span>root@stemcaa2 <span style="color: #CC0099;">~</span><span style="color: #FF00FF;">&#93;</span><span style="color: #808080; font-style: italic;"># mysqlcheck chris_wordpress --auto-repair</span>
chris_wordpress.wp_ak_twitter                      OK
chris_wordpress.wp_commentmeta                     OK
chris_wordpress.wp_comments                        OK
chris_wordpress.wp_links                           OK
chris_wordpress.wp_options                         OK
chris_wordpress.wp_postmeta                        OK
chris_wordpress.wp_posts
warning  : <span style="color: #990099; font-weight: bold;">Table</span> <span style="color: #CC0099; font-weight: bold;">is</span> marked <span style="color: #990099; font-weight: bold;">as</span> crashed
error    : Size of datafile <span style="color: #CC0099; font-weight: bold;">is</span>: <span style="color: #008080;">745472</span>         Should be: <span style="color: #008080;">745692</span>
error    : Corrupt
chris_wordpress.wp_term_relationships              OK
chris_wordpress.wp_term_taxonomy                   OK
chris_wordpress.wp_terms                           OK
chris_wordpress.wp_usermeta                        OK
chris_wordpress.wp_users                           OK
&nbsp;
Repairing <span style="color: #990099; font-weight: bold;">tables</span>
chris_wordpress.wp_posts
info     : Found block that points outside <span style="color: #990099; font-weight: bold;">data</span> file at <span style="color: #008080;">742932</span>
<span style="color: #990099; font-weight: bold;">status</span>   : OK</pre></div></div>

<p>And then all was well again! Why can't technology always be this easy to fix?  A huge, huge heartfelt thanks goes to <a href="http://www.felipecruz.com/" title="Felipe's Blog - Technology Articles &amp; know how">Felipe Cruz</a> for adding <a href="http://www.felipecruz.com/repair-mysql-database.php" title="Ways to repair MYSQL Databases">such simple instructions on his site</a> explaining how to use that insanely handy <code>mysqlcheck</code> command.</p>
<p><!-- links --></p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://chrisadams.me.uk/wordpress/wp-content/plugins/add-to-any/share_save_171_16.gif" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://chrisadams.me.uk/2010/05/16/how-to-fix-a-wordpress-site-when-the-database-corrupts-on-you/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>After reading this, I think I&#8217;ll let someone else work on Solaris boxes in future</title>
		<link>http://chrisadams.me.uk/2010/05/09/after-reading-this-i-think-ill-let-someone-else-work-on-solaris-boxes-in-future/</link>
		<comments>http://chrisadams.me.uk/2010/05/09/after-reading-this-i-think-ill-let-someone-else-work-on-solaris-boxes-in-future/#comments</comments>
		<pubDate>Sun, 09 May 2010 13:57:19 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[chef]]></category>
		<category><![CDATA[mistakes]]></category>
		<category><![CDATA[solaris]]></category>
		<category><![CDATA[sysadmin]]></category>

		<guid isPermaLink="false">http://chrisadams.me.uk/?p=257</guid>
		<description><![CDATA[I was doing some research on StackOverflow today to find out more about using Chef-Solo to manage smaller numbers of virtual machines (i.e. less than 5 for example), and I came across this snippet on a confessional thread about the worst mistakes you've made as a sysadmin: I had fun discovering the difference between the [...]]]></description>
			<content:encoded><![CDATA[<p>I was doing some research on StackOverflow today to find out more about using <a href="http://serverfault.com/questions/126298/idiomatic-way-to-invoke-chef-solo" title="Idiomatic way to invoke chef-solo? - Server Fault">Chef-Solo to manage smaller numbers of virtual machines</a> (i.e. less than 5 for example), and I came across this snippet on a <a href="http://serverfault.com/questions/20738/what-do-you-do-to-prevent-stupid-mistakes" title="What do you do to prevent stupid mistakes? - Server Fault">confessional thread about the worst mistakes you've made as a sysadmin</a>:</p>
<blockquote>
<p>I had fun discovering the difference between the linux "killall" command (kills all processes matching the specified name, useful for stopping zombies) and the solaris "killall" command (kills all processes and halts the system, useful for stopping the production server in the middle of peak hours and getting all your co-workers to laugh at you for a week)</p>
</blockquote>
<p>Remind me to avoid looking after any Solaris boxes at all costs from now on - if a fairly innocuous Linux command kills an entire system, I shudder to think what other pitfalls and pratfalls lie in wait for a poor sysadmin....</p>
<p><!-- links --></p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://chrisadams.me.uk/wordpress/wp-content/plugins/add-to-any/share_save_171_16.gif" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://chrisadams.me.uk/2010/05/09/after-reading-this-i-think-ill-let-someone-else-work-on-solaris-boxes-in-future/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Setting up wordpress to update itself</title>
		<link>http://chrisadams.me.uk/2009/07/25/setting-up-wordpress-to-update-itself/</link>
		<comments>http://chrisadams.me.uk/2009/07/25/setting-up-wordpress-to-update-itself/#comments</comments>
		<pubDate>Sat, 25 Jul 2009 21:06:31 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[linux ubuntu redhat apache wordpress]]></category>
		<category><![CDATA[sysadmin]]></category>

		<guid isPermaLink="false">http://chrisadams.me.uk/?p=177</guid>
		<description><![CDATA[WordPress&#8217;s auto update feature is incredibly handy. However, not every webhost automatically has accounts setup to allow for this, and if click the promising looking auto-upgrade icon, you&#8217;ll often be face with this screen here: You get this screen when the folder containing wordpress belongs to the user, instead of the apache daemon; this is [...]]]></description>
			<content:encoded><![CDATA[<p>WordPress&#8217;s auto update feature is incredibly handy.</p>
<p>However, not every webhost automatically has accounts setup to allow for this, and if click the promising looking auto-upgrade icon, you&#8217;ll often be face with this screen here:</p>
<p><a href="http://chrisadams.me.uk/wordpress/wp-content/uploads/2009/07/Wordpress-auto-upload-fail-.jpg"><img class="alignnone size-medium wp-image-179" title="Wordpress - auto-upload fail" src="http://chrisadams.me.uk/wordpress/wp-content/uploads/2009/07/Wordpress-auto-upload-fail--300x202.jpg" alt="Wordpress - auto-upload fail" width="300" height="202" /></a></p>
<p>You get this screen when the folder containing wordpress belongs to the user, instead of the apache daemon; this is normally either <code>www-data</code> if you&#8217;re using Ubuntu, or <code>nobody</code> if you&#8217;re using Redhat Linux instead.</p>
<p>The simplest way to do this is to change the folders to be owned by the apache daemon instead, by using <code>chmod</code> like so:</p>
<pre><code>
chown -R nobody wordpress
</code></pre>
<p>Adding the <code>-R</code> flag makes the changing of ownership recursive through all the folders inside wordpress.</p>
<p>Job done.</p>
<p>This is outlined in more detail by <a title="Rob Spender on WordPress permissions" href="http://robspencer.net/auto-update-wordpress-without-ftp/">Rob Spencer</a> on his own blog &#8211; really quite handy.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://chrisadams.me.uk/wordpress/wp-content/plugins/add-to-any/share_save_171_16.gif" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://chrisadams.me.uk/2009/07/25/setting-up-wordpress-to-update-itself/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>A brief primer on using ssh</title>
		<link>http://chrisadams.me.uk/2008/12/24/a-brief-primer-on-using-ssh/</link>
		<comments>http://chrisadams.me.uk/2008/12/24/a-brief-primer-on-using-ssh/#comments</comments>
		<pubDate>Wed, 24 Dec 2008 15:15:57 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[Journal]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[ssh]]></category>
		<category><![CDATA[sysadmin]]></category>

		<guid isPermaLink="false">http://chrisadams.me.uk/?p=27</guid>
		<description><![CDATA[I keep forgetting how to do this, so I'm writing this here for future reference. This year, as I use web app frameworks like Django or Rails more and more, I've increasingly been using the command line instead of tools like Transmit for making changes to sites and web apps. This works fine locally, but [...]]]></description>
			<content:encoded><![CDATA[<p><em>I keep forgetting how to do this, so I'm writing this here for future reference.</em></p>
<p>This year, as I use web app frameworks like Django or Rails more and more, I've increasingly been using the command line instead of tools like Transmit for making changes to sites and web apps. This works fine locally, but when you  start using remote servers, typing passwords all day gets old quickly.</p>
<p>This is where logging into servers using ssh keys comes in. This a very high level abstraction, and isn't that accurate technically, I found it easiest to think of this process as three separate steps:</p>
<p>1) Generate a lock and key<br />
2) Put the lock on the server.<br />
3) Use the key to get into the server.</p>
<h3>Generate the lock and key - generate your key pair</h3>
<p>Essentially what you do is generate a private/public key pair, and put the public part of the key onto the remote server. The server can then check your the public key you gave it against the private key on your laptop, and if they 'fit', it's pretty sure you are who you say you are.</p>
<p>First , you generate the key pair, using the program ssh-keygen, and telling it to use the encryption type 'rsa':</p>
<pre class="literal-block">ssh-keygen -t rsa</pre>
<p>The two common options here are to use -rsa type encryption, or -dsa encryption. <cite><a title="DSA authentication" href="http://en.wikipedia.org/wiki/Digital_Signature_Algorithm">DSA</a></cite> stands for Digital Signature Algorithm, whereas <cite><a title="RSA  authentication" href="http://en.wikipedia.org/wiki/RSA">RSA</a></cite> is named after the three inventors of the algorithm; Ron Rivest, Adi Shamir and Leonard Adleman.</p>
<p>I haven't found any real difference that affects my experience of ssh as a developer, but the gist I get from skimming the newsgroups is that DSA is a slightly faster encryption algorithm than RSA, but also slightly less difficult to (eventually) crack.</p>
<p>My understanding earlier was that DSA was the more 'free' encryption method, as RSA was under patent initially, but a quick check on wikipedia tells us that RSA released to the public domain in the year 2000, so for most of us non-crypto profs, there's almost nothing in choosing between the two now.</p>
<p>Running this command will create a public/private key pair, usually put in an invisible directory called <cite>.ssh</cite>, and they should look like this if you peep inside the <cite>~/.ssh</cite> directory:</p>
<dl class="docutils">
<dt><cite>id_rsa</cite></dt>
<dd>Your private key, which you keep on your computer. This shouldn't be shared with anyone, and though it's not totally accurate, I like to think of ssh key pairs in similar terms to locks and keys. In this case we can think of this as the front door key.</dd>
<dt><cite>id_rsa.pub</cite></dt>
<dd>your public key which you put on the remote server, specifically in a file called authorized_keys. You can think of this as the 'lock' that you would put the id_rsa private key into.</dd>
</dl>
<h3>Put your the lock (the public key) on the remote server</h3>
<p>You next need to put the public key into the hidden <cite>~/.ssh</cite> directory, appending the public key to a file called <cite>authorized_keys</cite> on the remote server. When you next try to ssh into your server, you'll end up combining your private key on your computer, with the public key on the server, to give a fairly strong claim to you being who you say you are.</p>
<p>Once you've copied it onto your server, which you can do using an <cite>sftp</cite> client, or simply using <cite>scp</cite>,You need to make the server aware of the public key by writing it to a text file called authorized_keys. A simple way to do this is to use a command called <cite>cat</cite> (think con<strong>cat</strong>enate):</p>
<p>cat .id_rsa.pub &gt;&gt; ./ssh/authorized_keys</p>
<p>This takes the contents of your public key, and writes it to the end of the authorized keys file.</p>
<p>To continue the clumsy lock and key analogy, this is like fitting the front door with the new lock that responds only to your private key.</p>
<p>Exit the <cite>ssh</cite> session, and then try logging in once more..</p>
<h3>Log in</h3>
<p>Et voila! You should now have passwordless log-in to a server setup from your computer to a remote server now. You can use a variant of this setup to create secure automated backups from one server to another, and to set up other dull tasks that are best automated.</p>
<p>It doesn't stop here though - you can ramp up security here by limiting what tasks a script, or person logging in using ssh can do on a server, and you can add extra layers of security to make key pairs AND passwords needed for certain accounts, or certain actions, or set up elaborate daisy chain sequences where an action on one computer sets of a series of other automated tasks on other computers around the web that you'd previously have to do by yourself. But that's for a future post.</p>
<p><em>Common gotchas here</em></p>
<p>I've lost a depressing amount of time trying to setup ssh keys for passwordless login, before realising that I needed to fiddle with file permissions on the relevant files.<br />
If you're still being challenged for a password when you're signing, check that you have the permissions setup properly on your server. You need to be the only person able to alter the <cite>authorized_keys file</cite>, on the remote server, and you can do this with the tool <cite>chmod</cite>, like so:</p>
<pre class="literal-block">chmod 600 ~/.ssh/authorized_keys</pre>
<p>This gives you read and write access to the <cite>authorized_keys</cite> file (the 6), but removes anyone else's access to it (the second and third 0's). Which makes sense really - for security you want to be the only person who can decide who is allowed to add authorised user's public keys.</p>
<p>You also need to check that your hidden <cite>~/.ssh</cite> has similar permissions: you want to be the only person who can edit the directory, so make sure this is reflected in the permissions. You need to set chmod to 700:</p>
<pre class="literal-block">chmod 700 ~/.ssh/</pre>
<p>Once again, this grants access only to you, and no one else.</p>
<h3>Isn't logging into a server without a password a horrifically bad idea security wise? What if someone steals your laptop?</h3>
<p>If you lose the keys to your house, it's a good idea to change the locks, so people with those keys can't get in. Likewise, if you lose your computer, the equivalent action to changing your locks would be removing that laptop's public key from your server's list of authorised keys.</p>
<p>I've borrowed heavily from <a title="James Gardner - ssh primer" href="http://jimmyg.org/2008/07/26/beginners-guide-to-ssh-keys-with-ssh2/">James Gardner's own writing about ssh</a>, so if you're interested in learning more, he's written quite lucidly and at length about them on his own blog.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://chrisadams.me.uk/wordpress/wp-content/plugins/add-to-any/share_save_171_16.gif" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://chrisadams.me.uk/2008/12/24/a-brief-primer-on-using-ssh/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
