<?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>The Dining Philosopher &#187; Programming</title>
	<atom:link href="http://www.dining-philosopher.com/category/computing/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dining-philosopher.com</link>
	<description>Atheist Gun Owners Unite!</description>
	<lastBuildDate>Fri, 25 Jun 2010 15:43:40 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>Spring Semester Over</title>
		<link>http://www.dining-philosopher.com/2010/05/27/spring-semester-over/</link>
		<comments>http://www.dining-philosopher.com/2010/05/27/spring-semester-over/#comments</comments>
		<pubDate>Thu, 27 May 2010 15:13:36 +0000</pubDate>
		<dc:creator>Nick</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[algorithms]]></category>
		<category><![CDATA[c]]></category>

		<guid isPermaLink="false">http://www.dining-philosopher.com/?p=640</guid>
		<description><![CDATA[I passed Calculus, finally. I also passed Physics, where oddly, on all three tests I received exactly an 80. I would say that I got an 80 on the final, except that it was extremely easy. In the meantime I&#8217;ve been doing a little work around the house and on the car, and I&#8217;ve also [...]]]></description>
			<content:encoded><![CDATA[<p>I passed Calculus, finally. I also passed Physics, where oddly, on all three tests I received exactly an 80. I would say that I got an 80 on the final, except that it was extremely easy.</p>
<p>In the meantime I&#8217;ve been doing a little work around the house and on the car, and I&#8217;ve also done a little C programming, just for the heck of it.</p>
<p>I&#8217;ve revisited my infamous random sort algorithms. I used variations of a random sort algorithm in my data structures and algorithms class at UWYO, one or two homemade tests, and on a test for course placement at UTA (with a whole lot of controversy around that).</p>
<p>The one at UWYO was what I like to call the &#8220;shuffle the deck&#8221; variation. You assign each element in whatever list you want sorted a new place in the list, chosen randomly but only using each place once, and then check to see if it&#8217;s sorted. Repeat until the list is sorted. I remember doing this cleverly, but I can&#8217;t remember exactly how. I&#8217;m working on recreating it. (This is known as a <a href="http://en.wikipedia.org/wiki/Bogosort" target="_blank">Bogosort</a>, apparently I wasn&#8217;t the first one to think of it.)</p>
<p>The one on that test at UTA was a simple swap two values, and check if sorted. It was all from memory in pseudo-code. This, also, is known as a Bozosort. All I had to do, according to the instructions, was to &#8220;Write, in pseudo-code, a sorting algorithm.&#8221; So, I wrote a sorting algorithm. I got bad marks on that test (but was still able to pass after a small scolding). Unfortunately, my requests to see the actual graded test went against deaf ears&#8230;</p>
<p>So, anyway, here&#8217;s what I have:</p>
<p><code><br />
int isSorted(int array[], int length)<br />
{<br />
int c;<br />
for (c = 0; c &lt; (length - 1); ++c) if (!(array[c] &lt;= array[c + 1])) return 0;</p>
<p>return 1;<br />
}</p>
<p>//rands1 - Random Swap Sort - v1.0.1<br />
//1.0.1 - Changed return value from int to void<br />
void rands1(int array[], int length)<br />
{<br />
while (!isSorted(array, length))<br />
{<br />
swap(&amp;array[rand() % length], &amp;array[rand() % length]);<br />
}<br />
}</p>
<p>//rands2 - Shuffle sort v0<br />
void rands2(int array[], int length)<br />
{<br />
int i;<br />
while (!isSorted(array, length))<br />
{<br />
//give each array value a new index from an index pool and swap them all<br />
}<br />
}<br />
</code></p>
<p>I haven&#8217;t quite implemented my favorite yet. I have timed the sorting of random lists from 2 to 12 items long, each 1000 times. I turns out that sorting a list from 2-9 items is, as far as a human can tell, just as fast as quicksort and the like. It&#8217;s that magic number 10 where things start taking time. Then at 11 items it&#8217;s already unbearable. At a list size of 12 items it took 54 hours to sort 1000 unique lists, the average one taking 3 minutes or so.</p>
<p>I&#8217;m working on the bozosort, and can&#8217;t wait to see how slow it is.</p>
<div id="in_post_ad_bottom_1" style="clear:both;margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "pub-7462076129993234";
/* 468x60, created 9/9/09 */
google_ad_slot = "5795392629";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div><div style='clear:both'></div>]]></content:encoded>
			<wfw:commentRss>http://www.dining-philosopher.com/2010/05/27/spring-semester-over/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Nonprogramming Programmers</title>
		<link>http://www.dining-philosopher.com/2010/03/31/nonprogramming-programmers/</link>
		<comments>http://www.dining-philosopher.com/2010/03/31/nonprogramming-programmers/#comments</comments>
		<pubDate>Wed, 31 Mar 2010 23:00:41 +0000</pubDate>
		<dc:creator>Nick</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[School]]></category>

		<guid isPermaLink="false">http://www.dining-philosopher.com/?p=586</guid>
		<description><![CDATA[This and the related sub-links are pretty interesting. Apparently there are programmers in the real world who can&#8217;t program, at all. I&#8217;ve noticed that their were a few people in my CoSci classes that just &#8220;didn&#8217;t get it&#8221;. They couldn&#8217;t program for the life of them, and would constantly be seeking help. I just thought they [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.codinghorror.com/blog/2010/02/the-nonprogramming-programmer.html" target="_blank">This</a> and the related sub-links are pretty interesting. Apparently there are programmers in the real world who can&#8217;t program, at all. I&#8217;ve noticed that their were a few people in my CoSci classes that just &#8220;didn&#8217;t get it&#8221;. They couldn&#8217;t program for the life of them, and would constantly be seeking help. I just thought they would give up and go for another major. However, some of them are graduating. Somehow&#8230;.</p>
<p><span id="more-586"></span></p>
<p>I&#8217;ve personally witnessed, as a computer lab assistant (who wasn&#8217;t supposed to be helping people with homework), as a CS student (trying to help other students), and as a IT person, that there are two groups of people: Those who get computers, and those who don&#8217;t (like, really <em>do not</em> get it).</p>
<p>First, as an IT support guy, there are people that I rarely ever have to help. The users can either figure it out by themselves or look it up themselves. Then, there are people who stop at the slightest bit of unfamiliarity, and call me. Of course, there are people that are a bit of both, but most stick to one side or the other. There&#8217;s a gap.</p>
<p>There&#8217;s another gap between programmers and non-programmers. Well, no. I know some computer savvy people that could probably learn to program without much fuss. Let me say it like this: There&#8217;s a gap between people that can program and people that cannot program.</p>
<p>And it&#8217;s glaring. It&#8217;s more like a sharp divide. It&#8217;s pointy.</p>
<p>When I worked as a computer lab assistant, I ran in to these two students who were in a beginning programming course, I think it was Java. It was some C style language. Whatever.</p>
<p>Anyway, first of all, their code was the ugliest shit I have ever seen. Before I could help them, I had to reformat all their whitespace so I could read it. Then I tried over and over again to explain to them the various reasons why their programs would not compile.</p>
<p>They never got it. I ended up doing their work for them just to get them to stop bothering me. I&#8217;ve seen people in my CS classes who just don&#8217;t understand the simplest things, like assignment or logic/conditional statements. It seemed to me like they were expecting to learn each program character by character&#8211;that by studying each line of someone else&#8217;s code they would &#8220;learn&#8221; how to do it. It seemed that they couldn&#8217;t take a step back and abstract any of the problems. There had to be a certain way to do it and that was it, it had to be some certain combination of key strokes to make it work.</p>
<p>I&#8217;m probably not explaining this well. It&#8217;s not about key strokes, it&#8217;s about understanding the problem, and the ways a computer can and can&#8217;t solve that problem, and what ways are the most efficient. Only then is it about key strokes and code.</p>
<p>How are these people graduating?</p>
<div id="in_post_ad_bottom_1" style="clear:both;margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "pub-7462076129993234";
/* 468x60, created 9/9/09 */
google_ad_slot = "5795392629";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div><div style='clear:both'></div>]]></content:encoded>
			<wfw:commentRss>http://www.dining-philosopher.com/2010/03/31/nonprogramming-programmers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>100th Post! (&#8230;and Megasquirt Woes)</title>
		<link>http://www.dining-philosopher.com/2009/12/02/100th-post-and-megasquirt-woes/</link>
		<comments>http://www.dining-philosopher.com/2009/12/02/100th-post-and-megasquirt-woes/#comments</comments>
		<pubDate>Wed, 02 Dec 2009 20:48:01 +0000</pubDate>
		<dc:creator>Nick</dc:creator>
				<category><![CDATA[Automotive]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[cars]]></category>
		<category><![CDATA[megasquirt]]></category>
		<category><![CDATA[z31]]></category>

		<guid isPermaLink="false">http://www.dining-philosopher.com/?p=517</guid>
		<description><![CDATA[Hum, 100 posts. 100 posts about random crap, but 100 nonetheless. Speaking of random, I was (am) attempting to make my own version of the MegaLogViewer for Megasquirt. In this attempt, I happened to notice that my Z31 cranks at 280-325 or so RPM. This is not a big deal, it&#8217;s just that I have [...]]]></description>
			<content:encoded><![CDATA[<p>Hum, 100 posts. 100 posts about random crap, but 100 nonetheless.</p>
<p>Speaking of random, I was (am) attempting to make my own version of the MegaLogViewer for Megasquirt. In this attempt, I happened to notice that my Z31 cranks at 280-325 or so RPM. This is not a big deal, it&#8217;s just that I have my MS box set to interpret anything at 300 RPM or below as &#8220;cranking&#8221;. It applies a whole different fuel factor to the engine when cranking versus running, which is 301 and up RPM.</p>
<p>So, this could explain why my car is hard to start sometimes. One of these days, when I&#8217;m not busy studying (which consists of mostly me running errands and otherwise not studying), I will up the cranking RPM to 350 or so and see if I can finally get some positive feedback from modifying the cranking pulsewidths. Before now I was pretty much shooting in the dark, with some settings working some of the time.</p>
<p>Here&#8217;s a screenshot of my program so far. It&#8217;s in C#, and it&#8217;s horridly put together right now. All it does as of now is load files (up to a million records long, anyway), parse the data in to memory, and draw unscaled graphs of the first x records. Where x is the pixel size of that picturebox control you see there (the actual graph):</p>
<div id="attachment_518" class="wp-caption alignnone" style="width: 310px"><a href="http://www.dining-philosopher.com/wp-content/uploads/mslog1.png"><img class="size-medium wp-image-518" title="mslog1" src="http://www.dining-philosopher.com/wp-content/uploads/mslog1-300x283.png" alt="MSLog Preview" width="300" height="283" /></a><p class="wp-caption-text">MSLog Preview</p></div>
<p>The ticker control at the bottom is eventually going to &#8220;scroll&#8221; the graph. Right now it does do something, it scales itself according to whatever file is loaded (thus, however many records are loaded), but I&#8217;ve yet to implement the scrolling feature.</p>
<div id="in_post_ad_bottom_1" style="clear:both;margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "pub-7462076129993234";
/* 468x60, created 9/9/09 */
google_ad_slot = "5795392629";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div><div style='clear:both'></div>]]></content:encoded>
			<wfw:commentRss>http://www.dining-philosopher.com/2009/12/02/100th-post-and-megasquirt-woes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WackoWiki Lives Up To It&#8217;s Name</title>
		<link>http://www.dining-philosopher.com/2009/11/23/wackwiki-is-wacko/</link>
		<comments>http://www.dining-philosopher.com/2009/11/23/wackwiki-is-wacko/#comments</comments>
		<pubDate>Mon, 23 Nov 2009 19:22:21 +0000</pubDate>
		<dc:creator>Nick</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[The Internets]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[internet]]></category>
		<category><![CDATA[wiki]]></category>

		<guid isPermaLink="false">http://www.dining-philosopher.com/?p=482</guid>
		<description><![CDATA[I wanted a PHP/MySQL Wiki to use for my car site, and I crossed upon some crazy Russian made one called &#8220;WackoWiki&#8221;. I just installed WackoWiki try it out. I was quickly surprised to realize that after editing the main page once, every subsequent visit would log me out. It was very annoying. Then, after [...]]]></description>
			<content:encoded><![CDATA[<p>I wanted a PHP/MySQL Wiki to use for my car site, and I crossed upon some crazy Russian made one called &#8220;WackoWiki&#8221;. I just installed WackoWiki try it out. I was quickly surprised to realize that after editing the main page once, every subsequent visit would log me out. It was very annoying. Then, after logging in a few times, I realized that I could also log in using arbitrary passwords.</p>
<p>Needless to say, I uninstalled it. MediaWiki it is. Darn.</p>
<div id="in_post_ad_bottom_1" style="clear:both;margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "pub-7462076129993234";
/* 468x60, created 9/9/09 */
google_ad_slot = "5795392629";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div><div style='clear:both'></div>]]></content:encoded>
			<wfw:commentRss>http://www.dining-philosopher.com/2009/11/23/wackwiki-is-wacko/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Interesting Errors</title>
		<link>http://www.dining-philosopher.com/2009/09/09/interesting-errors/</link>
		<comments>http://www.dining-philosopher.com/2009/09/09/interesting-errors/#comments</comments>
		<pubDate>Wed, 09 Sep 2009 20:37:15 +0000</pubDate>
		<dc:creator>Nick</dc:creator>
				<category><![CDATA[Computing]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[diversity]]></category>
		<category><![CDATA[engrish]]></category>
		<category><![CDATA[errors]]></category>
		<category><![CDATA[warnings]]></category>
		<category><![CDATA[wtf]]></category>

		<guid isPermaLink="false">http://www.dining-philosopher.com/?p=124</guid>
		<description><![CDATA[Software developers come from various far away places. Sometimes, they come from places were English isn&#8217;t their first, or best language. Sometimes, they decide that holding out on important details is necessary, for some reason. Let us bask in their diversity: That narrows it down to a Visual C++ program installed in &#8220;C:\Program Files&#8221;, thanks! [...]]]></description>
			<content:encoded><![CDATA[<p>Software developers come from various far away places. Sometimes, they come from places were English isn&#8217;t their first, or best language. Sometimes, they decide that holding out on important details is necessary, for some reason. Let us bask in their diversity: <span id="more-124"></span></p>
<p><a href="http://www.dining-philosopher.com/wp-content/uploads/vcpp-error.JPG"><img class="aligncenter size-full wp-image-112" title="vcpp-error" src="http://www.dining-philosopher.com/wp-content/uploads/vcpp-error.JPG" alt="vcpp-error" width="446" height="185" /></a></p>
<p>That narrows it down to a Visual C++ program installed in &#8220;C:\Program Files&#8221;, thanks!</p>
<p><img class="aligncenter size-full wp-image-150" title="my-app-name" src="http://www.dining-philosopher.com/wp-content/uploads/my-app-name.JPG" alt="my-app-name" width="278" height="126" />Not only is the message box&#8217;s title botched, but they didn&#8217;t even bother to enter &#8220;Their application name&#8221;.</p>
<p><a href="http://www.dining-philosopher.com/wp-content/uploads/vaio-firmware-lol.JPG"><img class="aligncenter size-medium wp-image-113" title="vaio-firmware-lol" src="http://www.dining-philosopher.com/wp-content/uploads/vaio-firmware-lol-300x236.jpg" alt="vaio-firmware-lol" width="300" height="236" /></a>I made sure, after I shutdown Windows after exit the program, that I turned off a computer. This reminds me off the signs in the restrooms at school: &#8220;Please make sure toilet is flushed&#8221;. Meh, that wasn&#8217;t so funny.</p>
<p>And to finish off this post, I give you the almighty Microsoft Installer uninstallation script for Symantec Endpoint Protection:</p>
<p><img class="aligncenter size-full wp-image-143" title="sep-longtime" src="http://www.dining-philosopher.com/wp-content/uploads/sep-longtime.JPG" alt="sep-longtime" width="386" height="147" /></p>
<p>Don&#8217;t be fooled, neither the time remaining <em>nor</em> the progress bar actually indicate anything useful. It actually takes about 3-5 minutes, depending on the computer. It shouldn&#8217;t take more than one minute, but perhaps Microsoft or Symantec thought a few useless time-wasting loops were needed. The timer on it is so inaccurate, it quickly jumps down to 1 hour, then 40 minutes, and so on until it reads zero seconds. And then it stays at zero seconds for another minute or two. And then the progress bar repeats a few times, each time rather quickly, though. My question is: Why even bother putting the progress bar or the time estimate there, Microsoft? Why not just say&#8230; &#8220;Please wait&#8230;&#8221;</p>
<div id="in_post_ad_bottom_1" style="clear:both;margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "pub-7462076129993234";
/* 468x60, created 9/9/09 */
google_ad_slot = "5795392629";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div><div style='clear:both'></div>]]></content:encoded>
			<wfw:commentRss>http://www.dining-philosopher.com/2009/09/09/interesting-errors/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WordPress Upload Bug</title>
		<link>http://www.dining-philosopher.com/2009/09/09/wordpress-upload-bug/</link>
		<comments>http://www.dining-philosopher.com/2009/09/09/wordpress-upload-bug/#comments</comments>
		<pubDate>Wed, 09 Sep 2009 20:13:15 +0000</pubDate>
		<dc:creator>Nick</dc:creator>
				<category><![CDATA[Computing]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[bug]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.dining-philosopher.com/?p=116</guid>
		<description><![CDATA[I noticed, as I tried to upload images from WordPress, that the images would not be in the correct directory. This is a problem with the default value of a setting under Miscellaneous in Settings. If you &#8220;wp-content&#8221; folder permission are correct (this depends on your server&#8217;s settings, mine required a temporary &#8220;chmod 777&#8243;), then you [...]]]></description>
			<content:encoded><![CDATA[<p>I noticed, as I tried to upload images from WordPress, that the images would not be in the correct directory. This is a problem with the default value of a setting under <strong>Miscellaneous</strong> in <strong>Settings</strong>. <span id="more-116"></span></p>
<p>If you &#8220;wp-content&#8221; folder permission are correct (this depends on your server&#8217;s settings, mine required a temporary &#8220;chmod 777&#8243;), then you will find that the media uploader reports success, but the thumbnail is not loading, and the file path is incorrect.</p>
<p>Right now I am using WordPress 2.8.4. The text in the &#8220;Store uploads in this folder&#8221; box was &#8220;wp-content&#8221;, although just to the right it says the default is supposed to be: &#8220;wp-content/uploads&#8221;. Using this value unmodified results in the actual file being uploaded to &#8220;wp-content&#8221;, but the database information on the file lists it as &#8220;wp-content/uploads&#8221;, even though no &#8220;uploads&#8221; folder existed.</p>
<p>Changing the value to &#8220;wp-content/uploads&#8221;, the so-called default, fixed the problem:</p>
<p><a href="http://www.dining-philosopher.com/wp-content/uploads/wp-uploads-settings.JPG"><img class="aligncenter size-medium wp-image-117" title="wp-uploads-settings" src="http://www.dining-philosopher.com/wp-content/uploads/wp-uploads-settings-300x52.jpg" alt="wp-uploads-settings" width="300" height="52" /></a></p>
<p>After changing that, then attempting to upload, the &#8220;uploads&#8221; directory is created and the file is placed correctly in it. After that, you can change the permissions on wp-content back to whatever they were. The change in permissions is only for the creation of the uploads folder.</p>
<div id="in_post_ad_bottom_1" style="clear:both;margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "pub-7462076129993234";
/* 468x60, created 9/9/09 */
google_ad_slot = "5795392629";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div><div style='clear:both'></div>]]></content:encoded>
			<wfw:commentRss>http://www.dining-philosopher.com/2009/09/09/wordpress-upload-bug/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>A Simple Backup Script for Linux</title>
		<link>http://www.dining-philosopher.com/2009/09/07/a-simple-backup-script-for-linux/</link>
		<comments>http://www.dining-philosopher.com/2009/09/07/a-simple-backup-script-for-linux/#comments</comments>
		<pubDate>Tue, 08 Sep 2009 00:20:56 +0000</pubDate>
		<dc:creator>Nick</dc:creator>
				<category><![CDATA[Computing]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[backup]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[scripting]]></category>

		<guid isPermaLink="false">http://www.dining-philosopher.com/?p=97</guid>
		<description><![CDATA[Not too long ago I upgraded a hard drive in my home server. I went from a 250 GB media storage drive to a 1000 GB one. The main drive is another 250 GB disk. I decided that since I didn&#8217;t have any kind of backup system in place, I could assign those duties to [...]]]></description>
			<content:encoded><![CDATA[<p>Not too long ago I upgraded a hard drive in my home server. I went from a 250 GB media storage drive to a 1000 GB one. The main drive is another 250 GB disk. I decided that since I didn&#8217;t have any kind of backup system in place, I could assign those duties to the extra 250 GB drive. Now, I can&#8217;t backup 1 TB of data on to a drive one fourth of that size, even with hardcore compression, so I do only a selective backup. Actually, as of writing this, I only backup the main hard drive. I plan on adding some of the files on the media drive, as soon as I clean it out a bit, and decide which ones I can live without if there were a drive failure.</p>
<p>Anyway, my Bash scripting skills aren&#8217;t exactly great, but I knew what I wanted to do and how to do it, more or less. Here&#8217;s the code, I&#8217;ll explain later:</p>
<p><span id="more-97"></span></p>
<p><code>#!/bin/bash</code></p>
<p><code># Backup Script<br />
# 2009 Nick Earwood<br />
# TODO:<br />
bsversion=1.6</code></p>
<p><code>. /etc/init.d/functions.sh<br />
#ebegin "Initializaing"<br />
#eend<br />
#einfo "The car is in the garage."<br />
#ewarn "Warning!"<br />
#eerror "Error!"</code></p>
<p><code>einfo "Nick's Backup Script v$bsversion"</code></p>
<p><code> </code></p>
<p><code>myBase=/mnt/usb<br />
myDir=$myBase/backup<br />
myDate=`date +%Y%m%d`<br />
myFile=$myDir/$myDate.tar.bz2<br />
clearOld=1<br />
createBackup=1</code></p>
<p><code>#Check and delete old backups. Must be at least 3 no matter how old.<br />
#Sort of. If 1 file is &lt;21 and 3 files are &gt;21, the 3 files get rm'd, leaving only 1 file.<br />
# Which isn't a big deal, I think.<br />
ebegin "Checking current backups"<br />
if [ $clearOld -eq 1 ]; then<br />
if [ `find . -daystart -mtime +21 -type f | wc -l` -gt 3 ]; then<br />
ebegin "Clearing old backups"<br />
find $myDir -daystart -mtime +21 -type f -name \*.tar.bz2 -exec rm -v {} \;<br />
eend<br />
else<br />
ewarn "Not enough backups exist."<br />
fi<br />
fi<br />
eend</p>
<p>#Check if there's less than 25GB free<br />
ebegin "Checking free space on \"$myBase\""<br />
df -k -P --sync | grep -v "Used" | while read i; do i=( ${i} )<br />
case ${i[5]} in $myBase )<br />
#einfo "Free: ${i[3]}"<br />
df -h | grep $myBase | while read x; do x=( ${x} )<br />
einfo "Free space: ${x[3]}"<br />
done<br />
if [ ${i[3]} -lt 26214400 ]; then<br />
ewarn "Free space is &lt;25GB"<br />
createBackup=0<br />
fi<br />
esac<br />
done<br />
eend</p>
<p>#Actual backup magic if [ $createBackup -eq 1 ]; then<br />
ebegin "Creating $myFile"<br />
echo Backup v$bsversion Started `date` &gt;&gt; /var/log/backup<br />
echo Creating $myFile... &gt;&gt; /var/log/backup<br />
{ time tar -cjf $myFile / --exclude /mnt --exclude /proc --exclude /swapfile --exclude /sys --exclude /var/run &gt; /dev/null; } &gt;&gt; /var/log/backup 2&gt;&amp;1</p>
<p></code></p>
<p><code>echo Backup Completed `date` &gt;&gt; /var/log/backup<br />
eend<br />
else<br />
eerror "Unable to create backup."<br />
fi</code></p>
<p>The script, as it stands now, just backs up the main hard disk (minus /mnt, /proc, my swap file, and other dynamic directories). This results in a 7.5 GB bzip2 file. Since it&#8217;s on my home server, it&#8217;s also somewhat autonomous.</p>
<p>First, it checks for really old backups, and deletes them if there will still be 3 backups left after deleting. This check works when operating normally, but if something or someone were to change the file modification times, the script would delete more than intended.</p>
<p>Second, after potentially clearing out some space, the script checks the amount of free disk space, and will not attempt to backup if there&#8217;s less than 25 GB remaining.</p>
<p>Third, if there&#8217;s enough free space, the actual backup happens. I have the system output the amount of time it takes to compress everything in to a log file. I eventually want to compound some simple statistics about it.</p>
<p>You&#8217;ll notice that the script includes &#8220;functions.sh&#8221; which provides the pretty init style output, that include file, or at least the location of it, is probably specific to Gentoo, the distribution of GNU/Linux I&#8217;m using.</p>
<p>Here&#8217;s what my &#8220;/var/log/backup&#8221; log file looks like:<br />
<code><br />
Backup Started Thu Aug 20 19:20:00 CDT 2009<br />
real    220m24.434s<br />
user    189m50.361s<br />
sys     5m43.754s<br />
Backup Completed Fri Aug 21 00:26:34 CDT 2009</code></p>
<p><code>Backup Started Fri Aug 21 14:20:00 CDT 2009<br />
real    216m16.404s<br />
user    186m16.552s<br />
sys     5m32.129s<br />
Backup Completed Fri Aug 21 16:01:43 CDT 2009</code></p>
<p><code> </code></p>
<p><code>Backup v1.5 Started Mon Aug 24 01:30:01 CDT 2009<br />
real    208m32.106s<br />
user    180m19.725s<br />
sys     4m47.159s<br />
Backup Completed Mon Aug 24 04:58:33 CDT 2009<br />
Backup v1.5 Started Mon Aug 31 01:30:02 CDT 2009<br />
Creating /mnt/usb/backup/20090831.tar.bz2...</code></p>
<p><code>real    215m57.642s<br />
user    185m56.501s<br />
sys     5m50.068s<br />
Backup Completed Mon Aug 31 05:06:00 CDT 2009<br />
Backup v1.6 Started Mon Sep 7 01:30:02 CDT 2009<br />
Creating /mnt/usb/backup/20090907.tar.bz2...</p>
<p></code></p>
<p><code>real    213m39.033s<br />
user    184m2.978s<br />
sys     5m37.151s<br />
Backup Completed Mon Sep 7 05:03:41 CDT 2009<br />
</code></p>
<p>I used  &#8220;cat backup | grep -v tar:&#8221; to get that. The &#8220;-v&#8221; option for grep is filter out all the tar messages; they all begin with &#8220;tar:&#8221;, and there are a lot of them.</p>
<p>The script also outputs the last run to &#8220;/var/log/backup-last&#8221;:<br />
<code> * Nick's Backup Script v1.6<br />
* Checking current backups ...<br />
* Clearing old backups ...                                               [ ok ]<br />
[ ok ]<br />
* Checking free space on "/mnt/usb" ...<br />
* Free space: 188G<br />
[ ok ]<br />
* Creating /mnt/usb/backup/20090907.tar.bz2 ...                          [ ok ]</code></p>
<p>It looks nicer in the console, I swear. Anyway, It&#8217;s been running as a Cron job every Monday around 1:00 AM. So far, my backup directory is listed like so:<br />
<code><br />
-rw-r--r-- 1 root root 7.5G Aug 20 06:00 20090820.tar.bz2<br />
-rw-r--r-- 1 root root 7.5G Aug 21 16:01 20090821.tar.bz2<br />
-rw-r--r-- 1 root root 7.5G Aug 24 04:58 20090824.tar.bz2<br />
-rw-r--r-- 1 root root 7.6G Aug 31 05:06 20090831.tar.bz2<br />
-rw-r--r-- 1 root root 7.6G Sep  7 05:03 20090907.tar.bz2<br />
</code></p>
<p>The first couple are out of sequence due to testing. But the last 3 are genuine. So far so good, but I hope I never need any of them.</p>
<div id="in_post_ad_bottom_1" style="clear:both;margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "pub-7462076129993234";
/* 468x60, created 9/9/09 */
google_ad_slot = "5795392629";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div><div style='clear:both'></div>]]></content:encoded>
			<wfw:commentRss>http://www.dining-philosopher.com/2009/09/07/a-simple-backup-script-for-linux/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
