<?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>Untitled &#187; sysadmin</title>
	<atom:link href="http://ammonlauritzen.com/blog/category/sysadmin/feed/" rel="self" type="application/rss+xml" />
	<link>http://ammonlauritzen.com/blog</link>
	<description>and still for good reason.</description>
	<lastBuildDate>Tue, 13 Dec 2011 21:29:14 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.2</generator>
		<item>
		<title>console2</title>
		<link>http://ammonlauritzen.com/blog/2011/05/31/console2/</link>
		<comments>http://ammonlauritzen.com/blog/2011/05/31/console2/#comments</comments>
		<pubDate>Tue, 31 May 2011 22:24:07 +0000</pubDate>
		<dc:creator>Ammon</dc:creator>
				<category><![CDATA[personal]]></category>
		<category><![CDATA[sysadmin]]></category>
		<category><![CDATA[geek]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[ssh]]></category>
		<category><![CDATA[work]]></category>

		<guid isPermaLink="false">http://ammonlauritzen.com/blog/?p=1330</guid>
		<description><![CDATA[For -years- I have hoped and searched and wished and moaned for lack of a halfway decent terminal emulator on Windows. Specifically, one that: Lets me use my standard unix toolset. Gives me a command line interface to the host machine WITHOUT requiring me to do something ridiculous like ssh&#8217;ing to localhost or firing up [...]]]></description>
			<content:encoded><![CDATA[<p>For -years- I have hoped and searched and wished and moaned for lack of a halfway decent terminal emulator on Windows. Specifically, one that:</p>
<ol>
<li>Lets me use my standard unix toolset.</li>
<li>Gives me a command line interface to the host machine WITHOUT requiring me to do something ridiculous like ssh&#8217;ing to localhost or firing up an x11 server&#8230;</li>
<li>Realizes that sometimes the display is wider than 80 characters&#8230;</li>
<li>Provides customizable color codes (#006 on black really stinks).</li>
<li>Doesn&#8217;t set TERM=something-nobody-supports.</li>
</ol>
<p>One wouldn&#8217;t think this was too much to ask. But none of the major open source projects of which I am aware provide this. I even tried my hand at writing one myself but got distracted before it was any good.</p>
<p>So, for years, I have used Cygwin xterms and rxvt as a mildly tolerable alternative to, well, nothing.</p>
<p>Today, a coworker and I discovered a 3-year-old blog post promoting <a href='http://console.sf.net'>Console</a>, a GPL licensed CMD.exe replacement that matches all of my base criteria plus my big dream feature of tabs. TABS!</p>
<p>Console2, Where have you been all my life?!</p>
<p>The project is ancient &#8211; but I was using linux desktops for work back in its early days so that probably accounts for my missing it back then.</p>
<p>In the grand tradition of old Sourceforge projects, there is no installer. You just decompress it somewhere and run the exe directly.</p>
<p>When I launched it the first time, I was unsurprised by the 80&#215;25 courier 10 cmd.exe shell it launched by default. I opened the settings menu and was very very pleased with what I found on the first screen. A few minutes later, I had it pointing at my cygwin install:</p>
<div style='text-align:center'><img src="http://ammonlauritzen.com/blog/wp-content/uploads/2011/05/console2-settings.png" alt="" title="console2-settings" width="327" height="62" class="alignnone size-full wp-image-1332" /></div>
<p><br/><br />
And a few minutes later:</p>
<div style='text-align:center'><img src="http://ammonlauritzen.com/blog/wp-content/uploads/2011/05/console2-is-love.png" alt="" title="console2-is-love" width="597" height="764" class="alignnone size-full wp-image-1331" /></div>
<p><span id="more-1330"></span><br />
I am a very happy camper now. It is apparently still an actively developed project &#8211; the last SF commit was two days ago.</p>
<p>The only feature requests I can think of is dynamic tab renaming to follow my host/path as I ssh around places, and profiles that recognize when I am connected to a given host and therefore tint the background to warn that I am on a production server, etc&#8230;</p>
<p>To be fair, this is a pretty minor gripe as the application actually has similar functionality already &#8211; you can configure individual tab templates, and can set ssh as your shell:</p>
<div style='text-align:center'><img src="http://ammonlauritzen.com/blog/wp-content/uploads/2011/05/console2-tiff-tab-settings.png" alt="" title="console2-tiff-tab-settings" width="537" height="550" class="alignnone size-full wp-image-1335" /></div>
<p><br/><br />
And if you select the little dropdown next to the new tab button you can choose to launch the different kind of tab:</p>
<div style='text-align:center'><img src="http://ammonlauritzen.com/blog/wp-content/uploads/2011/05/console2-tiff.png" alt="" title="console2-tiff" width="597" height="534" class="alignnone size-full wp-image-1334" /></div>
<p><br/><br />
So&#8230; I&#8217;m content. This is the coolest toy I&#8217;ve discovered in a very long time.</p>
]]></content:encoded>
			<wfw:commentRss>http://ammonlauritzen.com/blog/2011/05/31/console2/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>virtualbox rules</title>
		<link>http://ammonlauritzen.com/blog/2010/03/10/virtualbox-rules/</link>
		<comments>http://ammonlauritzen.com/blog/2010/03/10/virtualbox-rules/#comments</comments>
		<pubDate>Wed, 10 Mar 2010 21:42:23 +0000</pubDate>
		<dc:creator>Ammon</dc:creator>
				<category><![CDATA[personal]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[sysadmin]]></category>
		<category><![CDATA[geek]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[linux]]></category>

		<guid isPermaLink="false">http://ammonlauritzen.com/blog/?p=1111</guid>
		<description><![CDATA[Nothing much to say here, but with absolutely minimal pain and suffering, I have 64-bit linux virtual machines running on top of my 32-bit windows XP install. This pleases me. The recipe: Compatible CPU with VT-x/AMD-V enabled in the BIOS Innotek/Oracle/Sun VirtualBox (a current version) with hardware virtualization enabled Profit! The one downside to this? [...]]]></description>
			<content:encoded><![CDATA[<p>Nothing much to say here, but with absolutely minimal pain and suffering, I have 64-bit linux virtual machines running on top of my 32-bit windows XP install. This pleases me.</p>
<p>The recipe:</p>
<ol>
<li>Compatible CPU with VT-x/AMD-V enabled in the BIOS</li>
<li>Innotek/Oracle/Sun VirtualBox (a current version) with hardware virtualization enabled</li>
<li>Profit!</li>
</ol>
<p>The one downside to this? 64-bit VM&#8217;s running on 32-bit host OS can&#8217;t see multiple cpu&#8217;s. Boo. Hoo. I&#8217;ll just run more VM&#8217;s!</p>
<p><a href="http://ammonlauritzen.com/blog/wp-content/uploads/2010/03/centos-installer-64-virtualbox.png"><img src="http://ammonlauritzen.com/blog/wp-content/uploads/2010/03/centos-installer-64-virtualbox-300x250.png" alt="64-bit centos installer" title="centos-installer-64-virtualbox" width="300" height="250" class="alignnone size-medium wp-image-1112" /></a> <a href="http://ammonlauritzen.com/blog/wp-content/uploads/2010/03/ubuntu-64-virtualbox.png"><img src="http://ammonlauritzen.com/blog/wp-content/uploads/2010/03/ubuntu-64-virtualbox-300x250.png" alt="64-bit ubuntu livecd" title="ubuntu-64-virtualbox" width="300" height="250" class="alignnone size-medium wp-image-1113" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://ammonlauritzen.com/blog/2010/03/10/virtualbox-rules/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>dead simple traditional style rotation</title>
		<link>http://ammonlauritzen.com/blog/2010/02/05/dead-simple-traditional-style-rotation/</link>
		<comments>http://ammonlauritzen.com/blog/2010/02/05/dead-simple-traditional-style-rotation/#comments</comments>
		<pubDate>Fri, 05 Feb 2010 17:51:26 +0000</pubDate>
		<dc:creator>Ammon</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[sysadmin]]></category>
		<category><![CDATA[logfiles]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://ammonlauritzen.com/blog/?p=1105</guid>
		<description><![CDATA[In response to my two-step rotation post earlier this week, I figure I may as well share the logic I use for a more traditional logfile rotation scheme. I think this is as simple as I can possibly make it: &#38;lt;? define&#40; 'MAX_COPIES', 3 &#41;; $back_fname = &#38;quot;/path/to/log/file/abc.log&#38;quot;; function trace&#40; $msg &#41; &#123; &#160; &#160; [...]]]></description>
			<content:encoded><![CDATA[<p>In response to <a href='http://ammonlauritzen.com/blog/2010/02/03/simple-two-step-logfile-rotation/'>my two-step rotation post</a> earlier this week, I figure I may as well share the logic I use for a more traditional logfile rotation scheme.</p>
<p>I think this is as simple as I can possibly make it:</p>
<div class="syntax_hilite">
<div id="php-3">
<div class="php">&amp;lt;?<br />
<a href="http://www.php.net/define"><span style="color:#000066;">define</span></a><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#FF0000;">'MAX_COPIES'</span>, <span style="color:#CC66CC;">3</span> <span style="color:#006600; font-weight:bold;">&#41;</span>;<br />
<span style="color:#0000FF;">$back_fname</span> = &amp;quot;/path/to/<a href="http://www.php.net/log"><span style="color:#000066;">log</span></a>/<a href="http://www.php.net/file"><span style="color:#000066;">file</span></a>/abc.log&amp;quot;;</p>
<p><span style="color:#000000; font-weight:bold;">function</span> trace<span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#0000FF;">$msg</span> <span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; <a href="http://www.php.net/echo"><span style="color:#000066;">echo</span></a> &amp;quot;- <span style="color:#0000FF;">$msg</span>\n&amp;quot;;<br />
<span style="color:#006600; font-weight:bold;">&#125;</span></p>
<p><a href="http://www.php.net/exec"><span style="color:#000066;">exec</span></a><span style="color:#006600; font-weight:bold;">&#40;</span> &amp;quot;ls -r $<span style="color:#006600; font-weight:bold;">&#123;</span>back_fname<span style="color:#006600; font-weight:bold;">&#125;</span>*&amp;quot;, <span style="color:#0000FF;">$copies</span>, <span style="color:#0000FF;">$succ</span> <span style="color:#006600; font-weight:bold;">&#41;</span>;<br />
<span style="color:#616100;">while</span><span style="color:#006600; font-weight:bold;">&#40;</span> <a href="http://www.php.net/count"><span style="color:#000066;">count</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$copies</span><span style="color:#006600; font-weight:bold;">&#41;</span>&amp;gt;= MAX_COPIES <span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; <span style="color:#0000FF;">$fname</span> = <a href="http://www.php.net/array_shift"><span style="color:#000066;">array_shift</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$copies</span><span style="color:#006600; font-weight:bold;">&#41;</span>;<br />
&nbsp; &nbsp; trace<span style="color:#006600; font-weight:bold;">&#40;</span> &amp;quot;deleting &amp;quot;.<span style="color:#0000FF;">$fname</span> <span style="color:#006600; font-weight:bold;">&#41;</span>;<br />
<span style="color:#006600; font-weight:bold;">&#125;</span><br />
<span style="color:#0000FF;">$next</span> = <a href="http://www.php.net/count"><span style="color:#000066;">count</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$copies</span><span style="color:#006600; font-weight:bold;">&#41;</span>;<br />
<span style="color:#616100;">while</span><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#0000FF;">$fname</span> = <a href="http://www.php.net/array_shift"><span style="color:#000066;">array_shift</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$copies</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; --<span style="color:#0000FF;">$next</span>;<br />
&nbsp; &nbsp; trace<span style="color:#006600; font-weight:bold;">&#40;</span> &amp;quot;rotating <span style="color:#0000FF;">$fname</span> -&amp;gt; <span style="color:#0000FF;">$next</span>&amp;quot; <span style="color:#006600; font-weight:bold;">&#41;</span>;<br />
&nbsp; &nbsp; <a href="http://www.php.net/rename"><span style="color:#000066;">rename</span></a><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#0000FF;">$fname</span>, &amp;quot;<span style="color:#0000FF;">$back_fname</span>.<span style="color:#0000FF;">$next</span>&amp;quot; <span style="color:#006600; font-weight:bold;">&#41;</span>;<br />
<span style="color:#006600; font-weight:bold;">&#125;</span></p>
<p>trace<span style="color:#006600; font-weight:bold;">&#40;</span> &amp;quot;creating <span style="color:#0000FF;">$back_fname</span>&amp;quot; <span style="color:#006600; font-weight:bold;">&#41;</span>;<br />
<a href="http://www.php.net/touch"><span style="color:#000066;">touch</span></a><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#0000FF;">$back_fname</span> <span style="color:#006600; font-weight:bold;">&#41;</span>;<br />
?&amp;gt;</div>
</div>
</div>
<p></p>
<p>A sample series of executions might look like this:</p>
<div class="syntax_hilite">
<div id="code-4">
<div class="code">ammon@wernstrom:/path/to/log/file$ touch abc.<span style="">log</span><br />
ammon@wernstrom:/path/to/log/file$ php rotate.<span style="">php</span> <br />
- rotating /path/to/log/file/abc.<span style="">log</span> -&amp;gt; <span style="color:#800000;">0</span><br />
- creating /path/to/log/file/abc.<span style="">log</span><br />
ammon@wernstrom:/path/to/log/file$ php rotate.<span style="">php</span> <br />
- rotating /path/to/log/file/abc.<span style="">log</span>.<span style="color:#800000;">0</span> -&amp;gt; <span style="color:#800000;">1</span><br />
- rotating /path/to/log/file/abc.<span style="">log</span> -&amp;gt; <span style="color:#800000;">0</span><br />
- creating /path/to/log/file/abc.<span style="">log</span><br />
ammon@wernstrom:/path/to/log/file$ php rotate.<span style="">php</span> <br />
- rotating /path/to/log/file/abc.<span style="">log</span>.<span style="color:#800000;">1</span> -&amp;gt; <span style="color:#800000;">2</span><br />
- rotating /path/to/log/file/abc.<span style="">log</span>.<span style="color:#800000;">0</span> -&amp;gt; <span style="color:#800000;">1</span><br />
- rotating /path/to/log/file/abc.<span style="">log</span> -&amp;gt; <span style="color:#800000;">0</span><br />
- creating /path/to/log/file/abc.<span style="">log</span><br />
ammon@wernstrom:/path/to/log/file$ php rotate.<span style="">php</span> <br />
- deleting /path/to/log/file/abc.<span style="">log</span>.<span style="color:#800000;">2</span><br />
- rotating /path/to/log/file/abc.<span style="">log</span>.<span style="color:#800000;">1</span> -&amp;gt; <span style="color:#800000;">2</span><br />
- rotating /path/to/log/file/abc.<span style="">log</span>.<span style="color:#800000;">0</span> -&amp;gt; <span style="color:#800000;">1</span><br />
- rotating /path/to/log/file/abc.<span style="">log</span> -&amp;gt; <span style="color:#800000;">0</span><br />
- creating /path/to/log/file/abc.<span style="">log</span></div>
</div>
</div>
<p></p>
<p>This doesn't have any failsafes, doesn't compress anything, depends on an external call to 'ls', and it actually deletes old files in stead of overwriting them... but it is the shortest, simplest method I've come up with to get the job done.</p>
<p>If I feel like making this a full-fledged series, I might actually post a more thorough implementation later <img src='http://ammonlauritzen.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://ammonlauritzen.com/blog/2010/02/05/dead-simple-traditional-style-rotation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>simple two-step logfile rotation</title>
		<link>http://ammonlauritzen.com/blog/2010/02/03/simple-two-step-logfile-rotation/</link>
		<comments>http://ammonlauritzen.com/blog/2010/02/03/simple-two-step-logfile-rotation/#comments</comments>
		<pubDate>Wed, 03 Feb 2010 19:23:08 +0000</pubDate>
		<dc:creator>Ammon</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[sysadmin]]></category>
		<category><![CDATA[logfiles]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://ammonlauritzen.com/blog/?p=1103</guid>
		<description><![CDATA[This is the result of 10 minutes of pounding on the keyboard after yet another disappointing experience with trying to get logrotate to do something vaguely more flexible. This simple script scans all normal files in a log directory, and if they are older than a certain cutoff, moves them into a holding directory for [...]]]></description>
			<content:encoded><![CDATA[<p>This is the result of 10 minutes of pounding on the keyboard after yet another disappointing experience with trying to get logrotate to do something vaguely more flexible.</p>
<p>This simple script scans all normal files in a log directory, and if they are older than a certain cutoff, moves them into a holding directory for old logs. Future passes will check files in the old directory for another age setting and will delete them. That's all there is to it.</p>
<p>Configure your cutoffs, directories of interest, and optionally plug in a better logging mechanism and you're set. (Oh, and change the #! if necessary, of course).</p>
<div class="syntax_hilite">
<div id="php-6">
<div class="php"><span style="color:#008000; font-style:italic;">#!/usr/bin/php</span><br />
&amp;lt;?<br />
<span style="color:#0000FF;">$cutoff_rotate</span> = &amp;quot;<span style="color:#CC66CC;">3</span> days&amp;quot;;<br />
<span style="color:#0000FF;">$cutoff_delete</span> = &amp;quot;<span style="color:#CC66CC;">7</span> days&amp;quot;;<br />
<span style="color:#0000FF;">$dir_log</span> = &amp;quot;/logs&amp;quot;;<br />
<span style="color:#0000FF;">$dir_old</span> = &amp;quot;/logs.old&amp;quot;;</p>
<p><span style="color:#000000; font-weight:bold;">function</span> trace<span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#0000FF;">$msg</span>, <span style="color:#0000FF;">$debug</span> = <span style="color:#000000; font-weight:bold;">FALSE</span> <span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; <span style="color:#FF9933; font-style:italic;">// appropriate logging mechanism can be plugged in here</span><br />
&nbsp; &nbsp; <a href="http://www.php.net/echo"><span style="color:#000066;">echo</span></a> &amp;quot;<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#0000FF;">$msg</span>\n&amp;quot;;<br />
<span style="color:#006600; font-weight:bold;">&#125;</span></p>
<p><span style="color:#FF9933; font-style:italic;">// scan old files for deletion</span><br />
<span style="color:#616100;">if</span><span style="color:#006600; font-weight:bold;">&#40;</span> <a href="http://www.php.net/is_dir"><span style="color:#000066;">is_dir</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$dir_old</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; <span style="color:#0000FF;">$dh</span> = <a href="http://www.php.net/opendir"><span style="color:#000066;">opendir</span></a><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#0000FF;">$dir_old</span> <span style="color:#006600; font-weight:bold;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color:#616100;">if</span><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#0000FF;">$dh</span> !== <span style="color:#000000; font-weight:bold;">FALSE</span> <span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/chdir"><span style="color:#000066;">chdir</span></a><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#0000FF;">$dir_old</span> <span style="color:#006600; font-weight:bold;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; trace<span style="color:#006600; font-weight:bold;">&#40;</span> &amp;quot;scanning <span style="color:#0000FF;">$dir_old</span> <span style="color:#616100;">for</span> logs more than <span style="color:#0000FF;">$cutoff_delete</span> old&amp;quot; <span style="color:#006600; font-weight:bold;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$cutoff</span> = <a href="http://www.php.net/strtotime"><span style="color:#000066;">strtotime</span></a><span style="color:#006600; font-weight:bold;">&#40;</span> &amp;quot;-<span style="color:#0000FF;">$cutoff_delete</span>&amp;quot; <span style="color:#006600; font-weight:bold;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; trace<span style="color:#006600; font-weight:bold;">&#40;</span> &amp;quot;cutoff is &amp;quot;.<a href="http://www.php.net/date"><span style="color:#000066;">date</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'r'</span>,<span style="color:#0000FF;">$cutoff</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#616100;">while</span><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$file</span> = <a href="http://www.php.net/readdir"><span style="color:#000066;">readdir</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$dh</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span> !== <span style="color:#000000; font-weight:bold;">FALSE</span> <span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#616100;">if</span><span style="color:#006600; font-weight:bold;">&#40;</span> <a href="http://www.php.net/is_dir"><span style="color:#000066;">is_dir</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$file</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; trace<span style="color:#006600; font-weight:bold;">&#40;</span> &amp;quot;skipping <span style="color:#0000FF;">$file</span>&amp;quot;, <span style="color:#000000; font-weight:bold;">true</span> <span style="color:#006600; font-weight:bold;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#616100;">continue</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span> <span style="color:#616100;">else</span> <span style="color:#006600; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$ts</span> = <a href="http://www.php.net/filemtime"><span style="color:#000066;">filemtime</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$file</span><span style="color:#006600; font-weight:bold;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#616100;">if</span><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#0000FF;">$ts</span> &amp;lt;<span style="color:#0000FF;">$cutoff</span> <span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; trace<span style="color:#006600; font-weight:bold;">&#40;</span> &amp;quot;deleting <span style="color:#0000FF;">$file</span>, &amp;quot;.<a href="http://www.php.net/date"><span style="color:#000066;">date</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'r'</span>,<span style="color:#0000FF;">$ts</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$succ</span> = @<a href="http://www.php.net/unlink"><span style="color:#000066;">unlink</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$file</span><span style="color:#006600; font-weight:bold;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#616100;">if</span><span style="color:#006600; font-weight:bold;">&#40;</span> !<span style="color:#0000FF;">$succ</span> <span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; trace<span style="color:#006600; font-weight:bold;">&#40;</span> &amp;quot;failed to <a href="http://www.php.net/unlink"><span style="color:#000066;">unlink</span></a> <span style="color:#0000FF;">$file</span>!&amp;quot; <span style="color:#006600; font-weight:bold;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span> <span style="color:#616100;">else</span> <span style="color:#006600; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; trace<span style="color:#006600; font-weight:bold;">&#40;</span> &amp;quot;ignoring <span style="color:#0000FF;">$file</span>, &amp;quot;.<a href="http://www.php.net/date"><span style="color:#000066;">date</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'r'</span>,<span style="color:#0000FF;">$ts</span><span style="color:#006600; font-weight:bold;">&#41;</span>, <span style="color:#000000; font-weight:bold;">true</span> <span style="color:#006600; font-weight:bold;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span><br />
&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span><br />
&nbsp; &nbsp; <a href="http://www.php.net/closedir"><span style="color:#000066;">closedir</span></a><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#0000FF;">$dh</span> <span style="color:#006600; font-weight:bold;">&#41;</span>;<br />
<span style="color:#006600; font-weight:bold;">&#125;</span> <span style="color:#616100;">else</span> <span style="color:#006600; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; trace<span style="color:#006600; font-weight:bold;">&#40;</span> &amp;quot;no old <a href="http://www.php.net/log"><span style="color:#000066;">log</span></a> <a href="http://www.php.net/dir"><span style="color:#000066;">dir</span></a> <span style="color:#0000FF;">$dir_old</span> to scan yet&amp;quot; <span style="color:#006600; font-weight:bold;">&#41;</span>;<br />
<span style="color:#006600; font-weight:bold;">&#125;</span></p>
<p><span style="color:#FF9933; font-style:italic;">// scan current files for rotation</span><br />
<span style="color:#616100;">if</span><span style="color:#006600; font-weight:bold;">&#40;</span> <a href="http://www.php.net/file_exists"><span style="color:#000066;">file_exists</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$dir_old</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; trace<span style="color:#006600; font-weight:bold;">&#40;</span> &amp;quot;creating <span style="color:#0000FF;">$dir_old</span>&amp;quot; <span style="color:#006600; font-weight:bold;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color:#0000FF;">$succ</span> = @<a href="http://www.php.net/mkdir"><span style="color:#000066;">mkdir</span></a><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#0000FF;">$dir_old</span>, <span style="color:#CC66CC;">0775</span>, <span style="color:#000000; font-weight:bold;">true</span> <span style="color:#006600; font-weight:bold;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color:#616100;">if</span><span style="color:#006600; font-weight:bold;">&#40;</span> !<span style="color:#0000FF;">$succ</span> <span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; trace<span style="color:#006600; font-weight:bold;">&#40;</span> &amp;quot;mkdir failed, aborting rotation&amp;quot; <span style="color:#006600; font-weight:bold;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/exit"><span style="color:#000066;">exit</span></a><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#CC66CC;">1</span> <span style="color:#006600; font-weight:bold;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span><br />
<span style="color:#006600; font-weight:bold;">&#125;</span><br />
<span style="color:#616100;">if</span><span style="color:#006600; font-weight:bold;">&#40;</span> <a href="http://www.php.net/is_dir"><span style="color:#000066;">is_dir</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$dir_log</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; <span style="color:#0000FF;">$dh</span> = <a href="http://www.php.net/opendir"><span style="color:#000066;">opendir</span></a><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#0000FF;">$dir_log</span> <span style="color:#006600; font-weight:bold;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color:#616100;">if</span><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#0000FF;">$dh</span> !== <span style="color:#000000; font-weight:bold;">FALSE</span> <span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/chdir"><span style="color:#000066;">chdir</span></a><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#0000FF;">$dir_log</span> <span style="color:#006600; font-weight:bold;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; trace<span style="color:#006600; font-weight:bold;">&#40;</span> &amp;quot;scanning <span style="color:#0000FF;">$dir_log</span> <span style="color:#616100;">for</span> logs more than <span style="color:#0000FF;">$cutoff_rotate</span> old&amp;quot; <span style="color:#006600; font-weight:bold;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$cutoff</span> = <a href="http://www.php.net/strtotime"><span style="color:#000066;">strtotime</span></a><span style="color:#006600; font-weight:bold;">&#40;</span> &amp;quot;-<span style="color:#0000FF;">$cutoff_delete</span>&amp;quot; <span style="color:#006600; font-weight:bold;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; trace<span style="color:#006600; font-weight:bold;">&#40;</span> &amp;quot;cutoff is &amp;quot;.<a href="http://www.php.net/date"><span style="color:#000066;">date</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'r'</span>,<span style="color:#0000FF;">$cutoff</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#616100;">while</span><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$file</span> = <a href="http://www.php.net/readdir"><span style="color:#000066;">readdir</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$dh</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span> !== <span style="color:#000000; font-weight:bold;">FALSE</span> <span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#616100;">if</span><span style="color:#006600; font-weight:bold;">&#40;</span> <a href="http://www.php.net/is_dir"><span style="color:#000066;">is_dir</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$file</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; trace<span style="color:#006600; font-weight:bold;">&#40;</span> &amp;quot;skipping <span style="color:#0000FF;">$file</span>&amp;quot;, <span style="color:#000000; font-weight:bold;">true</span> <span style="color:#006600; font-weight:bold;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#616100;">continue</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span> <span style="color:#616100;">else</span> <span style="color:#006600; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$ts</span> = <a href="http://www.php.net/filemtime"><span style="color:#000066;">filemtime</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$file</span><span style="color:#006600; font-weight:bold;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#616100;">if</span><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#0000FF;">$ts</span> &amp;lt;<span style="color:#0000FF;">$cutoff</span> <span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; trace<span style="color:#006600; font-weight:bold;">&#40;</span> &amp;quot;rotating <span style="color:#0000FF;">$file</span>, &amp;quot;.<a href="http://www.php.net/date"><span style="color:#000066;">date</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'r'</span>,<span style="color:#0000FF;">$ts</span><span style="color:#006600; font-weight:bold;">&#41;</span>, <span style="color:#000000; font-weight:bold;">true</span> <span style="color:#006600; font-weight:bold;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$succ</span> = @<a href="http://www.php.net/rename"><span style="color:#000066;">rename</span></a><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#0000FF;">$file</span>, <span style="color:#0000FF;">$dir_old</span> <span style="color:#006600; font-weight:bold;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#616100;">if</span><span style="color:#006600; font-weight:bold;">&#40;</span> !<span style="color:#0000FF;">$succ</span> <span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; trace<span style="color:#006600; font-weight:bold;">&#40;</span> &amp;quot;failed to rotate <span style="color:#0000FF;">$file</span>!&amp;quot; <span style="color:#006600; font-weight:bold;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span> <span style="color:#616100;">else</span> <span style="color:#006600; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; trace<span style="color:#006600; font-weight:bold;">&#40;</span> &amp;quot;ignoring <span style="color:#0000FF;">$file</span>, &amp;quot;.<a href="http://www.php.net/date"><span style="color:#000066;">date</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'r'</span>,<span style="color:#0000FF;">$ts</span><span style="color:#006600; font-weight:bold;">&#41;</span>, <span style="color:#000000; font-weight:bold;">true</span> <span style="color:#006600; font-weight:bold;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span><br />
&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span><br />
&nbsp; &nbsp; <a href="http://www.php.net/closedir"><span style="color:#000066;">closedir</span></a><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#0000FF;">$dh</span> <span style="color:#006600; font-weight:bold;">&#41;</span>;<br />
<span style="color:#006600; font-weight:bold;">&#125;</span><br />
?&amp;gt;</div>
</div>
</div>
<p></p>
]]></content:encoded>
			<wfw:commentRss>http://ammonlauritzen.com/blog/2010/02/03/simple-two-step-logfile-rotation/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>report-storage.sh</title>
		<link>http://ammonlauritzen.com/blog/2009/10/14/report-storagesh/</link>
		<comments>http://ammonlauritzen.com/blog/2009/10/14/report-storagesh/#comments</comments>
		<pubDate>Wed, 14 Oct 2009 20:55:13 +0000</pubDate>
		<dc:creator>Ammon</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[sysadmin]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://ammonlauritzen.com/blog/?p=552</guid>
		<description><![CDATA[In the grand tradition of my publishing little building-block shell scripts of interest, here goes another one. This is a simple cron job that I run daily on a number of hosts to generate storage usage growth. (This is in addition to Cacti and Nagios which poll some of this data already but for different [...]]]></description>
			<content:encoded><![CDATA[<p>In the grand tradition of my publishing little building-block shell scripts of interest, here goes another one. This is a simple cron job that I run daily on a number of hosts to generate storage usage growth. (This is in addition to Cacti and Nagios which poll some of this data already but for different reasons and with different granularity).</p>
<p>The FILES variable should be populated with a whitespace separated list of files, directories, and block devices to track.</p>
<p>The DB_ABCD variables should be populated with appropriate credentials to talk to a mysql server.</p>
<p>The actual script looks something like this:<br />
[bash]<br />
#!/bin/bash</p>
<p>FILES='/var/lib/mysql/ibdata1 /var/lib/mysql/db/table.ibd /dev/sda1 /var/log/mysql'</p>
<p>LOCAL=`hostname -s`<br />
DB_HOST='aaa'<br />
DB_USER='bbb'<br />
DB_PASS='ccc'</p>
<p>function insert {<br />
    FILE=$1<br />
    SIZE=$2<br />
    QUERY=&quot;replace into metrics.storage_usage values( now(), '$LOCAL', '$FILE', $SIZE )&quot;<br />
    mysql --host=${DB_HOST} --user=${DB_USER} --password=&quot;${DB_PASS}&quot; -e &quot;${QUERY}&quot;<br />
}</p>
<p>for FILE in $FILES<br />
do<br />
    if [ -d $FILE ]; then<br />
        BASE=$FILE<br />
        SIZE=`du -ks $FILE/ | awk '{print $1}'`<br />
    elif [ -b $FILE ]; then<br />
        TMP=`df -k -P $FILE | tail -n1 | awk '{print $3 &quot; &quot; $6}'`<br />
        SIZE=`echo $TMP | awk '{print $1}'`<br />
        BASE=`echo $TMP | awk '{print $2}'`<br />
    else<br />
        BASE=`basename $FILE`<br />
        SIZE=`du -k $FILE | awk '{print $1}'`<br />
    fi</p>
<p>    echo &quot;$BASE = $SIZE&quot;<br />
    insert $BASE $SIZE<br />
done<br />
[/bash]</p>
<p>I am putting my data into a table called "storage_usage" in a database called "metrics":</p>
<div class="syntax_hilite">
<div id="sql-8">
<div class="sql"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> <span style="color: #ff0000;">`storage_usage`</span> <span style="color:#006600; font-weight:bold;">&#40;</span><br />
&nbsp; <span style="color: #ff0000;">`ts`</span> date <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span>,<br />
&nbsp; <span style="color: #ff0000;">`host`</span> varchar<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #cc66cc;">25</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span>,<br />
&nbsp; <span style="color: #ff0000;">`file`</span> varchar<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #cc66cc;">64</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span>,<br />
&nbsp; <span style="color: #ff0000;">`size`</span> int<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #cc66cc;">10</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color: #993333; font-weight: bold;">UNSIGNED</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span> COMMENT <span style="color: #ff0000;">'in kbytes'</span>,<br />
&nbsp; <span style="color: #993333; font-weight: bold;">PRIMARY</span> <span style="color: #993333; font-weight: bold;">KEY</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #ff0000;">`ts`</span>,<span style="color: #ff0000;">`host`</span>,<span style="color: #ff0000;">`file`</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</div>
</div>
<p></p>
<p>Obviously, this could be tweaked in any different number of ways, based on your needs. One tweak you might want to consider if you're running it in a daily cron is to remove the echo so you don't get an email report of every run. Also, if you might want to record more than one snapshot per file per host per day - in the which case you probably need to change the type of the timestamp column to a datetime. Or there might be cases where you want to change the replace to an insert or... whatever <img src='http://ammonlauritzen.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://ammonlauritzen.com/blog/2009/10/14/report-storagesh/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>xtrabackup innodb_file_per_table gotcha</title>
		<link>http://ammonlauritzen.com/blog/2009/08/18/xtrabackup-innodb_file_per_table-gotcha/</link>
		<comments>http://ammonlauritzen.com/blog/2009/08/18/xtrabackup-innodb_file_per_table-gotcha/#comments</comments>
		<pubDate>Tue, 18 Aug 2009 17:55:03 +0000</pubDate>
		<dc:creator>Ammon</dc:creator>
				<category><![CDATA[sysadmin]]></category>
		<category><![CDATA[gotcha]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[innodb]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[xtrabackup]]></category>

		<guid isPermaLink="false">http://ammonlauritzen.com/blog/?p=540</guid>
		<description><![CDATA[Several months ago, I'd switched to using Percona's xtrabackup &#038; innobackupex for all of my mysql backup needs. I had successfully used these backups to restore and replicate databases across several systems. It is good stuff. Last week, I needed to set up new replication of an 80gb database. This should have been routine by [...]]]></description>
			<content:encoded><![CDATA[<p>Several months ago, I'd switched to using Percona's xtrabackup &#038; innobackupex for all of my mysql backup needs. I had successfully used these backups to restore and replicate databases across several systems. It is good stuff.</p>
<p>Last week, I needed to set up new replication of an 80gb database. This should have been routine by now, but when I attempted to prepare the backup this time, it whined and complained and failed. I was kind of frazzled by the time I gave up on the issue and declared it a fluke of one sort or another.</p>
<p>Last night, I tried again from Sunday's full backup, and it happened again:</p>
<pre>
ammon@amy:/var/lib/2009-08-16_04-02-17$ sudo xtrabackup --prepare --target-dir=.
xtrabackup  Ver 0.8.1rc Rev 78 for 5.0.83 unknown-linux-gnu (x86_64)
xtrabackup: cd to .
xtrabackup: This target seems to be not prepared yet.
xtrabackup: xtrabackup_logfile detected: size=75546624, start_lsn=(86 1293090752)
xtrabackup: Temporary instance for recovery is set as followings.
xtrabackup:   innodb_data_home_dir = ./
xtrabackup:   innodb_data_file_path = ibdata1:512M:autoextend
xtrabackup:   innodb_log_group_home_dir = ./
xtrabackup:   innodb_log_files_in_group = 1
xtrabackup:   innodb_log_file_size = 75546624
xtrabackup: Starting InnoDB instance for recovery.
xtrabackup: Using 104857600 bytes for buffer pool (set by --use-memory parameter)
InnoDB: Log scan progressed past the checkpoint lsn 86 1293090752
090818  2:54:34  InnoDB: Database was not shut down normally!
InnoDB: Starting crash recovery.
InnoDB: Reading tablespace information from the .ibd files...
090818  2:54:34  InnoDB: Operating system error number 2 in a file operation.
InnoDB: The error means the system cannot find the path specified.
InnoDB: If you are installing InnoDB, remember that you must create
InnoDB: directories yourself, InnoDB does not create them.
InnoDB: File name .//tmp/#sql6e1e_8cce1_0.ibd
InnoDB: File operation call: 'create'.
InnoDB: Cannot continue operation.
</pre>
<p>I gave up after poking a few things.</p>
<p>This morning's fresh look turned up <a href='http://bugs.mysql.com/bug.php?id=41609'>this bug report</a>.</p>
<pre>
ammon@amy:/var/lib/2009-08-16_04-02-17$ sudo <b>mkdir tmp</b>
ammon@amy:/var/lib/2009-08-16_04-02-17$ sudo xtrabackup --prepare --target-dir=.
xtrabackup  Ver 0.8.1rc Rev 78 for 5.0.83 unknown-linux-gnu (x86_64)
xtrabackup: cd to .
xtrabackup: This target seems to be not prepared yet.
090818 12:27:41  InnoDB: Operating system error number 2 in a file operation.
InnoDB: The error means the system cannot find the path specified.
xtrabackup: Warning: cannot open ./xtrabackup_logfile. will try to find.
xtrabackup: 'ib_logfile0' seems to be 'xtrabackup_logfile'. will retry.
xtrabackup: xtrabackup_logfile detected: size=84983808, start_lsn=(86 1293090752)
xtrabackup: Temporary instance for recovery is set as followings.
xtrabackup:   innodb_data_home_dir = ./
xtrabackup:   innodb_data_file_path = ibdata1:512M:autoextend
xtrabackup:   innodb_log_group_home_dir = ./
xtrabackup:   innodb_log_files_in_group = 1
xtrabackup:   innodb_log_file_size = 84983808
xtrabackup: Starting InnoDB instance for recovery.
xtrabackup: Using 104857600 bytes for buffer pool (set by --use-memory parameter)
InnoDB: Log scan progressed past the checkpoint lsn 86 1293090752
090818 12:27:41  InnoDB: Database was not shut down normally!
InnoDB: Starting crash recovery.
InnoDB: Reading tablespace information from the .ibd files...
InnoDB: Doing recovery: scanned up to log sequence number 86 1298333184 (6 %)
InnoDB: Doing recovery: scanned up to log sequence number 86 1303576064 (13 %)
InnoDB: Doing recovery: scanned up to log sequence number 86 1308818944 (20 %)
InnoDB: Doing recovery: scanned up to log sequence number 86 1314061824 (27 %)
InnoDB: Doing recovery: scanned up to log sequence number 86 1319304704 (34 %)
090818 12:27:44  InnoDB: Starting an apply batch of log records to the database...
<i>... snip ...</i>
</pre>
<p>That's right. There's a bug in innodb restoration that interprets location of /tmp (configurable in my.cnf) to be relative in stead of absolute.</p>
<p>So, if you have problems while trying to restore from an xtrabackup/ibbackup snapshot (or if you're trying to recover innodb after a crash), just creating the offending tmp directory appears to work.</p>
]]></content:encoded>
			<wfw:commentRss>http://ammonlauritzen.com/blog/2009/08/18/xtrabackup-innodb_file_per_table-gotcha/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>init.d template</title>
		<link>http://ammonlauritzen.com/blog/2009/06/18/initd-template/</link>
		<comments>http://ammonlauritzen.com/blog/2009/06/18/initd-template/#comments</comments>
		<pubDate>Thu, 18 Jun 2009 17:29:31 +0000</pubDate>
		<dc:creator>Ammon</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[sysadmin]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[init.d]]></category>

		<guid isPermaLink="false">http://ammonlauritzen.com/blog/?p=512</guid>
		<description><![CDATA[This is a rudimentary template that I've been using for very quick and dirty /etc/init.d scripts recently. It works under the assumption that your server daemon has a unique name and only ever runs a single instance - this also means that the binary and the init.d script cannot share a name - otherwise strange [...]]]></description>
			<content:encoded><![CDATA[<p>This is a rudimentary template that I've been using for very quick and dirty /etc/init.d scripts recently.</p>
<p>It works under the assumption that your server daemon has a unique name and only ever runs a single instance - this also means that the binary and the init.d script cannot share a name - otherwise strange things happen <img src='http://ammonlauritzen.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>Actual invocation logic may need to be updated on a per-service basis and chkconfig style headers would have to be added manually, but it works well for what it is.</p>
<p>[bash]<br />
#!/bin/bash</p>
<p>DIR=''	# path to the daemon executable<br />
CMD=''	# name of the command itself<br />
ARG=''	# optional. any arguments to pass when starting<br />
NAM=''	# descriptive name of the daemon so it shows up pretty</p>
<p>function get_ps {<br />
	ps --no-header -C${CMD}<br />
}</p>
<p>function do_start {<br />
	echo -n &quot;Starting ${NAM}... &quot;<br />
	cd ${DIR}<br />
	nohup ./${CMD} ${ARG} &amp;<br />
	SUCC=`get_ps | wc -l`<br />
	if [ &quot;1&quot; == &quot;$SUCC&quot; ]; then<br />
		echo &quot;[SUCCESS]&quot;<br />
	else<br />
		echo &quot;[FAILURE]&quot;<br />
	fi<br />
}</p>
<p>function do_stop {<br />
	echo -n &quot;Stopping ${NAM}... &quot;<br />
	PID=`get_ps | awk '{print $1}'`<br />
	kill $PID<br />
	SUCC=`get_ps | wc -l`<br />
	if [ &quot;0&quot; == &quot;$SUCC&quot; ]; then<br />
		echo &quot;[SUCCESS]&quot;<br />
	else<br />
		echo &quot;[FAILURE]&quot;<br />
	fi<br />
}</p>
<p>case &quot;${1:-''}&quot; in<br />
	'start')<br />
		do_start<br />
		;;<br />
	'stop')<br />
		do_stop<br />
		;;<br />
	'restart')<br />
		do_stop<br />
		do_start<br />
		;;<br />
	*)<br />
		#echo &quot;Usage: $SELF start|stop|restart|reload|force-reload|status&quot;<br />
		echo &quot;Usage: $SELF start|stop|restart&quot;<br />
		exit 1<br />
		;;<br />
esac<br />
[/bash]</p>
]]></content:encoded>
			<wfw:commentRss>http://ammonlauritzen.com/blog/2009/06/18/initd-template/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>i </title>
		<link>http://ammonlauritzen.com/blog/2009/02/04/i-heart-rsync/</link>
		<comments>http://ammonlauritzen.com/blog/2009/02/04/i-heart-rsync/#comments</comments>
		<pubDate>Wed, 04 Feb 2009 22:07:39 +0000</pubDate>
		<dc:creator>Ammon</dc:creator>
				<category><![CDATA[personal]]></category>
		<category><![CDATA[sysadmin]]></category>
		<category><![CDATA[rsync]]></category>

		<guid isPermaLink="false">http://ammonlauritzen.com/blog/?p=448</guid>
		<description><![CDATA[I really love rsync. I'll get to the specifics later, but first, the excessive backstory. I've been doing a lot of backup scripting recently. Yes, there are tons of commercial apps out there, but none of them that I've looked into are a perfect match for all of our needs. I'll eventually settle on one [...]]]></description>
			<content:encoded><![CDATA[<p>I really love rsync. I'll get to the specifics later, but first, the excessive backstory.</p>
<p>I've been doing a lot of backup scripting recently. Yes, there are tons of commercial apps out there, but none of them that I've looked into are a perfect match for all of our needs. I'll eventually settle on one and it will probably replace 80% of my scripts, but plenty will remain.</p>
<p>One problem that I've encountered while doing the whole backup juggling bit is the ferocious rate of change in the nature of the data we're archiving. Code I'd written a year ago was obsoleted 6 months ago by code that was obsoleted 3 months ago by code that I replaced a few weeks back that is being replaced by the code I'm writing right now.</p>
<p>Another one of the problems is that the sheer quantity of data involved is growing in a very uncontrolled way. Early last May (the oldest archive I have easy access to), a full archive of the entire system was barely 3gb in size. Today, it is closer to 60gb. ~20x growth over the last 9 months.</p>
<p>It's been fun, if somewhat frustrating, dealing with all of the growth.</p>
<p>On January 20th, I needed to perform a long-deprecated sort of snapshot. The code that generated this sort of file no longer worked because so many things had changed. I wound up digging out old scripts from SVN and updating them to run against the new environment.</p>
<p>Because of the amount of data involved, this took a very long time. It didn't help that the scripts consumed an unfair amount of system resources - I couldn't run them with any meaningful priority during the day without crippling everyone else.</p>
<p>Lots of low priority io later, I finally had a 54gb tar file... In one of the three places I needed it.</p>
<p>The first transfer was simple, the hosts are on the same gigabit switch as each other. Unfortunately, scping that much data between two hosts at that kind of speed has negative effects on the systems involved. I had to throttle the transfer way down to before it could run without visibly impacting performance.</p>
<div class="syntax_hilite">
<div id="code-12">
<div class="code">rsync --partial --bwlimit=<span style="color:#800000;">10000</span> -e <span style="color:#CC0000;">"ssh -i ${RSA_KEYFILE}"</span> $<span style="color:#006600; font-weight:bold;">&#123;</span>LOCAL_FNAME<span style="color:#006600; font-weight:bold;">&#125;</span> <span style="color:#006600; font-weight:bold;">&#123;</span>REMOTE_USER<span style="color:#006600; font-weight:bold;">&#125;</span>@$<span style="color:#006600; font-weight:bold;">&#123;</span>REMOTE_HOST<span style="color:#006600; font-weight:bold;">&#125;</span>:$<span style="color:#006600; font-weight:bold;">&#123;</span>REMOTE_FNAME<span style="color:#006600; font-weight:bold;">&#125;</span></div>
</div>
</div>
<p></p>
<p>The second transfer... wasn't so easy. I needed to move the file to my office without negatively impacting everyone's ability to work - and I couldn't wait for the transfer to run at low enough speeds not to cripple the T1.</p>
<p>We have a backup 6mbit DSL link that I only use for emergencies and for testing. Even at a full 6mbit, the transfer would have taken more than 36 hours. Compressing the file took a while but brought the file size down to a much more manageable 24gb (~11 hours over the DSL).</p>
<p>The only remaining gotcha was that DSL link can't actually SSH through the firewall into the colo <img src='http://ammonlauritzen.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  So... I started the transfer over https last night and went home.</p>
<p>This morning, it was finally time to decompress the monstrosity locally, but I noticed a hiccup in dsl traffic overnight and figured I'd run a check on things first - just to make sure that http resume had worked correctly.</p>
<div class="syntax_hilite">
<div id="code-13">
<div class="code">ammon@scruffy:~$ gunzip --test archive_2009_01_20.<span style="">tar</span>.<span style="">gz</span><br />
gunzip: archive_2009_01_20.<span style="">tar</span>.<span style="">gz</span>: invalid compressed data--format violated</div>
</div>
</div>
<p>
This was not good. I had a 24gb file that was somehow corrupted... <u>somewhere</u>.</p>
<p>Since re-downloading the whole thing would cost me another whole day... I had to find out a way to repair the file in a reasonable amount of time. Some research and suggestion gathering later, it was confirmed that rsync would probably handle the task.</p>
<p>Assuming that I wouldn't be using an unfair amount of bandwidth for this, I switched back to the T1 link so I could tunnel through SSH again.</p>
<div class="syntax_hilite">
<div id="code-14">
<div class="code">ammon@scruffy:~$ rsync --checksum --inplace -e <span style="color:#CC0000;">"ssh"</span> wernstrom:/tmp/archive_2009_01_20.<span style="">tar</span>.<span style="">gz</span> archive_2009_01_20.<span style="">tar</span>.<span style="">gz</span> </p>
<p>sent <span style="color:#800000;">1280578</span> bytes&nbsp; received <span style="color:#800000;">1440757</span> bytes&nbsp; <span style="color:#800000;">2622</span>.<span style="color:#800000;">97</span> bytes/sec<br />
total size is <span style="color:#800000;">25619572576</span>&nbsp; speedup is <span style="color:#800000;">9414</span>.<span style="color:#800000;">34</span></p>
<p>ammon@scruffy:~$ gunzip --test archive_2009_01_20.<span style="">tar</span>.<span style="">gz</span><br />
ammon@scruffy:~$</div>
</div>
</div>
<p><i>(remember, this is unix, no output implies success)</i></p>
<p>So, yeah. Rsync, I love it when you work. <img src='http://ammonlauritzen.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>It took some time and generated a lot of disk activity when the process started, but it worked almost painlessly and only transferred the data I needed - thus leaving the shared network resource free for everyone else <img src='http://ammonlauritzen.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://ammonlauritzen.com/blog/2009/02/04/i-heart-rsync/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ccent</title>
		<link>http://ammonlauritzen.com/blog/2008/07/02/ccent/</link>
		<comments>http://ammonlauritzen.com/blog/2008/07/02/ccent/#comments</comments>
		<pubDate>Wed, 02 Jul 2008 21:25:20 +0000</pubDate>
		<dc:creator>Ammon</dc:creator>
				<category><![CDATA[personal]]></category>
		<category><![CDATA[sysadmin]]></category>
		<category><![CDATA[cisco]]></category>
		<category><![CDATA[networking]]></category>

		<guid isPermaLink="false">http://ammonlauritzen.com/blog/?p=390</guid>
		<description><![CDATA[So... I just finished the first half of my CCNA today. I never really cared about networking much beyond that needed to make sure clients on a lan can talk to their dns server... but we've been growing enough here at work that the needs quickly outpaced my prior skillset. And since I was the [...]]]></description>
			<content:encoded><![CDATA[<p>So... I just finished the <a href='http://www.cisco.com/web/learning/le3/current_exams/640-822.html'>first half</a> of my <a href='http://www.cisco.com/web/learning/le3/le2/le0/le9/learning_certification_type_home.html'>CCNA</a> today.</p>
<p>I never really cared about networking much beyond that needed to make sure clients on a lan can talk to their dns server... but we've been growing enough here at work that the needs quickly outpaced my prior skillset. And since I was the closest thing we had to a network admin, I got signed up for classes <img src='http://ammonlauritzen.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>It's been fun and profoundly enlightening. I didn't expect to have my way of thinking so radically altered, but I'm hardly complaining.</p>
<p>I'll be starting up the <a href='http://www.cisco.com/web/learning/le3/current_exams/640-816.html'>second class</a> in a week or two. This'll include such topics as VLANs, IPv6, and fancy routing protocols. I'm stoked.</p>
<p>It's funny. I never finished college (though I took classes for roughly 10 years), so this is actually the first certificate of education I've received since highschool.</p>
<p>The comment was made at work that I'd dinged as a sysadmin. I haven't. I'm just cherry picking my next few levels in netadmin <img src='http://ammonlauritzen.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://ammonlauritzen.com/blog/2008/07/02/ccent/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>svn get revision</title>
		<link>http://ammonlauritzen.com/blog/2008/05/27/svn-get-revision/</link>
		<comments>http://ammonlauritzen.com/blog/2008/05/27/svn-get-revision/#comments</comments>
		<pubDate>Tue, 27 May 2008 19:57:04 +0000</pubDate>
		<dc:creator>Ammon</dc:creator>
				<category><![CDATA[sysadmin]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[subversion]]></category>

		<guid isPermaLink="false">http://ammonlauritzen.com/blog/?p=388</guid>
		<description><![CDATA[One of the more annoying things about svn is that (to my knowledge), there exists no single simple command to retrieve the revision number from a shell. What I want: ammon@hermes:~/repo$ svn info --get-revision . 1234 But of course, nothing like this exists. Thankfully, svn info's output IS easy enough to parse. You just have [...]]]></description>
			<content:encoded><![CDATA[<p>One of the more annoying things about svn is that (to my knowledge), there exists no single simple command to retrieve the revision number from a shell.</p>
<p>What I want:</p>
<div class="syntax_hilite">
<div id="code-18">
<div class="code">ammon@hermes:~/repo$ svn info --get-revision .<br />
<span style="color:#800000;">1234</span></div>
</div>
</div>
<p></p>
<p>But of course, nothing like this exists.</p>
<p>Thankfully, svn info's output IS easy enough to parse. You just have to do it your self.</p>
<div class="syntax_hilite">
<div id="code-19">
<div class="code">ammon@hermes:~/repo$ svn info | grep Revision | awk -- <span style="color:#CC0000;">'{print $2}'</span><br />
<span style="color:#800000;">1234</span></div>
</div>
</div>
<p></p>
<p>Will give you the revision of your current checkout without the network hit of a call to svn log.</p>
<p>To get the current version of the repo itself (hits the network), add "-r HEAD" to the svn info call:</p>
<div class="syntax_hilite">
<div id="code-20">
<div class="code">ammon@hermes:~/repo$ svn info -r HEAD | grep Revision | awk -- <span style="color:#CC0000;">'{print $2}'</span><br />
<span style="color:#800000;">1280</span></div>
</div>
</div>
<p></p>
<p>Of course, svn info also supports outputting info as xml, so you could use that to parse things in a more advanced environment but one where you're still not using the svn api bindings.</p>
]]></content:encoded>
			<wfw:commentRss>http://ammonlauritzen.com/blog/2008/05/27/svn-get-revision/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

