<?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>A Sceptical Mind &#187; backup</title>
	<atom:link href="http://www.scepticalmind.com/tag/backup/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.scepticalmind.com</link>
	<description>The ramblings of a Danish sceptic liberal</description>
	<lastBuildDate>Sat, 24 Apr 2010 16:24:19 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=abc</generator>
		<item>
		<title>Simple backup script with notification</title>
		<link>http://www.scepticalmind.com/2008/09/28/simple-backup-script-with-notification/</link>
		<comments>http://www.scepticalmind.com/2008/09/28/simple-backup-script-with-notification/#comments</comments>
		<pubDate>Sun, 28 Sep 2008 01:07:58 +0000</pubDate>
		<dc:creator>Michael Lind Mortensen</dc:creator>
				<category><![CDATA[Unix]]></category>
		<category><![CDATA[backup]]></category>
		<category><![CDATA[FreeBSD]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[Security]]></category>

		<guid isPermaLink="false">http://www.scepticalmind.com/?p=80</guid>
		<description><![CDATA[So I recently had to come up with a simple backup solution that didn&#8217;t involve any fancy system and basically just gave one the opportunity to choose what directories to backup, where to back them up and notify if something goes wrong. So I came up with a solution which, in my own view, could [...]]]></description>
			<content:encoded><![CDATA[<p>So I recently had to come up with a simple backup solution that didn&#8217;t involve any fancy system and basically just gave one the opportunity to choose what directories to backup, where to back them up and notify if something goes wrong.</p>
<p>So I came up with a solution which, in my own view, could be better and more &#8220;clean&#8221;, however this is how it is right now. You&#8217;re welcome to take the script, change and redistribute it &#8211; it&#8217;s released under the BSD license.</p>
<p>You might notice it&#8217;s refering to a bunch of files &#8211; these files are the error messages sent in e-mails and need to be placed somewhere, with corresponding changes in the script. If they don&#8217;t, e-mail notification won&#8217;t work.</p>
<p>Right now it&#8217;s sending e-mails when it&#8217;s succesful in making a backup. Depending on how often you want your cron job to do a backup, it might be irritating to get that many e-mails, so all you need to do is basically just remove the last part so that it only notifies you if something goes wrong.. That will however create the possibility that the e-mail functionality of the server will stop working and you won&#8217;t notice.</p>
<p>But yeah.. Here&#8217;s the script + all the error-messages zipped for download: <a href="http://www.scepticalmind.com/wp-content/uploads/2008/09/backup_script.zip">backup_script</a></p>
<p>I&#8217;ll be the first to admit it&#8217;s not optimal in any way.. it&#8217;s a quick solution and has a bunch of DRY (Don&#8217;t Repeat Yourself) violations&#8230; but hey.. it works and given it&#8217;s low complexity I don&#8217;t wanna prioritize cleaning it up that much &#8211; but you are more than welcome to do so!</p>
<p>Here&#8217;s the code copied into the post:</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>
<span style="color: #666666; font-style: italic;"># Copyright (c) 2008, Michael Lind Mortensen</span>
<span style="color: #666666; font-style: italic;"># All rights reserved.</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># Redistribution and use in source and binary forms, with or without</span>
<span style="color: #666666; font-style: italic;"># modification, are permitted provided that the following conditions are met:</span>
<span style="color: #666666; font-style: italic;">#     * Redistributions of source code must retain the above copyright</span>
<span style="color: #666666; font-style: italic;">#       notice, this list of conditions and the following disclaimer.</span>
<span style="color: #666666; font-style: italic;">#     * Redistributions in binary form must reproduce the above copyright</span>
<span style="color: #666666; font-style: italic;">#       notice, this list of conditions and the following disclaimer in the</span>
<span style="color: #666666; font-style: italic;">#       documentation and/or other materials provided with the distribution.</span>
<span style="color: #666666; font-style: italic;">#     * Neither the name of Michael Lind Mortensen nor the</span>
<span style="color: #666666; font-style: italic;">#       names of his contributors may be used to endorse or promote products</span>
<span style="color: #666666; font-style: italic;">#       derived from this software without specific prior written permission.</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># THIS SOFTWARE IS PROVIDED BY MICHAEL LIND MORTENSEN ''AS IS'' AND ANY</span>
<span style="color: #666666; font-style: italic;"># EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED</span>
<span style="color: #666666; font-style: italic;"># WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE</span>
<span style="color: #666666; font-style: italic;"># DISCLAIMED. IN NO EVENT SHALL MICHAEL LIND MORTENSEN BE LIABLE FOR ANY</span>
<span style="color: #666666; font-style: italic;"># DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES</span>
<span style="color: #666666; font-style: italic;"># (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;</span>
<span style="color: #666666; font-style: italic;"># LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND</span>
<span style="color: #666666; font-style: italic;"># ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT</span>
<span style="color: #666666; font-style: italic;"># (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS</span>
<span style="color: #666666; font-style: italic;"># SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Define settings</span>
<span style="color: #007800;">DATA</span>=<span style="color: #ff0000;">&quot;/home/user1 /home/user2 /etc /var/www/virtual /var/log&quot;</span> <span style="color: #666666; font-style: italic;">#Location of backup files.</span>
<span style="color: #007800;">DISC</span>=<span style="color: #ff0000;">&quot;/mnt/backup&quot;</span> <span style="color: #666666; font-style: italic;"># Mount location of backup disc</span>
<span style="color: #007800;">DEVICE</span>=<span style="color: #ff0000;">&quot;/dev/sdb1&quot;</span> <span style="color: #666666; font-style: italic;"># Backup devicename</span>
<span style="color: #007800;">MAILREC</span>=<span style="color: #ff0000;">&quot;info@example.com&quot;</span> <span style="color: #666666; font-style: italic;"># Define message recipients. Comma-separate for more recipients.</span>
<span style="color: #007800;">SENDER</span>=<span style="color: #ff0000;">&quot;noreply@example.com&quot;</span> <span style="color: #666666; font-style: italic;"># Define sender e-mail for error-messaging.</span>
<span style="color: #007800;">LOG</span>=<span style="color: #ff0000;">&quot;logfile.txt&quot;</span> <span style="color: #666666; font-style: italic;"># Location of the error logfile</span>
<span style="color: #007800;">DBPASS</span>=<span style="color: #ff0000;">&quot;databasepassword&quot;</span> <span style="color: #666666; font-style: italic;"># The root password to the mysql server</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">set</span> $<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">date</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#####################################################</span>
<span style="color: #666666; font-style: italic;">#  Define email functionality for error messaging   #</span>
<span style="color: #666666; font-style: italic;">#                                                   #</span>
<span style="color: #666666; font-style: italic;"># Parameters: MESSAGE - E-mail content from file    #</span>
<span style="color: #666666; font-style: italic;">#                                                   #</span>
<span style="color: #666666; font-style: italic;">#####################################################</span>
<span style="color: #000000; font-weight: bold;">function</span> error_mailer <span style="color: #7a0874; font-weight: bold;">&#123;</span>
        <span style="color: #007800;">MESSAGE</span>=$<span style="color: #000000;">1</span>
        <span style="color: #007800;">SUBJECT</span>=<span style="color: #ff0000;">&quot;Backup process encountered errors!&quot;</span>
        <span style="color: #666666; font-style: italic;"># Send the email using mail</span>
    <span style="color: #000000; font-weight: bold;">if</span> mail <span style="color: #660033;">-s</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$SUBJECT</span>&quot;</span> <span style="color: #660033;">-r</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$SENDER</span>&quot;</span>  <span style="color: #ff0000;">&quot;<span style="color: #007800;">$MAILREC</span>&quot;</span> <span style="color: #000000; font-weight: bold;">&amp;</span>lt; <span style="color: #007800;">$MESSAGE</span>
    <span style="color: #000000; font-weight: bold;">then</span>
        :
    <span style="color: #000000; font-weight: bold;">else</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;$3-$2-$6-$4 - ERROR: Mail functionality not working!&quot;</span> <span style="color: #000000; font-weight: bold;">&amp;</span>gt;<span style="color: #000000; font-weight: bold;">&amp;</span>gt; <span style="color: #007800;">$LOG</span>
    <span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#####################################################</span>
<span style="color: #666666; font-style: italic;">#  Define email functionality for success messaging #</span>
<span style="color: #666666; font-style: italic;">#                                                   #</span>
<span style="color: #666666; font-style: italic;"># Parameters: MESSAGE - E-mail content from file    #</span>
<span style="color: #666666; font-style: italic;">#                                                   #</span>
<span style="color: #666666; font-style: italic;">#####################################################</span>
<span style="color: #000000; font-weight: bold;">function</span> success_mailer <span style="color: #7a0874; font-weight: bold;">&#123;</span>
        <span style="color: #007800;">MESSAGE</span>=$<span style="color: #000000;">1</span>
        <span style="color: #007800;">SUBJECT</span>=<span style="color: #ff0000;">&quot;Backup created succesfully!&quot;</span>
        <span style="color: #666666; font-style: italic;"># Send the email using mail</span>
        <span style="color: #000000; font-weight: bold;">if</span> mail <span style="color: #660033;">-s</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$SUBJECT</span>&quot;</span> <span style="color: #660033;">-r</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$SENDER</span>&quot;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$MAILREC</span>&quot;</span> <span style="color: #000000; font-weight: bold;">&amp;</span>lt; <span style="color: #007800;">$MESSAGE</span>
        <span style="color: #000000; font-weight: bold;">then</span>
                :
        <span style="color: #000000; font-weight: bold;">else</span>
                <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;$3-$2-$6-$4 - ERROR: Mail functionality not working!&quot;</span> <span style="color: #000000; font-weight: bold;">&amp;</span>gt;<span style="color: #000000; font-weight: bold;">&amp;</span>gt; <span style="color: #007800;">$LOG</span>
        <span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span> 
&nbsp;
<span style="color: #666666; font-style: italic;"># Mount backup disc</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #c20cb9; font-weight: bold;">mount</span> <span style="color: #007800;">$DEVICE</span> <span style="color: #007800;">$DISC</span>
<span style="color: #000000; font-weight: bold;">then</span>
        :
<span style="color: #000000; font-weight: bold;">else</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;$3-$2-$6-$4 - ERROR: error while mounting disc!&quot;</span> <span style="color: #000000; font-weight: bold;">&amp;</span>gt;<span style="color: #000000; font-weight: bold;">&amp;</span>gt; <span style="color: #007800;">$LOG</span>
    error_mailer <span style="color: #ff0000;">&quot;/etc/backup_inc/errors/mount_error.txt&quot;</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Perform daily full backup</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #c20cb9; font-weight: bold;">tar</span> cfz <span style="color: #ff0000;">&quot;<span style="color: #007800;">$DISC</span>/data/data_$3-$2-$6.tgz&quot;</span> <span style="color: #007800;">$DATA</span>
<span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Data saved successfully!&quot;</span>
<span style="color: #000000; font-weight: bold;">else</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;$3-$2-$6-$4 - ERROR: error while saving data!&quot;</span> <span style="color: #000000; font-weight: bold;">&amp;</span>gt;<span style="color: #000000; font-weight: bold;">&amp;</span>gt; <span style="color: #007800;">$LOG</span>
    error_mailer <span style="color: #ff0000;">&quot;/etc/backup_inc/errors/data_error.txt&quot;</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Create SQL dumps of databases</span>
<span style="color: #000000; font-weight: bold;">if</span> mysqldump <span style="color: #660033;">-u</span> root <span style="color: #660033;">--password</span>=<span style="color: #007800;">$DBPASS</span> <span style="color: #660033;">--all-databases</span> <span style="color: #000000; font-weight: bold;">&amp;</span>gt; <span style="color: #ff0000;">&quot;<span style="color: #007800;">$DISC</span>/database/db_$3-$2-$6.sql&quot;</span>
<span style="color: #000000; font-weight: bold;">then</span>
        :
<span style="color: #000000; font-weight: bold;">else</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;$3-$2-$6-$4 - ERROR: error while making mysqldump!&quot;</span> <span style="color: #000000; font-weight: bold;">&amp;</span>gt;<span style="color: #000000; font-weight: bold;">&amp;</span>gt; <span style="color: #007800;">$LOG</span>
    error_mailer <span style="color: #ff0000;">&quot;/etc/backup_inc/errors/mysqldump_error.txt&quot;</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #c20cb9; font-weight: bold;">gzip</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$DISC</span>/database/db_$3-$2-$6.sql&quot;</span>
<span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;MySQL databases saved and compressed succesfully!&quot;</span>
<span style="color: #000000; font-weight: bold;">else</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;$3-$2-$6-$4 - ERROR: error while saving mysql databases!&quot;</span> <span style="color: #000000; font-weight: bold;">&amp;</span>gt;<span style="color: #000000; font-weight: bold;">&amp;</span>gt; <span style="color: #007800;">$LOG</span>
    error_mailer <span style="color: #ff0000;">&quot;/etc/backup_inc/errors/db_error.txt&quot;</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Unmount backup disc</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #c20cb9; font-weight: bold;">umount</span> <span style="color: #007800;">$DISC</span>
<span style="color: #000000; font-weight: bold;">then</span>
        success_mailer <span style="color: #ff0000;">&quot;/etc/backup_inc/success.txt&quot;</span>
<span style="color: #000000; font-weight: bold;">else</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;$3-$2-$6-$4 - ERROR: error while unmounting disc!&quot;</span> <span style="color: #000000; font-weight: bold;">&amp;</span>gt;<span style="color: #000000; font-weight: bold;">&amp;</span>gt; <span style="color: #007800;">$LOG</span>
        error_mailer <span style="color: #ff0000;">&quot;/etc/backup_inc/error/umount_error.txt&quot;</span>
<span style="color: #000000; font-weight: bold;">fi</span></pre></div></div>

<p>The fast person will probably notice that WordPress writes &lt; and &gt; as &amp;lt; and &amp;gt; .. that&#8217;s just the code plugin messing things up and I hope you can figure out how to fix that yourselves.. if not, the zipfile has the code without any odd layout errors.</p>
<p>All in all the code should be fairly self-explanatory.. if not, there are plenty of comments to help you use the script or change it to whatever you need.</p>
<p>Last but not least &#8211; Remember to add a cron job with the script.. If you don&#8217;t there won&#8217;t be much automatic backup about it.</p>
<p>That&#8217;s just about it.. Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.scepticalmind.com/2008/09/28/simple-backup-script-with-notification/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
