<?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>Musings of an Apple Systems Administrator &#187; backup</title>
	<atom:link href="http://www.jonsblog.org/tag/backup/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.jonsblog.org</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Wed, 11 Jan 2012 19:33:26 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Backing up the OD Master</title>
		<link>http://www.jonsblog.org/2010/12/20/backing-up-the-od-master/</link>
		<comments>http://www.jonsblog.org/2010/12/20/backing-up-the-od-master/#comments</comments>
		<pubDate>Mon, 20 Dec 2010 14:43:27 +0000</pubDate>
		<dc:creator>Jon Brown</dc:creator>
				<category><![CDATA[OSX Server Configuration]]></category>
		<category><![CDATA[backup]]></category>
		<category><![CDATA[ldap]]></category>

		<guid isPermaLink="false">http://www.jonsblog.org/?p=216</guid>
		<description><![CDATA[Open directory on the Mac OSX Server platform is a great directory platform using Kerberos and LDAP however I have found that there are two steps to a flawless directory experience. Since the directory is such a delicate system I find it necessary to create a backup of the OD Master at least once a [...]]]></description>
			<content:encoded><![CDATA[<p>Open directory on the Mac OSX Server platform is a great directory platform using Kerberos and LDAP however I have found that there are two steps to a flawless directory experience. Since the directory is such a delicate system I find it necessary to create a backup of the OD Master at least once a day in the event that something goes south you can restore from any day in the past with ease. The other method is to use OD Replicas, and to use them often. A replica is far easier to fix than the actual OD Master if the master goes bad, and you have no backup then you have to decommission and start over, with replicas you can demote, and recreate without even having to deal with the OD Master.</p>
<p><strong>1. Backing up the OD Master with Bash</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/sh</span>
&nbsp;
<span style="color: #007800;">NOW</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">date</span> +<span style="color: #ff0000;">&quot;%m-%d-%Y&quot;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Path to recovery directory (permissions should be 700 -- read-only root or admin)</span>
<span style="color: #007800;">recover</span>=<span style="color: #ff0000;">&quot;/Volumes/ODBackup&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Backup Open Directory</span>
<span style="color: #007800;">day</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">date</span> <span style="color: #ff0000;">''</span>+<span style="color: #000000; font-weight: bold;">%</span>u<span style="color: #ff0000;">''</span><span style="color: #000000; font-weight: bold;">`</span>
&nbsp;
<span style="color: #007800;">od_backup</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$recover</span>/od_backup - &quot;</span><span style="color: #007800;">$NOW</span><span style="color: #ff0000;">&quot;&quot;</span>
<span style="color: #007800;">ts</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">date</span> <span style="color: #ff0000;">''</span>+<span style="color: #000000; font-weight: bold;">%</span>F<span style="color: #ff0000;">''</span><span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;dirserv:backupArchiveParams:archivePassword = 908239032&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #007800;">$od_backup</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;dirserv:backupArchiveParams:archivePath = <span style="color: #007800;">$recover</span>/od_<span style="color: #007800;">$ts</span>&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$od_backup</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;dirserv:command = backupArchive&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$od_backup</span>
&nbsp;
serveradmin <span style="color: #7a0874; font-weight: bold;">command</span> <span style="color: #000000; font-weight: bold;">&lt;</span> <span style="color: #007800;">$od_backup</span></pre></div></div>

<p>The above script when run on a daily basis through CRON or LAUNCHD will create a recoverable sparse disk image of your OD Master that you can use to restore from, it saves each master with a date time stamp so you can see which one is which and the instructions to restore are logged to a separate file. The two variables you must change are<br />
<span id="more-216"></span></p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># Path to recovery directory (permissions should be 700 -- read-only root or admin)</span>
<span style="color: #007800;">recover</span>=<span style="color: #ff0000;">&quot;/Volumes/ODBackup&quot;</span></pre></div></div>

<p>This should be the location you want your OD Master backups to live, and</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;dirserv:backupArchiveParams:archivePassword = 908239032&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #007800;">$od_backup</span></pre></div></div>

<p>the password must be changed as well in the above example the password is 908239032 you can change it to anything you want, this is required to restore when you attempt to restore your OD Master backup in Server Admin you will be prompted for this password.</p>
<p><strong>2. Create an OD Master Replica</strong></p>
<p>Before you start the firewall on the OD Master, the Firewall on the OD Replica server and the Firewall on your router must all have the following ports open, and or port forwarded to their appropriate destination. Open Ports 389, 636, 625, 22, 3659, 106, and 88.</p>
<ol>
<li>
Make sure the master, the prospective replica, and every firewall between them is configured to permit SSH communications (port 22).<br />
You can enable SSH for Mac OS X Server in Server Admin. Select the server in the Servers list, click Settings, click General, then select the Remote Login (SSH) option.</p>
<p>Make sure that SSH access is not restricted to certain users or groups (using SACLs) on the prospective master. This will cause Server Admin to not have the necessary permissions during creation of the replica. You can temporarily disable SACLs in Server Admin under Settings > Access.
</li>
<li>Open Server Admin and connect to the server.</li>
<li>Click the triangle to the left of the server.<br />
The list of services appears.</li>
<li>From the expanded Servers list, select Open Directory.</li>
<li>Click Settings, then click General.</li>
<li>Click Change.<br />
The Service Configuration Assistant opens.</li>
<li>Choose Open Directory Replica, then click Continue.</li>
<li>Enter the following requested information:</li>
<ul>
<li>IP address or DNS name of Open Directory master:  Enter the IP address or DNS name of the server that is the Open Directory master.</li>
<li>Root password on Open Directory master:  Enter the password of the Open Directory master system’s root user (user name system administrator).</li>
<li>Domain administrator’s short name:  Enter the name of an LDAP directory domain administrator account.</li>
<li>Domain administrator’s password:  Enter the password of the administrator account whose name you entered.</li>
</ul>
<li>Click Continue.</li>
<li>Confirm the Open Directory configuration settings, then click Continue.</li>
<li>Click Close.</li>
<li>Make sure the date, time, and time zone are correct on the replica and the master.<br />
The replica and the master should use the same network time service so their clocks remain in sync.</li>
</ol>
<p>Again the point here is to have a place for your users to authenticate against that can easily be fixed if any issues arise, in my setup I use the replicas to bind clients to for computer authentication, bind my Mail server to for account information and also use it as the basis for my LDAP environment. Replicas are great because they also reduce the response time, and since each server is synced as the users change their passwords or information its virtually instant. If a client is bound to my replica and the replica has a problem it will search for the next nearest replica, connect and authenticate against that which means almost no downtime as well.</p>
<p><strong>3. Carbon Copy Cloner</strong><br />
I am a huge fan of this software which can be found at <a href="http://www.bombich.com/">Carbon Copy Cloners website</a>. I use this software to do a full, incremental clone of my server, which is great because at any given time I can boot off of the backup drive and or restore directly to my server. </p>
<p>I am not going to write another how to on using Carbon Copy Cloner except to link to their own how to section which goes over it in so much more detail than I could here.</p>
<p><a href="http://help.bombich.com/kb/scheduling/save-task">Scheduling Tasks in Carbon Copy Cloner >></a><br />
<a href="http://help.bombich.com/kb/explore/backup-options">Backup Options for Carbon Copy Cloner >></a><br />
<a href="http://help.bombich.com/kb/explore/backup">A more granular approach to Backup (Must Read!!!) >></a></p>
<p>If you find their software useful I urge you to donate. </p>
<p>Wrapping things up a bit, I am a big fan of backups and these three options will keep you covered in the event of an Open Directory nightmare! If you have comments or other solutions I am always happy to hear from you and let me know how you approach backups with your systems!</p>
<p><b>** Note</b><br />
I was not able to get the above script to run properly with Cron, but it does however with LaunchD. Here is my LaunchD script, I named it com.odbackup.plist and placed it in the /Library/LaunchDaemons/ folder on my server, the script is set to run the backup every morning at 7:45am</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;</span>?xml <span style="color: #007800;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #007800;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span>?<span style="color: #000000; font-weight: bold;">&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;!</span>DOCTYPE plist PUBLIC -<span style="color: #000000; font-weight: bold;">//</span>Apple Computer<span style="color: #000000; font-weight: bold;">//</span>DTD PLIST <span style="color: #000000;">1.0</span><span style="color: #000000; font-weight: bold;">//</span>EN http:<span style="color: #000000; font-weight: bold;">//</span>www.apple.com<span style="color: #000000; font-weight: bold;">/</span>DTDs<span style="color: #000000; font-weight: bold;">/</span>PropertyList-<span style="color: #000000;">1.0</span>.dtd <span style="color: #000000; font-weight: bold;">&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;</span>plist <span style="color: #007800;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span>
    <span style="color: #000000; font-weight: bold;">&lt;</span>dict<span style="color: #000000; font-weight: bold;">&gt;</span>
        <span style="color: #000000; font-weight: bold;">&lt;</span>key<span style="color: #000000; font-weight: bold;">&gt;</span>Label<span style="color: #000000; font-weight: bold;">&lt;/</span>key<span style="color: #000000; font-weight: bold;">&gt;</span>
        <span style="color: #000000; font-weight: bold;">&lt;</span>string<span style="color: #000000; font-weight: bold;">&gt;</span>com.odbackup<span style="color: #000000; font-weight: bold;">&lt;/</span>string<span style="color: #000000; font-weight: bold;">&gt;</span>
        <span style="color: #000000; font-weight: bold;">&lt;</span>key<span style="color: #000000; font-weight: bold;">&gt;</span>ProgramArguments<span style="color: #000000; font-weight: bold;">&lt;/</span>key<span style="color: #000000; font-weight: bold;">&gt;</span>
	<span style="color: #000000; font-weight: bold;">&lt;</span>array<span style="color: #000000; font-weight: bold;">&gt;</span>
	<span style="color: #000000; font-weight: bold;">&lt;</span>string<span style="color: #000000; font-weight: bold;">&gt;/</span>bin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">sh</span><span style="color: #000000; font-weight: bold;">&lt;/</span>string<span style="color: #000000; font-weight: bold;">&gt;</span> 
        <span style="color: #000000; font-weight: bold;">&lt;</span>string<span style="color: #000000; font-weight: bold;">&gt;/</span>path<span style="color: #000000; font-weight: bold;">/</span>to<span style="color: #000000; font-weight: bold;">/</span>backup<span style="color: #000000; font-weight: bold;">/</span>script<span style="color: #000000; font-weight: bold;">/</span>backup.sh<span style="color: #000000; font-weight: bold;">&lt;/</span>string<span style="color: #000000; font-weight: bold;">&gt;</span>
        <span style="color: #000000; font-weight: bold;">&lt;/</span>array<span style="color: #000000; font-weight: bold;">&gt;</span>
        <span style="color: #000000; font-weight: bold;">&lt;</span>key<span style="color: #000000; font-weight: bold;">&gt;</span>StartCalendarInterval<span style="color: #000000; font-weight: bold;">&lt;/</span>key<span style="color: #000000; font-weight: bold;">&gt;</span>
        <span style="color: #000000; font-weight: bold;">&lt;</span>dict<span style="color: #000000; font-weight: bold;">&gt;</span>
            <span style="color: #000000; font-weight: bold;">&lt;</span>key<span style="color: #000000; font-weight: bold;">&gt;</span>Hour<span style="color: #000000; font-weight: bold;">&lt;/</span>key<span style="color: #000000; font-weight: bold;">&gt;</span>
            <span style="color: #000000; font-weight: bold;">&lt;</span>integer<span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000;">7</span><span style="color: #000000; font-weight: bold;">&lt;/</span>integer<span style="color: #000000; font-weight: bold;">&gt;</span>
            <span style="color: #000000; font-weight: bold;">&lt;</span>key<span style="color: #000000; font-weight: bold;">&gt;</span>Minute<span style="color: #000000; font-weight: bold;">&lt;/</span>key<span style="color: #000000; font-weight: bold;">&gt;</span>
            <span style="color: #000000; font-weight: bold;">&lt;</span>integer<span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000;">45</span><span style="color: #000000; font-weight: bold;">&lt;/</span>integer<span style="color: #000000; font-weight: bold;">&gt;</span>
        <span style="color: #000000; font-weight: bold;">&lt;/</span>dict<span style="color: #000000; font-weight: bold;">&gt;</span>
    <span style="color: #000000; font-weight: bold;">&lt;/</span>dict<span style="color: #000000; font-weight: bold;">&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;/</span>plist<span style="color: #000000; font-weight: bold;">&gt;</span></pre></div></div>

<p>then you start the proceess by running load ctl /Library/LaunchDaemons/com.odbackup.plist or whatever you named it to see if its in the list run launchctl list.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jonsblog.org/2010/12/20/backing-up-the-od-master/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>III Syncing a failover website : Scheduling the sync</title>
		<link>http://www.jonsblog.org/2010/05/31/iii-syncing-a-failover-website-scheduling-the-sync/</link>
		<comments>http://www.jonsblog.org/2010/05/31/iii-syncing-a-failover-website-scheduling-the-sync/#comments</comments>
		<pubDate>Mon, 31 May 2010 22:29:23 +0000</pubDate>
		<dc:creator>Jon Brown</dc:creator>
				<category><![CDATA[OSX System Administration]]></category>
		<category><![CDATA[backup]]></category>
		<category><![CDATA[cronjob]]></category>
		<category><![CDATA[schedule]]></category>

		<guid isPermaLink="false">http://www.jonsblog.org/?p=147</guid>
		<description><![CDATA[So now we have our backup script, we have our secure SSH tunnel between the two servers and we have successfully synced our two databases and our files. Now we just have to schedule this task so that we do not have to manually run this each time we need to synchronize our systems. On [...]]]></description>
			<content:encoded><![CDATA[<p>So now we have our backup script, we have our secure SSH tunnel between the two servers and we have successfully synced our two databases and our files. Now we just have to schedule this task so that we do not have to manually run this each time we need to synchronize our systems. On Mac OSX Servers you have two options you can use Crontab and run a Cronjob, or you can use Launchd. If your running a Linux server then your pretty limited to just a Cronjob. We will talk about both types of scheduling methods and which one makes the best sense for your setup. </p>
<p>Crontab is one of the longest lasting scheduling daemons around, its part of any linux / unix system and uses a file that will trigger a script at a specific time at specific intervals. Cron can be pretty amazing but pretty daunting too if you are unsure about how to use cron, I recommend starting out easy and using this GUI for Mac OSX called <a href="http://code.google.com/p/cronnix/">Cronnix</a>.</p>
<p><a href="http://code.google.com/p/cronnix/">Cronnix</a> is a great tool because it lets you modify, save and create crontab cronjobs in a very easy to use interface. Before <a href="http://code.google.com/p/cronnix/">Cronnix</a> you basically had to use the VI editor in order to edit the crontab file manually which did not always prove successful. Once your ready to make your first schedule then you need to know what time or at what intervals you want the backup to run. I had my backup script run at midnight every-night so my crontab looked like this.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000;">0</span> <span style="color: #000000;">0</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">bash</span> <span style="color: #000000; font-weight: bold;">/</span>path<span style="color: #000000; font-weight: bold;">/</span>to<span style="color: #000000; font-weight: bold;">/</span>my<span style="color: #000000; font-weight: bold;">/</span>sync<span style="color: #000000; font-weight: bold;">/</span>script.sh</pre></td></tr></table></div>

<p>Here are some other popular crontab examples that might give you some greater insight and understanding on the whole cronjob scheduling schema.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000;">0</span> <span style="color: #000000;">0</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">*</span>          <span style="color: #660033;">--</span> midnight every day
<span style="color: #000000;">0</span> <span style="color: #000000;">0</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000;">1</span>-<span style="color: #000000;">5</span>        <span style="color: #660033;">--</span> midnight every weekday
<span style="color: #000000;">0</span> <span style="color: #000000;">0</span> <span style="color: #000000;">1</span>,<span style="color: #000000;">15</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">*</span>       <span style="color: #660033;">--</span> midnight on 1st and 15th
                      of month
<span style="color: #000000;">0</span> <span style="color: #000000;">0</span> <span style="color: #000000;">1</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000;">5</span>          <span style="color: #660033;">--</span> midnight on 1st of month
                      and every Friday</pre></td></tr></table></div>

<p><span id="more-147"></span><br />
The second method for scheduling tasks on a Mac OSX Server platform is Launcd. This is the timer system that Apple has written and sanctioned as being the best way to schedule tasks, the reason is that unlike a cronjob where if you want to pause the job, you must remove it from the system entirely and then re-enter it when you want it to resume. With launchd you can unload / or load schedules to run at startup or on regularly scheduled intervals. I would be lying if I told you I was a launchd master, but I do like the advantages that launchd has to offer. </p>
<p>While getting my script up and running I used <a href="http://www.macresearch.org/tutorial_backups_with_launchd">This tutorial</a> to get me started. The launchd file below is what I used in order to get my backup scheduled. In order to install your launchd file place it in one of these locations.</p>
<p>/System/Library/LaunchDaemons (admin level system daemons)<br />
/System/Library/LaunchAgents (admin level user agents)</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;</span> ? xml <span style="color: #007800;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #007800;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span> ? <span style="color: #000000; font-weight: bold;">&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;!</span>DOCTYPE plist PUBLIC <span style="color: #ff0000;">&quot;-//Apple Computer//DTD PLIST 1.0//EN&quot;</span> \ <span style="color: #ff0000;">&quot;http://www.apple.com/DTDs/PropertyList-1.0.dtd&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;</span>dict<span style="color: #000000; font-weight: bold;">&gt;</span>
        <span style="color: #000000; font-weight: bold;">&lt;</span>key<span style="color: #000000; font-weight: bold;">&gt;</span>Label<span style="color: #000000; font-weight: bold;">&lt;/</span>key<span style="color: #000000; font-weight: bold;">&gt;</span>
        <span style="color: #000000; font-weight: bold;">&lt;</span>string<span style="color: #000000; font-weight: bold;">&gt;</span>com.macresearch.backup<span style="color: #000000; font-weight: bold;">&lt;/</span>string<span style="color: #000000; font-weight: bold;">&gt;</span>
        <span style="color: #000000; font-weight: bold;">&lt;</span>key<span style="color: #000000; font-weight: bold;">&gt;</span>LowPriorityIO<span style="color: #000000; font-weight: bold;">&lt;/</span>key<span style="color: #000000; font-weight: bold;">&gt;</span>
        <span style="color: #000000; font-weight: bold;">&lt;</span>true<span style="color: #000000; font-weight: bold;">/&gt;</span>
        <span style="color: #000000; font-weight: bold;">&lt;</span>key<span style="color: #000000; font-weight: bold;">&gt;</span>Program<span style="color: #000000; font-weight: bold;">&lt;/</span>key<span style="color: #000000; font-weight: bold;">&gt;</span>
        <span style="color: #000000; font-weight: bold;">&lt;</span>string<span style="color: #000000; font-weight: bold;">&gt;/</span>Users<span style="color: #000000; font-weight: bold;">/</span>gohara<span style="color: #000000; font-weight: bold;">/</span>Library<span style="color: #000000; font-weight: bold;">/</span>Scripts<span style="color: #000000; font-weight: bold;">/</span>backup.sh<span style="color: #000000; font-weight: bold;">&lt;/</span>string<span style="color: #000000; font-weight: bold;">&gt;</span>
        <span style="color: #000000; font-weight: bold;">&lt;</span>key<span style="color: #000000; font-weight: bold;">&gt;</span>ProgramArguments<span style="color: #000000; font-weight: bold;">&lt;/</span>key<span style="color: #000000; font-weight: bold;">&gt;</span>
        <span style="color: #000000; font-weight: bold;">&lt;</span>array<span style="color: #000000; font-weight: bold;">&gt;</span>
                <span style="color: #000000; font-weight: bold;">&lt;</span>string<span style="color: #000000; font-weight: bold;">&gt;</span>backup.sh<span style="color: #000000; font-weight: bold;">&lt;/</span>string<span style="color: #000000; font-weight: bold;">&gt;</span>
        <span style="color: #000000; font-weight: bold;">&lt;/</span>array<span style="color: #000000; font-weight: bold;">&gt;</span>
        <span style="color: #000000; font-weight: bold;">&lt;</span>key<span style="color: #000000; font-weight: bold;">&gt;</span>WatchPaths<span style="color: #000000; font-weight: bold;">&lt;/</span>key<span style="color: #000000; font-weight: bold;">&gt;</span>
        <span style="color: #000000; font-weight: bold;">&lt;</span>array<span style="color: #000000; font-weight: bold;">&gt;</span>
        <span style="color: #000000; font-weight: bold;">&lt;</span>string<span style="color: #000000; font-weight: bold;">&gt;/</span>Volumes<span style="color: #000000; font-weight: bold;">&lt;/</span>string<span style="color: #000000; font-weight: bold;">&gt;</span>
        <span style="color: #000000; font-weight: bold;">&lt;/</span>array<span style="color: #000000; font-weight: bold;">&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;/</span>dict<span style="color: #000000; font-weight: bold;">&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;/</span>plist<span style="color: #000000; font-weight: bold;">&gt;</span></pre></td></tr></table></div>

<p>Once you have your launchd file installed you must register the launchd file with your system by running</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;">  launchctl load ~<span style="color: #000000; font-weight: bold;">/</span>Library<span style="color: #000000; font-weight: bold;">/</span>LaunchAgents</pre></td></tr></table></div>

<p>Then issue</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"> launchctl list</pre></td></tr></table></div>

<p>Then you should see something like this</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">&#91;</span>Voyager:~<span style="color: #000000; font-weight: bold;">/</span>Library<span style="color: #000000; font-weight: bold;">/</span>Scripts<span style="color: #7a0874; font-weight: bold;">&#93;</span> gohara<span style="color: #000000; font-weight: bold;">%</span> launchctl list
com.macresearch.backup</pre></td></tr></table></div>

<p>for my sync script I chose to use a crontab, because my knowledge of launchd is limited and my experience with cronjobs is more extensive I found that adding a cronjob was faster, quicker and more efficient for permanent scheduled items on my servers. I would love to get your feedback however and learn more about launchd from you.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jonsblog.org/2010/05/31/iii-syncing-a-failover-website-scheduling-the-sync/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>II Syncing a failover website : The Sync script</title>
		<link>http://www.jonsblog.org/2010/05/22/syncing-a-failover-website-the-sync-script/</link>
		<comments>http://www.jonsblog.org/2010/05/22/syncing-a-failover-website-the-sync-script/#comments</comments>
		<pubDate>Sat, 22 May 2010 18:41:37 +0000</pubDate>
		<dc:creator>Jon Brown</dc:creator>
				<category><![CDATA[OSX System Administration]]></category>
		<category><![CDATA[backup]]></category>
		<category><![CDATA[bash script]]></category>
		<category><![CDATA[cronjob]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[schedule]]></category>
		<category><![CDATA[sync]]></category>

		<guid isPermaLink="false">http://www.jonsblog.org/?p=134</guid>
		<description><![CDATA[In this article we are picking up where we left off, we now have the ability to connect from our primary server to our secondary server without the need to enter a password with the help of a secret key. If you are lost at this point please refer to the last article Syncing a [...]]]></description>
			<content:encoded><![CDATA[<p>In this article we are picking up where we left off, we now have the ability to connect from our primary server to our secondary server without the need to enter a password with the help of a secret key. If you are lost at this point please refer to the last article <a href="http://www.jonsblog.org/2010/03/12/creating-an-ssh-key-for-secure-development">Syncing a failover website : Creating an SSH key</a>. At this point all we need to do is setup the bash script. We will create the script to log all of its activity so that we know if the process is having problems. The log file will be kept in a directory on the primary server. You will need to know the absolute path to this file and the file must be writable and readable by the system, so a chmod of 755 or 777 should do the trick.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> Sync started <span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">date</span><span style="color: #000000; font-weight: bold;">`</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>Volumes<span style="color: #000000; font-weight: bold;">/</span>Logs<span style="color: #000000; font-weight: bold;">/</span>Sync_log.txt
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Now starting rsync&quot;</span></pre></div></div>

<p>At this point we are ready for the sync to start, we will start by syncing the files from the primary server to the secondary server. This is a one way sync, whatever we add to the primary server will be copied over to the secondary server. Whatever is deleted from the primary server will also be deleted from the secondary server we accomplish this via the use of rsync.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">rsync <span style="color: #660033;">-avz</span> <span style="color: #660033;">--delete</span> <span style="color: #ff0000;">&quot;/Volumes/PrimaryWebsite/&quot;</span> <span style="color: #660033;">--rsh</span>=<span style="color: #ff0000;">'ssh -p8286'</span> username<span style="color: #000000; font-weight: bold;">@</span>XX.18.XX.22:www<span style="color: #000000; font-weight: bold;">/</span>domains<span style="color: #000000; font-weight: bold;">/</span>SecondaryWebsite</pre></div></div>

<p>Notice that the first line is the path to our primary website, the second value is the port number that you use to ssh into your secondary server if they require that.  The third option is the username and the ip address or hostname of the secondary server and then the path to the files on the secondary server. Again in order for this to work you really have to have completed the first step if this is not working refer back to the article that covers the appropriate way to ssh into your remote server <a href="http://www.jonsblog.org/2010/03/12/creating-an-ssh-key-for-secure-development">Syncing a failover website : Creating an SSH key</a>.<span id="more-134"></span></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Now starting modifications&quot;</span>
&nbsp;
<span style="color: #c20cb9; font-weight: bold;">scp</span> <span style="color: #660033;">-oPort</span>=<span style="color: #000000;">8286</span> <span style="color: #ff0000;">&quot;/Volumes/modifications/wp-config.php&quot;</span> username<span style="color: #000000; font-weight: bold;">@</span>XX.18.XX.22:www<span style="color: #000000; font-weight: bold;">/</span>domains<span style="color: #000000; font-weight: bold;">/</span>SecondaryWebsite</pre></div></div>

<p>What we are doing above is copying a modified version of the wp-config.php file because we use wordpress installations as our main CMS platform, the configuration settings on the primary server will not always match exactly the configuration settings on your secondary server. Which means that if you failover and the settings on the secondary server are the ones from your first server, and the secondary server uses a different database prefix, username or password the failover will succeed but it will failover to a website that will give you the dreaded &#8220;Cannot connect to database&#8221; error.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Now starting database sync&quot;</span>
&nbsp;
mysqldump <span style="color: #660033;">--user</span>=primarymysqlusername <span style="color: #660033;">--password</span>=primarymysqlpassword primarydatabasename <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">ssh</span> secondarysshusername<span style="color: #000000; font-weight: bold;">@</span>XX.18.XX.22 <span style="color: #660033;">-p8286</span> mysql <span style="color: #660033;">--user</span>= secondarymysqlusername <span style="color: #660033;">--password</span>= secondarymysqlpassword secondarydatabasename
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> Sync finished <span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">date</span><span style="color: #000000; font-weight: bold;">`</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>Volumes<span style="color: #000000; font-weight: bold;">/</span>Logs<span style="color: #000000; font-weight: bold;">/</span>Sync_log.txt</pre></div></div>

<p>The above code, will allow you to sync your database with the database in your secondary location. You will need to modify the settings to match your primary username and password for mysql. Your secondary username and passwords for mysql and the primary and secondary database names in mysql. What this does is it empties the target database and then it re-imports all the content from your primary server. Then it logs a line in the log, stating when it has completed. Here is what the finished script looks like.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> Sync started <span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">date</span><span style="color: #000000; font-weight: bold;">`</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>Volumes<span style="color: #000000; font-weight: bold;">/</span>Logs<span style="color: #000000; font-weight: bold;">/</span>Sync_log.txt
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Now starting rsync&quot;</span>
&nbsp;
rsync <span style="color: #660033;">-avz</span> <span style="color: #660033;">--delete</span> <span style="color: #ff0000;">&quot;/Volumes/PrimaryWebsite/&quot;</span> <span style="color: #660033;">--rsh</span>=<span style="color: #ff0000;">'ssh -p8286'</span> username<span style="color: #000000; font-weight: bold;">@</span>XX.18.XX.22:www<span style="color: #000000; font-weight: bold;">/</span>domains<span style="color: #000000; font-weight: bold;">/</span>SecondaryWebsite
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Now starting modifications&quot;</span>
&nbsp;
<span style="color: #c20cb9; font-weight: bold;">scp</span> <span style="color: #660033;">-oPort</span>=<span style="color: #000000;">8286</span> <span style="color: #ff0000;">&quot;/Volumes/modifications/wp-config.php&quot;</span> username<span style="color: #000000; font-weight: bold;">@</span>XX.18.XX.22:www<span style="color: #000000; font-weight: bold;">/</span>domains<span style="color: #000000; font-weight: bold;">/</span>SecondaryWebsite
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Now starting database sync&quot;</span>
&nbsp;
mysqldump <span style="color: #660033;">--user</span>=primarymysqlusername <span style="color: #660033;">--password</span>=primarymysqlpassword primarydatabasename <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">ssh</span> secondarysshusername<span style="color: #000000; font-weight: bold;">@</span>XX.18.XX.22 <span style="color: #660033;">-p8286</span> mysql <span style="color: #660033;">--user</span>= secondarymysqlusername <span style="color: #660033;">--password</span>= secondarymysqlpassword secondarydatabasename
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> Sync finished <span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">date</span><span style="color: #000000; font-weight: bold;">`</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>Volumes<span style="color: #000000; font-weight: bold;">/</span>Logs<span style="color: #000000; font-weight: bold;">/</span>Sync_log.txt</pre></div></div>

<p>Thats about it, in our next and final article on the topic of syncing multiple websites on multiple servers for failover purposes we will talk about the proper way to schedule your sync.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jonsblog.org/2010/05/22/syncing-a-failover-website-the-sync-script/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>I Syncing a failover website : Creating an SSH key</title>
		<link>http://www.jonsblog.org/2010/03/12/creating-an-ssh-key-for-secure-development/</link>
		<comments>http://www.jonsblog.org/2010/03/12/creating-an-ssh-key-for-secure-development/#comments</comments>
		<pubDate>Fri, 12 Mar 2010 18:09:18 +0000</pubDate>
		<dc:creator>Jon Brown</dc:creator>
				<category><![CDATA[OSX System Administration]]></category>
		<category><![CDATA[backup]]></category>
		<category><![CDATA[cronjob]]></category>
		<category><![CDATA[key]]></category>
		<category><![CDATA[schedule]]></category>
		<category><![CDATA[ssh tunnel]]></category>

		<guid isPermaLink="false">http://www.jonsblog.org/?p=104</guid>
		<description><![CDATA[Recently at our organization we were charged with the task of creating an auto failover solution for our websites. Basically the idea here is that we have our web server sitting in a data center but if for some reason the server were to ever go down then the website would fail over to a [...]]]></description>
			<content:encoded><![CDATA[<p>Recently at our organization we were charged with the task of creating an auto failover solution for our websites. Basically the idea here is that we have our web server sitting in a data center but if for some reason the server were to ever go down then the website would fail over to a second server where a duplicate of the website is waiting to be accessed in the event that the primary ever had an issue. This is doable but it requires that you have all your ducks in a row.</p>
<p>First, you must have DNS that can process a failover, you must have a script that will sync your files and your databases and most importantly of all you must have an open SSH tunnel between the two servers so that the sync can perform in a secure way without risk of any hacking happening. In this article I am going to outline the process of creating an ssh key for your second server, using terminal, and CPANEL. The failover hosting company we chose uses CPANEL and before we started we had to ask our host to enable jailed SSH access on our account in order to proceed.</p>
<p>Once enabled we must go through the process of creating a set of keys, a public key, and a private key. You must create the key on the computer that is considered to be the primary or the computer that will be running the sync script. Once your logged into that computer run these commands in terminal to create your private and public keys.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"> <span style="color: #c20cb9; font-weight: bold;">mkdir</span> ~<span style="color: #000000; font-weight: bold;">/</span>.ssh</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"> <span style="color: #7a0874; font-weight: bold;">cd</span> ~<span style="color: #000000; font-weight: bold;">/</span>.ssh</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"> <span style="color: #c20cb9; font-weight: bold;">ssh-keygen</span> <span style="color: #660033;">-b</span> <span style="color: #000000;">1024</span> <span style="color: #660033;">-t</span> dsa <span style="color: #660033;">-f</span> id_dsa <span style="color: #660033;">-P</span> <span style="color: #ff0000;">''</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"> <span style="color: #c20cb9; font-weight: bold;">chmod</span> <span style="color: #000000;">400</span> id_dsa</pre></div></div>

<p><span id="more-104"></span><br />
Now in your ~/.ssh folder you should have an id_dsa file, an id_dsa.pub and a file called authorized_keys. The first file is your private key. The second file is your public key. The last file is a file that protects your primary server, meaning no one will be able to ssh into your primary server without the public or private keys as a form of authorization.</p>
<p>On the secondary server with CPANEL login to your control panel and choose SSH from the list of options. Once there, press the &#8220;Import Keys&#8221; button and you will see two fields one for a public key one for the private key. Copy and paste the contents of your private key id_dsa on your primary server into the private key field. Copy the contents of id_dsa.pub into the second field labeled public key. Name the key, in the top field and press save.</p>
<p>Now that you have the keys there, you must authorize the keys, once you have you will be able to ssh into your secondary server from your primary server without entering your password. Your host may have you connect to their ssh tunnel using a custom port, if this is the case then this is the syntax.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"> <span style="color: #c20cb9; font-weight: bold;">ssh</span> <span style="color: #660033;">-p8569</span> username<span style="color: #000000; font-weight: bold;">@</span>host_name</pre></div></div>

<p>This will give you access to your account area, in our next article we will talk about how to create the sync script and sync your files, and databases over from the primary server to the secondary server on a scheduled basis.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jonsblog.org/2010/03/12/creating-an-ssh-key-for-secure-development/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>10.6.2 Dovecot Mail Backups</title>
		<link>http://www.jonsblog.org/2010/01/24/10-6-2-dovecot-mail-backups/</link>
		<comments>http://www.jonsblog.org/2010/01/24/10-6-2-dovecot-mail-backups/#comments</comments>
		<pubDate>Sun, 24 Jan 2010 00:08:15 +0000</pubDate>
		<dc:creator>Jon Brown</dc:creator>
				<category><![CDATA[Mail Server]]></category>
		<category><![CDATA[OSX Server Configuration]]></category>
		<category><![CDATA[backup]]></category>
		<category><![CDATA[dovecot]]></category>
		<category><![CDATA[download]]></category>
		<category><![CDATA[scripts]]></category>

		<guid isPermaLink="false">http://www.jonsblog.org/?p=33</guid>
		<description><![CDATA[Before migrating to 10.6 Server we were running our entire mailstore on the 10.5.8 platform. Say what you will about Leopard, once we had it set up correctly it ran fine. We migrated because of the greater benefits of Dovecot over Cyrus. Many of the other features intriqued us as well such as the improved [...]]]></description>
			<content:encoded><![CDATA[<p>Before migrating to 10.6 Server we were running our entire mailstore on the 10.5.8 platform. Say what you will about Leopard, once we had it set up correctly it ran fine. We migrated because of the greater benefits of Dovecot over Cyrus. Many of the other features intriqued us as well such as the improved Wiki server and iCal server. However we were really excited about Dovecots ability to repair itself basically doing away with the need to ever have to rebuild a users mailbox.</p>
<p>The one great thing about 10.5.8 was the development of <a href="http://osx.topicdesk.com/content/view/41/41/">Mailbfr</a> this was an amazing script that would help you backup your entire mailstore, recover email accounts, repair quotas, and of course rebuild or repair the entire mail-store. This was an invaluable tool, however since switching we have had to come up with our own solution.</p>
<p>We tried at first to get RSYNC running however this did not work because we did not have the permission to copy the mailstore with the permissions in tact. The reason is that while the root account does have access to look at the mailstore the secondary user on the mailstore folder is the mail user itself. Without running the script as each user then its near impossible to use RSYNC to move the mailstore or to even perform a simple backup.</p>
<p>Our solution was to create a backup script that use SCP with SCP we were able to move our mail-store to another drive on the server. It copies the store over and it resets the permissions to the administrator account. This solution works very well however after some time with a large mailstore you will run out of space on the target volume. Unlike RSYNC which uses hard links to save space SCP creates a new copy of the mailstore each time it is run.</p>
<p>In order to save space on the backup volume the oldest 2 weeks worth of backed up email gets dumped to DVD and removed from the drive on a monthly basis. This is fine but not optimal. Here is a copy of the script that we use on our server.<span id="more-33"></span></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> backup started daily backup <span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">date</span><span style="color: #000000; font-weight: bold;">`</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>Volumes<span style="color: #000000; font-weight: bold;">/</span>EMAIL\ BACKUP<span style="color: #000000; font-weight: bold;">/</span>Backup<span style="color: #000000; font-weight: bold;">/</span>Logs<span style="color: #000000; font-weight: bold;">/</span>Backup_log.txt
&nbsp;
<span style="color: #c20cb9; font-weight: bold;">scp</span> <span style="color: #660033;">-r</span> <span style="color: #000000; font-weight: bold;">/</span>Volumes<span style="color: #000000; font-weight: bold;">/</span>Mailstore-Location<span style="color: #000000; font-weight: bold;">/</span>spool <span style="color: #000000; font-weight: bold;">/</span>Volumes<span style="color: #000000; font-weight: bold;">/</span>EMAIL\ BACKUP<span style="color: #000000; font-weight: bold;">/</span>Email-Backups<span style="color: #000000; font-weight: bold;">/</span>$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">date</span> +<span style="color: #000000; font-weight: bold;">%</span>d<span style="color: #7a0874; font-weight: bold;">&#41;</span>-$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">date</span> +<span style="color: #000000; font-weight: bold;">%</span>m<span style="color: #7a0874; font-weight: bold;">&#41;</span>-$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">date</span> +<span style="color: #000000; font-weight: bold;">%</span>Y<span style="color: #7a0874; font-weight: bold;">&#41;</span>backup 
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> backup daily backup completed <span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">date</span><span style="color: #000000; font-weight: bold;">`</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>Volumes<span style="color: #000000; font-weight: bold;">/</span>EMAIL\ BACKUP<span style="color: #000000; font-weight: bold;">/</span>Backup<span style="color: #000000; font-weight: bold;">/</span>Logs<span style="color: #000000; font-weight: bold;">/</span>Backup_log.txt</pre></td></tr></table></div>

<p>This will backup the mailstore and then log each time that it does so. To recover an email to the original mailstore is not as hard as it seems. Navigate to the backed up mailstore destination and match up the name of the folder to the users UID of which you want to recover. For example if the users UID is 7458-58713-952554-544226 then you would look for a folder with the same name. Once in the folder you can copy or look at individual email files. Find the ones or one that you need and copy it to the folder of the original mailstore. In order to do this you will have to use sudo. For example this is how you would restore the entire folder</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">scp</span> <span style="color: #660033;">-r</span> <span style="color: #ff0000;">&quot;Volumes/EMAIL\ BACKUP/Email-Backups/7458-58713-952554-544226/.*&quot;</span> <span style="color: #ff0000;">&quot;/Volumes/Mailstore-Location/spool/7458-58713-952554-544226/.*&quot;</span></pre></td></tr></table></div>

<p>Until <a href="http://osx.topicdesk.com/content/view/41/41/">Mailbfr</a> comes back for Dovecot this is how we are protecting ourself against the accidental loss of email. I am not saying that this is the best method it is simply the one we are using. If you have another solution that works bette than please let me know and share your own experience!</p>
<p>*** UPDATE 12/8/2011 ***<br />
Here is the script that I am using to date for your use. It logs the backups and emails me when they are complete.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># This adds a record to our backup log</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> backup started daily backup <span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">date</span><span style="color: #000000; font-weight: bold;">`</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>Scripts<span style="color: #000000; font-weight: bold;">/</span>Logs<span style="color: #000000; font-weight: bold;">/</span>Backup_log.txt
&nbsp;
<span style="color: #666666; font-style: italic;"># This backs up the files</span>
&nbsp;
rsync <span style="color: #660033;">-avu</span> <span style="color: #000000; font-weight: bold;">/</span>location<span style="color: #000000; font-weight: bold;">/</span>of<span style="color: #000000; font-weight: bold;">/</span>mail<span style="color: #000000; font-weight: bold;">/</span>spool <span style="color: #000000; font-weight: bold;">/</span>Volumes<span style="color: #000000; font-weight: bold;">/</span>backup-volume<span style="color: #000000; font-weight: bold;">/</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># This adds another record to our backup log</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> backup daily backup completed <span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">date</span><span style="color: #000000; font-weight: bold;">`</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>Scripts<span style="color: #000000; font-weight: bold;">/</span>Logs<span style="color: #000000; font-weight: bold;">/</span>Backup_log.txt
&nbsp;
<span style="color: #666666; font-style: italic;"># This emails the Sys Admin</span>
&nbsp;
<span style="color: #007800;">NOW</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">date</span> +<span style="color: #ff0000;">&quot;%m-%d-%Y&quot;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
&nbsp;
<span style="color: #007800;">SUBJECT</span>=<span style="color: #ff0000;">&quot;Email Backed Up - &quot;</span><span style="color: #007800;">$NOW</span><span style="color: #ff0000;">&quot;&quot;</span>
&nbsp;
<span style="color: #007800;">EMAIL</span>=<span style="color: #ff0000;">&quot;email@user.com&quot;</span>
&nbsp;
<span style="color: #007800;">EMAILMESSAGE</span>=<span style="color: #ff0000;">&quot;/Scripts/Logs/Backup_log.txt&quot;</span>
&nbsp;
mail <span style="color: #660033;">-s</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$SUBJECT</span>&quot;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$EMAIL</span>&quot;</span> <span style="color: #000000; font-weight: bold;">&lt;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$EMAILMESSAGE</span>&quot;</span></pre></td></tr></table></div>

<p>The easiest way to start / stop  this is to setup a LaunchD or Cronjob, I prefer Cron since its easier in my opinion to setup. Setup the rsync script that you have below and put the code in a bash script. I use a GUI tool called Cronix http://code.google.com/p/cronnix/ once you download this launch it and put the full path to the bash script at the bottom the cron job code for every ten minutes is</p>
<p>0/10 * * * * * /path/to/bash/script.sh</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jonsblog.org/2010/01/24/10-6-2-dovecot-mail-backups/feed/</wfw:commentRss>
		<slash:comments>31</slash:comments>
		</item>
	</channel>
</rss>

