<?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>Dot Boston &#187; unix</title>
	<atom:link href="http://adamp.com/tag/unix/feed/" rel="self" type="application/rss+xml" />
	<link>http://adamp.com</link>
	<description>Apple, Bicycles, Boston, Dot and Web Media</description>
	<lastBuildDate>Mon, 25 Oct 2010 02:57:58 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
<cloud domain='adamp.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
		<item>
		<title>Lessons Learned from an Accidental rm -rf *</title>
		<link>http://adamp.com/apple/lessons-learned-from-an-accidental-rm-rf/</link>
		<comments>http://adamp.com/apple/lessons-learned-from-an-accidental-rm-rf/#comments</comments>
		<pubDate>Sun, 14 Feb 2010 03:13:20 +0000</pubDate>
		<dc:creator>Adam</dc:creator>
				<category><![CDATA[Apple]]></category>
		<category><![CDATA[backups]]></category>
		<category><![CDATA[mac os x]]></category>
		<category><![CDATA[recovery]]></category>
		<category><![CDATA[rm -rf*]]></category>
		<category><![CDATA[terminal]]></category>
		<category><![CDATA[unix]]></category>

		<guid isPermaLink="false">http://adamp.wp42.com/?p=2736</guid>
		<description><![CDATA[One of the main principles that&#8217;s been hammered into me from lectures and experience over my 15+ years of computing is backup, backup, backup. It becomes even more crucial when you start hosting sites, especially sites for other people. On all the servers we run, we backup site and database files nightly, with automated syncs [...]]]></description>
			<content:encoded><![CDATA[<p>One of the main principles that&#8217;s been hammered into me from lectures and experience over my 15+ years of computing is backup, backup, backup. It becomes even more crucial when you start hosting sites, especially sites for other people. On all the <a href="http://www.the42ndestate.com/">servers we run</a>, we backup site and database files nightly, with automated syncs offsite to other servers/the cloud <em>and</em> to my laptop.</p>
<p>Every few days, I hook up one of my external hard drives and transfer over the offsite backups so they&#8217;re not cluttering up my working space.</p>
<h2>The Bleepin&#8217; Leadin&#8217; Asterik</h2>
<p>Yesterday was one of those days. After syncing my laptop&#8217;s backup folder to my external backup folder (via rsync), I wanted to drop the files from my laptop. Already being on the command line and knowing I wanted to drop everything inside my local offsite backups folder, I naturally ran this command:</p>
<pre>
rm -rf * /Users/Adam/offsitebackups/*
</pre>
<p>Usually this cleanup runs in under ten seconds, since it only contains a few days worth of backups.</p>
<p>After fifteen seconds I started wondering what was going on. After twenty seconds, I noticed the leading asterik and started pounding on
<pre>control+c</pre>
<p> as fast as humanly possible.</p>
<p>After swearing very loudly, I ran:</p>
<pre>
pwd
</pre>
<p>to show me my working directory:</p>
<pre>
/Users/Adam
</pre>
<p>flashed on the screen and again I swore very loudly. To anyone not familiar with Unix, here&#8217;s a quick introduction. The <code>rm</code> command stands for remove. the <code>-rf</code> after <code>rm</code> stands for &#8220;recursive&#8221; and &#8220;force&#8221; and the <code>*</code> stands for &#8220;all&#8221;. In short, I issued a command from my home folder that would go through and delete any files, folders, and sub-directories inside that folder. Since I keep almost all of my files inside /Users/Adam, you can understand the frustration.</p>
<p>My next step was crucial and brings us to our first lesson.</p>
<h2>Don&#8217;t Panic!</h2>
<p>After realizing what I did, I walked away from my computer. If I had remained at the console, I probably would have furiously done some things that may or may not have made the situation worse. The damage had already been done so my next step was to calm down. After pouring myself a glass of water, I returned to the computer with a calm, clear mind ready to rationally recover as much as possible.</p>
<h2>Internet Syncing is Wonderfully Convenient&#8230;</h2>
<p>After sitting back down, I stared at the screen blankly for a few moments. Knowing that I periodically run Time Machine and that the damage had been contained to /Users/Adam gave me some relief, since at worst I would have to rebuild my home directory from a recent backup. But at least the core system would be intact.</p>
<p>Also knowing I sync some of my files with Dropbox and run version control on the important sites, left me with some peace of mind. With services like <a href="https://www.getdropbox.com/referrals/NTc5MTgwNzk">Dropbox</a> and Subversion getting easier and easier to install and run, there&#8217;s really no excuse for not having wonderfully convenient backups of your important stuff up on the internet or your local network.</p>
<h2>&#8230; and Deceptively Dangerous</h2>
<p>Then I noticed <a href="http://spanningsync.com/">Spanning Syn</a>c spinning up. Unsure if my local Address Book files were intact, I immediately shut off my wireless connection and yanked out my ethernet cord. No need to start updating my cloud files and deleting what shouldn&#8217;t be deleted. Of course Spanning Sync would ask me before syncing up the deleted entries, but without knowing off the top of my head what else might be planning a sync at any moment, I felt turning off access to the internet was the best way to ensure the damage stayed localized.</p>
<p>I also shut down Time Machine, since there was no need to run a massive backup to save my newly shrunken down system.</p>
<h2>Get a Base Reading</h2>
<p>After regaining my composure and severing my laptop&#8217;s connection to the network and other devices, it was time to start checking what was gone. </p>
<p>My first instinct was to:</p>
<pre>ls -la</pre>
<p>which would show me all the files in /Users/Adam and provide a timestamp of the last modification date.</p>
<p>A sigh of relief at this point, as I noticed most of the structure was still intact and untouched. The only folder with a recent modification date was my Desktop. I have a very particular organization for my Desktop, which means I only keep two folders on the desktop.</p>
<ul>
<li>Projects</li>
<p>My projects folder contains anything I&#8217;m currently working on. For instance any graphic files or copy for sites is stored inside Projects. Needless to say, it&#8217;s a crucial folder.</p>
<li>Stuff</li>
<p>A catch all folder for anything else. I like to keep my desktop nice and tidy so anytime I go on a downloading spree or have random files cluttering up my desktop that don&#8217;t relate to any of the projects I&#8217;m working on, they get dropped into Stuff. Not as crucial as Projects, but because the nature of this folder means I really have no clue what was or wasn&#8217;t in here, I was hoping it wasn&#8217;t too badly damaged.</p>
</ul>
<p>Well, a quick glance at my actual desktop showed me that Projects was completely gone. </p>
<p>At least I had double backups of the Projects folder to Time Machine and to Dropbox, but unfortunately both were a bit out of date.</p>
<h2>Keep Timely Updates</h2>
<p>For some reason, I&#8217;d shut down Dropbox at some point. Now, I let it start when my computer starts and leave it running at all times. This way, when I make changes to the Projects folder or any other folder synced to Dropbox, it gets updated automagically. All you have to do to get the same auto-magic is link the folder with dropbox.</p>
<pre>ln -s ~/Desktop/Projects ~/Dropbox/Projects</pre>
<p>That little trick will make sure there&#8217;s always a recent backup. Since Dropbox takes a little time to sync up, it might&#8217;ve started deleting some files but at least it&#8217;s another backup. The other key to keeping timely backups is to let Time Machine run off the network, rather than a hard drive I have to remember to plug in every few days.</p>
<h2>Script it!</h2>
<p>Finally, the biggest and most important lesson is to take human error out of the equation. Now, instead of manually moving files over to my external, I&#8217;ve set up a script to automatically sync them over and then clean up the laptop hard drive after its done. It&#8217;s one of those things I should&#8217;ve done a while ago but kept putting off. Foolish indeed as scripting it the first time would&#8217;ve saved me time and files.</p>
<p><span class="postfootnote">Photo credit: <a href="http://www.flickr.com/photos/drmillerlg/3294341985/"> Larry Miller</a> | <a href="http://creativecommons.org/licenses/by-nc-nd/2.0/deed.en">CC-NC-ND 2.0</a></span></p>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://adamp.com/technology/clickclickclick-how-a-virtual-kubuntu-penguin-saved-my-50gb-music-collection/" rel="bookmark" class="crp_title">Click&#8230;Click&#8230;Click: How a Virtual (K)Ubuntu Penguin Saved My 50GB Music Collection</a></li><li><a href="http://adamp.com/technology/itunes-lastfm/" rel="bookmark" class="crp_title">Start iTunes &#038; Last.fm Simultaneously</a></li><li><a href="http://adamp.com/apple/45-free-applications-for-your-new-mac/" rel="bookmark" class="crp_title">45 Free Applications for Your New Mac</a></li><li><a href="http://adamp.com/technology/tweetdeck-on-the-iphone/" rel="bookmark" class="crp_title">Tweetdeck on the iPhone</a></li><li><a href="http://adamp.com/boston/is-it-boston/" rel="bookmark" class="crp_title">Is It Boston?</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://adamp.com/apple/lessons-learned-from-an-accidental-rm-rf/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk
Page Caching using disk (enhanced)
Database Caching using disk
Object Caching 378/442 objects using disk
Content Delivery Network via cdn.adamp.com

Served from: adamp.com @ 2012-02-10 12:42:43 -->
