<?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>Technology Associates Group &#187; Mondo</title>
	<atom:link href="http://tagfl.com/tag/mondo/feed/" rel="self" type="application/rss+xml" />
	<link>http://tagfl.com</link>
	<description>"Serve wholeheartedly, as if you were serving the LORD, not men." - Ephesians 6:7</description>
	<lastBuildDate>Wed, 10 Jun 2009 20:52:36 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Automating Mondo</title>
		<link>http://tagfl.com/2008/04/10/automating-mondo/</link>
		<comments>http://tagfl.com/2008/04/10/automating-mondo/#comments</comments>
		<pubDate>Thu, 10 Apr 2008 14:25:37 +0000</pubDate>
		<dc:creator>jon</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[backup]]></category>
		<category><![CDATA[Mondo]]></category>

		<guid isPermaLink="false">http://tagfl.com/?p=5</guid>
		<description><![CDATA[Backing up your Linux system using Mondo and an external USB hard drive]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m sure at some point I&#8217;ll get around to expounding the various virtues of backups and how those who don&#8217;t ensure that their clients are backing-up should be burned at the stake, but that&#8217;s another post. What I really want to talk about is <a href="http://www.mondorescue.org/">Mondo</a>.<span id="more-5"></span></p>
<p>If you&#8217;ve never heard of Mondo, I&#8217;m not surprised. Mondo is a Linux backup program designed to be reliable, easy and comprehensive &#8211; which all backup suites should be. Here are some excerpts from the about page:</p>
<blockquote><p>&#8230; backs up your GNU/Linux server or workstation to tape, CD-R, CD-RW, DVD-R[W], DVD+R[W], NFS or hard disk partition. &#8230; you will be able to restore all of your data, from bare metal if necessary. Mondo is in use by Lockheed-Martin, Nortel Networks, Siemens, HP, IBM, NASA&#8217;s JPL, the US Dept of Agriculture, &#8230;</p>
<p>Mondo supports LVM 1/2, RAID, ext2, ext3, JFS, XFS, ReiserFS, VFAT, UFS, and can support additional filesystems easily: &#8230; software raid as well as most hardware raid controllers. &#8230; Mondo runs on all major Linux distributions &#8230; You may even use it to backup non-Linux partitions, such as NTFS.</p>
<p><strong>Mondo is free!</strong> It has been published under the GPL v2 (GNU Public         License), &#8230;</p></blockquote>
<p>A few of things you might have noticed there:</p>
<ol>
<li>Mondo is a Linux backup program. I stated this before, but I want to make sure all the Windows users out there know what they&#8217;re missing. You can use Mondo to backup a Windows-only workstation, but that&#8217;s another post too.</li>
<li>Large companies (probably larger than you deal with) use this software. You probably don&#8217;t have the resources to test every configuration that you&#8217;ll run into, but they most likely have.</li>
<li>This is FREE software. Everyone will know before long that I&#8217;m a huge proponent of free software. Best of all, should you need commercial support, it&#8217;s there!</li>
</ol>
<p>Now, let&#8217;s get started.</p>
<p>I&#8217;m going to assume your distribution already has Mondo in their repositories or that you already know how to download and install a package. If not, maybe I&#8217;ll cover <em>that</em> in another post. I&#8217;ll also assume that you can read documentation and that you can figure out the command-line options for Mondo. The intention of this post is to help you automate Mondo so you can use it for a daily backup.</p>
<p>My particular need of this solution came at the time a client&#8217;s 10/20 Travan drive failed, and the purchase of a new one combined with maintenance of tapes was more than finding a modern solution. I had used Mondo once before to backup up my own personal system before moving to a larger drive, so I had some experience with it.</p>
<p>I know very little about BASH scripting, just enough to get myself in trouble, so if there are huge glaring errors in my script, feel free to point them out in the comments and I will feel free to ignore them as I rewrite the script in Perl. <img src='http://tagfl.com/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' />  I called my script <strong>makemondobackup</strong>; inventive I know.</p>
<blockquote><p><code>#!/bin/bash</code></p>
<p>#Setup some static variables<br />
DATABASE=/etc/mondo/database<br />
MNT_POINT=/backup<br />
SCRIPT=&#8221;MMBK&#8221;<br />
TMPDIR=/tmp/makemondo.$RANDOM</p>
<p>#Functions<br />
function logOut() {<br />
echo -n $SCRIPT&#8221; &#8221;<br />
echo -n $(date +%H%M%S)&#8221;: &#8221;<br />
echo $1<br />
}</p>
<p># Check for the old log. I don&#8217;t think it appends, but why take the chance.<br />
if [ -f /var/log/mondo-archive.log ]; then<br />
logOut &#8220;Deleteing old mondo-archive.log&#8221;<br />
rm -f /var/log/mondo-archive.log<br />
else<br />
logOut &#8220;Old mondo-archive.log does not exist&#8221;<br />
fi</p>
<p># Mount the drive if not mounted.<br />
MNT_INFO=$(mount | awk -v mnt=$MNT_POINT &#8216;{ if ($3 == mnt) print $0 }&#8217;)<br />
#&#8217; To fix sysntax coloring in mc<br />
if [ "$MNT_INFO" == "" ]; then<br />
logOut &#8220;/backup Not Mounted&#8221;<br />
mount /dev/sda1 /backup<br />
else<br />
logOut &#8220;/backup Mounted&#8221;<br />
fi<br />
MNT_INFO=$(mount | awk -v mnt=$MNT_POINT &#8216;{ if ($3 == mnt) print $0 }&#8217;)<br />
#&#8217; To fix sysntax coloring again in mc<br />
if [ "$MNT_INFO" == "" ]; then<br />
logOut &#8220;/backup Still Not Mounted. Something went wrong.&#8221;<br />
exit<br />
fi</p>
<p># What backup device are we using?<br />
VOLUME=`ls $MNT_POINT | grep -i &#8220;Volume_&#8221;`</p>
<p>#logrotate -f /etc/mondo/mondologrotate<br />
# Count the number of previous backups on the drive, looking for directories beg<br />
inning with &#8220;20&#8243;<br />
MYBACKUPS=(`ls $MNT_POINT | grep &#8220;^20&#8243; | sort`)<br />
logOut &#8220;I found ${#MYBACKUPS[*]} backups&#8221;<br />
while [ ${#MYBACKUPS[@]} -gt 6 ]; do<br />
logOut &#8220;Too many backups, deleting oldest ${MYBACKUPS[0]}&#8221;<br />
rm -rf /backup/${MYBACKUPS[0]}<br />
#    sed &#8216;/${MYBACKUPS[0]}/ d&#8217; &gt; &#8220;$DATABASE.tmp&#8221;<br />
grep -v ${MYBACKUPS[0]} $DATABASE &gt; &#8220;$DATABASE.tmp&#8221;<br />
mv -f $DATABASE &#8220;$DATABASE.bak&#8221;<br />
mv -f &#8220;$DATABASE.tmp&#8221; $DATABASE<br />
MYBACKUPS=(`ls $MNT_POINT | grep &#8220;^2&#8243; | sort`)<br />
done</p>
<p># Name for backup folder<br />
DATE=$(date +%Y%m%d-%H%M%S)<br />
# Create the temp and backup directories<br />
logOut &#8220;Creating $TMPDIR&#8221;<br />
mkdir $TMPDIR<br />
logOut &#8220;Creating /backup/$DATE&#8221;<br />
mkdir /backup/$DATE</p>
<p># Actual mondoarchive command<br />
# -Oi = create iso files<br />
# -d = where to backup to<br />
# -E = Exclude these directories<br />
# -S -T = Temp dirs<br />
# -p = prefix for iso files<br />
# -0 = compression level [0-9]<br />
# -F = do not write floppy images<br />
CMDTORUN=&#8221;mondoarchive -Oi -d /backup/$DATE -E /backup -S $TMPDIR -T $TMPDIR -0<br />
-F -p $HOSTNAME&#8221;<br />
logOut &#8220;Executing: $CMDTORUN&#8221;<br />
touch /backup/$DATE/mondo-run.log<br />
$CMDTORUN 2&gt;&amp;1 &gt; /backup/$DATE/mondo-run.log</p>
<p># Check the exit code to see if everything went OK<br />
if [ "$?" -ne "0" ]; then<br />
logOut &#8220;We didn&#8217;t exit correctly. Not cleaning up $TMPDIR.&#8221;<br />
else<br />
logOut &#8220;Good exit. Cleaning up $TMPDIR.&#8221;<br />
rm -rf $TMPDIR<br />
logOut &#8220;Adding $DATE $VOLUME backup to $DATABASE&#8221;<br />
#Write the backup info to the database<br />
echo &#8220;$DATE $VOLUME&#8221; &gt;&gt; $DATABASE<br />
fi</p>
<p># Finally copy the backup script and other necessities<br />
mkdir /backup/$DATE/etc<br />
cp -rf /etc/mondo/* /backup/$DATE/etc<br />
mkdir /backup/$DATE/images<br />
cp -rf /root/images/* /backup/$DATE/images<br />
cp /var/log/mondo-archive.log /backup/$DATE</p>
<p># Email the report. Don&#8217;t need to do this now.<br />
#mailx -s &#8220;server-$DATE&#8221; nunya@biznes.com &lt; /backup/$DATE/mondo-archive.log</p>
<p>#Unmount the drive<br />
umount /backup</p></blockquote>
<p>My script requires a few things to be setup that the next version will automatically take care of. First, we expect the external drive to be <strong><em>sda1</em></strong>; if this is different on your system, change the mount line. Second, we expect each external drive to have a &#8220;label&#8221; (a file indicating what Volume number it is), so you have to label each drive by hand. Third, I expect you are allowing Mindi (Mondo&#8217;s cousin) to run so that we have bootable CD images that are copied to the backup. I can&#8217;t imagine why you wouldn&#8217;t, but people do odd things. Fourth, the file <strong>database</strong> must be created as the script will probably crash horribly without it. Lastly, everything should be placed in <strong>/etc/mondo</strong> as that was the arbitrary place I decided they should go.</p>
<p>The script takes care of mounting the drive (if it&#8217;s not already mounted), creating the backup directory on the external drive, running mondoarchive (the actual Mondo backup command), cleaning up after and unmounting the drive so the someone can change them out. It also copies the log file if everything went ok, and leaves it where it is, if it didn&#8217;t. I&#8217;ve left my numerous comments in, hopefully they help you understand my original design.</p>
<p>I run the script using a single cronjob, saved in <strong>/etc/cron.d</strong> and called <strong>mondo</strong>, detailed here:</p>
<blockquote><p><code># Regular cron job for backup</code></p>
<p>SHELL=/bin/sh<br />
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin</p>
<p># Every day at 7:30p<br />
0 19 * * 1-5    root    test -x /etc/mondo/makemondobackup &amp;&amp; /etc/mondo/makemondobackup | mailx -s &#8220;Backup Run Log&#8221; nunya@biznes.com<br />
#</p></blockquote>
<p>Obviously, you want to change the email address for the logs to go to; poor Nunya has enough logs to read on his own. Don&#8217;t forget an empty line at the end of your cronjob. You will spend many hours trying to figure out why you script doesn&#8217;t run.</p>
<p>If you are monitoring backups for your clients, <em>check your logs every morning</em>. If you didn&#8217;t get a log, find out why. I recently picked up a client whose previous consultant let them get 30 days behind on backups. They didn&#8217;t find out until they had a drive failure. It is going to happen. Drive failure is a &#8220;when&#8221;, not an &#8220;if.&#8221; Your clients will respect you so much more if they can recover quickly.</p>
<p>I love Linux for the simple fact that anything difficult can be made simple. I have run about three months of backups using this script and test about every other week. I have had yet to have a backup fail or fail to restore.</p>
<p>My hope is that this script and Mondo can help you automate those servers that aren&#8217;t getting regular backups; there are far too many of them out there. External drives are cheap folks, make your backups.</p>
]]></content:encoded>
			<wfw:commentRss>http://tagfl.com/2008/04/10/automating-mondo/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
