<?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>edsalisbury.net &#187; mirroring</title>
	<atom:link href="http://edsalisbury.net/tag/mirroring/feed/" rel="self" type="application/rss+xml" />
	<link>http://edsalisbury.net</link>
	<description>your guide to user-friendly entertainment</description>
	<lastBuildDate>Wed, 28 Mar 2012 02:07:28 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Asynchronous Mirroring in Unix</title>
		<link>http://edsalisbury.net/asynchronous-mirroring-in-unix/</link>
		<comments>http://edsalisbury.net/asynchronous-mirroring-in-unix/#comments</comments>
		<pubDate>Mon, 06 Jul 2009 14:00:11 +0000</pubDate>
		<dc:creator>Ed</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[data]]></category>
		<category><![CDATA[mirroring]]></category>
		<category><![CDATA[Unix]]></category>

		<guid isPermaLink="false">http://www.edsalisbury.net/?p=306</guid>
		<description><![CDATA[<a href="http://edsalisbury.net/asynchronous-mirroring-in-unix/" title="Asynchronous Mirroring in Unix"></a>One of the issues I&#8217;ve found with having lots of data is the fact that I&#8217;m worried that a hard drive will fail, and I&#8217;ll lose something important. Since I did have that happen earlier this year, I am now &#8230;<p class="read-more"><a href="http://edsalisbury.net/asynchronous-mirroring-in-unix/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://edsalisbury.net/asynchronous-mirroring-in-unix/" title="Asynchronous Mirroring in Unix"></a><p><img src="http://www.edsalisbury.net/wp-content/uploads/2009/07/unix-150x150.jpg" alt="Un*x" title="Un*x" width="150" height="150" class="alignleft size-thumbnail wp-image-308" /><br />
One of the issues I&#8217;ve found with having lots of data is the fact that I&#8217;m worried that a hard drive will fail, and I&#8217;ll lose something important.  Since I did have that happen earlier this year, I am now determined to not let it happen again.  I&#8217;ve been focusing a lot on resiliency &#8211; making it so that there are no single points of failure.  Since I have been collecting a lot of hard drives, I decided to put them to good use, and set up some data replication onto multiple drives.</p>
<p>You might ask, why not just set up a RAID5?  Or, alternatively, why not buy a Drobo and be done with it?  I hear the first one a lot, especially since I deal with RAID day in and day out for my day job.  The main issue I don&#8217;t do either of these things is that I&#8217;m cheap!  I want to be able to use all of the hardware I have without tossing out old stuff.  On my server, I have the following drives:</p>
<p><span id="more-306"></span></p>
<ul>
<li>disk1: 120 GB ATA</li>
<li>disk2: 200 GB ATA</li>
<li>disk3: 300 GB USB</li>
<li>disk4: 400 GB Firewire</li>
<li>disk5: 600 GB SATA</li>
<li>disk6: 1000 GB USB</li>
<li>disk7: 1500 GB USB</li>
</ul>
<p>Try to set up a RAID with all of that!  The problem with this is the disparate drive sizes (RAID requires disks to be the same size, and will use the lowest common denominator if not.)  I&#8217;ve been &#8216;collecting&#8217; hard drives for quite a while, and I like the fact that I can just go to the local electronics store and pick up another drive when I run out of space.  This configuration does have a downside though, and that is, how do you decide where to put everything?  I decided to sit down and figure out how much space I actually need for each of my data types, and came up with this list (taking approximate growth rates into consideration):</p>
<ul>
<li>Photos: 100 GB</li>
<li>Music: 300 GB</li>
<li>Movies: 1 TB</li>
<li>TV: 400 GB</li>
<li>Software: 150 GB</li>
</ul>
<p>I then tried to map things out onto the drives I have:</p>
<ul>
<li>disk1: Photos</li>
<li>disk2: Software</li>
<li>disk3: Music</li>
<li>disk4: TV</li>
<li>disk6: Movies</li>
</ul>
<p>This leaves two disks, disk5 (600 GB) and disk7 (1500 GB) left to be able to mirror to.  Since I can&#8217;t use standard mirroring software, I&#8217;m not able to have a real-time mirror.  This is OK for my purposes, as I don&#8217;t intend on having them be hot-swappable, etc. &#8212; I just want another copy of my data out there, without having to worry about making backups all the time.</p>
<p>I set up my server to only export the data disks (I don&#8217;t want to be able to write to the backups from my desktop, as the changes will be overwritten by the backups)  I also set up my filesystem in a convenient manner &#8212; everything is a directory off of /data:</p>
<ul>
<li>/data/Photos</li>
<li>/data/Video</li>
<li>/data/Software</li>
<li>/data/Audio</li>
</ul>
<p>This makes it very easy to get to any of my data  (try that in Windows!)</p>
<p>One inherent advantage of having an asynchronous mirror is the fact that it can serve as a temporary backup if you accidentally delete a file/directory, whereas with a normal mirror, you&#8217;d still have to back up to tape or some other drive to be able to get this data back.</p>
<p>To do the actual mirroring, I opted to create a simple rsync script that will copy the data nightly from cron.  Nothing overly complex, but something that makes it easy to add new filesystems via a config file:</p>
<pre class="brush:perl; gutter: false; wrap-lines: true; ruler: false">
#!/usr/bin/perl
# Mirror
# Asynchronously mirror filesystems on a local machine
# by Ed Salisbury (ed@edsalisbury.net)
# http://www.edsalisbury.net
# (c)2009 Ed Salisbury, Some Rights Reserved
#
# External Utilities Required:
# * rsync
#
# License:
# Except where otherwise noted, this work is licensed under Creative Commons
#   Attribution ShareAlike 3.0.
#
# You are free:
#   * to Share — to copy, distribute and transmit the work
#   * to Remix — to adapt the work
#
# Under the following conditions:
#   * Attribution. You must attribute the work in the manner specified by the
#     author or licensor (but not in any way that suggests that they endorse
#     you or your use of the work).
#   * Share Alike. If you alter, transform, or build upon this work, you may
#     distribute the resulting work only under the same, similar or a
#     compatible license.
#   * For any reuse or distribution, you must make clear to others the license
#     terms of this work. The best way to do this is with a link to the
#     license's web page (http://creativecommons.org/licenses/by-sa/3.0/)
#   * Any of the above conditions can be waived if you get permission from the
#     copyright holder.
#   * Nothing in this license impairs or restricts the author's moral rights.

use warnings;
use strict;

# Configuration file for mirrors
# Example Config:
# /data/Photos/       /backup/Backup/Photos/
# /data/Software/     /backup/Backup/Software/
# /data/Audio/        /backup/Backup/Audio/
# /data/Video/        /backup/Backup/Video/
# /data/Misc/         /backup/Backup/Misc/
my $CONFIG = "/usr/local/etc/mirror.cfg";

open(CFG, $CONFIG);
my @lines = &lt;CFG&gt;;
close(CFG);

foreach my $line (@lines)
{
    my ($src, $dest) = split(/s+/, $line);
    system("/usr/bin/rsync -av --delete $src $dest");
}
</pre>
<p>I put this script into /usr/local/bin, and then created a config file /usr/local/etc/mirror.conf similar to this:</p>
<pre>
/data/Photos/       /backup/Backup/Photos/
/data/Software/     /backup/Backup/Software/
/data/Audio/        /backup/Backup/Audio/
/data/Video/        /backup/Backup/Video/
/data/Misc/         /backup/Backup/Misc/
</pre>
<p>I then added a cronjob to have it run nightly:</p>
<pre>0 0 * * * /bin/backup > /dev/null 2>&#038;1</pre>
<p><strong><br />
A word of caution: Make *sure* you have the directories right!  rsync is set up to *DELETE* files in the destination if the file isn&#8217;t in the source directory, so if you have it rsync to two different directories, it will delete files as needed in the destination to sync them up.  You have been warned!  I take no responsibility for you deleting your data!</strong></p>
<p>Please let me know if you found this guide/script useful.</p>
]]></content:encoded>
			<wfw:commentRss>http://edsalisbury.net/asynchronous-mirroring-in-unix/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>How To Set Up a Two-Way Mirror Between Mac OS X and Ubuntu Linux</title>
		<link>http://edsalisbury.net/how-to-set-up-a-two-way-mirror-between-mac-os-x-and-ubuntu-linux/</link>
		<comments>http://edsalisbury.net/how-to-set-up-a-two-way-mirror-between-mac-os-x-and-ubuntu-linux/#comments</comments>
		<pubDate>Sun, 07 Jun 2009 23:11:48 +0000</pubDate>
		<dc:creator>Ed</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[macosx]]></category>
		<category><![CDATA[mirroring]]></category>
		<category><![CDATA[unison]]></category>

		<guid isPermaLink="false">http://www.edsalisbury.net/?p=58</guid>
		<description><![CDATA[<a href="http://edsalisbury.net/how-to-set-up-a-two-way-mirror-between-mac-os-x-and-ubuntu-linux/" title="How To Set Up a Two-Way Mirror Between Mac OS X and Ubuntu Linux"></a>After my hard drive crash a few months ago, I&#8217;ve been a bit paranoid about losing data.   By &#8220;a bit&#8221; I mean I&#8217;ve been sticking copies of my data on different machines to make sure I have various copies in &#8230;<p class="read-more"><a href="http://edsalisbury.net/how-to-set-up-a-two-way-mirror-between-mac-os-x-and-ubuntu-linux/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://edsalisbury.net/how-to-set-up-a-two-way-mirror-between-mac-os-x-and-ubuntu-linux/" title="How To Set Up a Two-Way Mirror Between Mac OS X and Ubuntu Linux"></a><p><a href="http://www.flickr.com/photos/aloshbennett/3237417064/"><img class="alignleft size-thumbnail wp-image-82" title="Mirror to the Sky" src="http://www.edsalisbury.net/wp-content/uploads/2009/06/aloshbennett-mirror-to-the-sky-150x150.jpg" alt="Mirror to the Sky (aloshbennet CC)" width="150" height="150" /></a>After my hard drive crash a few months ago, I&#8217;ve been a bit paranoid about losing data.   By &#8220;a bit&#8221; I mean I&#8217;ve been sticking copies of my data on different machines to make sure I have various copies in case another hard drive dies, or a computer gets fried, melting everything inside, or my house burns down&#8230; Oh wait, I don&#8217;t have that scenario covered&#8230;.  Time to fix that!  What I want is the ability to copy my data to an offsite location, and keep the backup up to date.  The main thing I care about is my family photos.   I was talking to my cousin Dave, and he had the same issue.  He wanted access to my photos, as well as have an offsite backup copy of his family&#8217;s photos.  I thought of a solution.  What if we could set up a two-way mirror between his machine and mine, and keep it updated nightly?  That way if he sticks something in the directory on his machine and vice versa, keeping a live backup.  I began doing some research, and I found the tool &#8212; <a href="http://www.cis.upenn.edu/~bcpierce/unison/">Unison</a>.</p>
<p><span id="more-58"></span></p>
<p>One slight wrinkle is the fact that he runs Mac OS X and I run Ubuntu Linux.  Unison will run on both, so it should be fine.</p>
<p>A couple of things to consider:</p>
<p>Mirroring over the internet is <strong>SLOW</strong> &#8212; if you want to keep a large quantity of files mirrored, it&#8217;s best to &#8220;seed&#8221; the mirror by doing a local copy to the drive.  Dave sent me his hard drive via snailmail, so this worked out.</p>
<p>This process will involve poking holes in your firewall, and setting up SSH keys with no password.  These are security risks (which can be minimized).  You have been warned.</p>
<p>To make things easy, I&#8217;ll specify the hostnames:</p>
<p><strong>Mac Host: eve</strong></p>
<p><strong>Linux Host: twiki</strong></p>
<p>One thing needs to be decided before we go on is which host will be initiating the transfer.   You can initiate from both sides, but to make it easy, I&#8217;ll just be initiating from my computer, twiki.</p>
<p>The first step is to verify connectivity between the two machines.  Since I&#8217;m initiating the transfer, I&#8217;ll be adding a hosts entry for eve.  I first have Dave go to <a href="http://www.whatismyip.com">www.whatismyip.com</a> and have him tell me his IP address.  I put this into /etc/hosts on my machine:</p>
<pre>&lt;hismachinesipaddress&gt;        eve</pre>
<p>I try to first ping the address.  Most likely it will fail.  Dave will need to poke a hole in the firewall (set up port forwarding) &#8211; How to do this is outside the scope of this article, but <a href="http://portforward.com">www.portforward.com</a> has a lot of info on how to do this.  Dave forwards port 22 (SSH) to his local IP address and saves settings.</p>
<p>Ping still doesn&#8217;t work, but SSH should.  I try sshing to the box, and voila, I get a password prompt.</p>
<p>The next step is to have Dave create an account for me.  To make it easy, I have him call it &#8220;ed&#8221; (same as on twiki)</p>
<p>After my account has been created, I&#8217;m able to login via ssh.  The next step is to set up an SSH key to make it so that I can ssh in without having to give a password.  On twiki, I run:</p>
<pre>twiki% ssh-keygen -t dsa -f ~/.ssh/unison</pre>
<p>(Press enter when it asks for a passphrase)</p>
<p>Add the contents of ~/.ssh/unison.pub to ~/.ssh/authorized_keys2 on eve.  Make sure it&#8217;s all on one line (no linebreaks)</p>
<p>To test it out, I ssh from twiki to eve, specifying the unison key:</p>
<pre>twiki% ssh -i ~/.ssh/unison eve</pre>
<p>It shouldn&#8217;t ask me for a password, so I&#8217;m good to go for this step.  If it does, make sure the permissions on the files in ~/.ssh are set to 600.</p>
<p>Next, we&#8217;ll install Unison on both machines:</p>
<p><strong>On Eve:</strong></p>
<ul>
<li>Get and install <a href="http://darwinports.com/download/">MacPorts</a></li>
<li>Use MacPorts to install Unison:</li>
</ul>
<pre>eve% sudo /opt/local/bin/port install unison
---&gt;  Fetching ocaml
---&gt;  Attempting to fetch ocaml-3.11.0.tar.bz2 from http://distfiles.macports.org/ocaml
---&gt;  Verifying checksum(s) for ocaml
---&gt;  Extracting ocaml
---&gt;  Configuring ocaml
---&gt;  Building ocaml
---&gt;  Staging ocaml into destroot
---&gt;  Installing ocaml @3.11.0_0
---&gt;  Activating ocaml @3.11.0_0
---&gt;  Cleaning ocaml
---&gt;  Fetching unison
---&gt;  Attempting to fetch unison-2.27.57.tar.gz from http://distfiles.macports.org/unison
---&gt;  Verifying checksum(s) for unison
---&gt;  Extracting unison
---&gt;  Applying patches to unison
---&gt;  Configuring unison
---&gt;  Building unison
---&gt;  Staging unison into destroot
---&gt;  Installing unison @2.27.57_0
---&gt;  Activating unison @2.27.57_0
---&gt;  Cleaning unison</pre>
<p><strong>On Twiki:</strong></p>
<pre>twiki% sudo apt-get install unison
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
unison
0 upgraded, 1 newly installed, 0 to remove and 11 not upgraded.
Need to get 0B/529kB of archives.
After this operation, 1262kB of additional disk space will be used.
(Reading database ... 150151 files and directories currently installed.)
Unpacking unison (from .../unison_2.27.57-1ubuntu1_i386.deb) ...
Processing triggers for man-db ...
Processing triggers for doc-base ...
Processing 1 added doc-base file(s)...
Registering documents with scrollkeeper...
Setting up unison (2.27.57-1ubuntu1) ...</pre>
<p>Next, set up the profile on twiki:</p>
<pre>twiki% mkdir ~/.unison
twiki% vi ~/.unison/default.prf</pre>
<p>Put the following into default.prf (changing as appropriate):</p>
<pre>root = /data/EdsPhotos
root = ssh://eve//DavesPhotos
rshargs = -C
sshargs = -i /home/ed/.ssh/unison
servercmd = /opt/local/bin/unison
ignore = Name _*
ignore = Name .*
batch = true
log = true</pre>
<p>For security purposes, add the following to ~/.ssh/authorized_keys2 on eve.  This will only allow this ssh key to be used to run unison:</p>
<pre>command="/opt/local/bin/unison",no-port-forwarding,no-X11-forwarding,no-agent-forwarding</pre>
<p>On twiki, run unison:</p>
<pre>twiki% unison</pre>
<p>It will spit out a lot of data, but should start scanning and eventually copying data back and forth, depending on how much data there is.   In order to run nightly, add the following to your crontab on twiki:</p>
<pre>0 0 * * * nohup /usr/local/bin/unison &gt; /dev/null 2&gt;&amp;1</pre>
<p>That should be it.  Any feedback would be appreciated.</p>
]]></content:encoded>
			<wfw:commentRss>http://edsalisbury.net/how-to-set-up-a-two-way-mirror-between-mac-os-x-and-ubuntu-linux/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

