<?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>Optima Solutions &#187; gmail</title>
	<atom:link href="http://www.optimasolutions.co.uk/tag/gmail/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.optimasolutions.co.uk</link>
	<description>Internet Consultancy without the technobabble</description>
	<lastBuildDate>Thu, 11 Mar 2010 21:15:17 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Automatic mySQL backups via email (Postfix -&gt; Google Mail)</title>
		<link>http://www.optimasolutions.co.uk/2009/10/30/automatic-mysql-backups-via-email-googlemail-postfix-ubuntu/</link>
		<comments>http://www.optimasolutions.co.uk/2009/10/30/automatic-mysql-backups-via-email-googlemail-postfix-ubuntu/#comments</comments>
		<pubDate>Fri, 30 Oct 2009 10:07:07 +0000</pubDate>
		<dc:creator>Stuart</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Internet]]></category>
		<category><![CDATA[Servers]]></category>
		<category><![CDATA[backup]]></category>
		<category><![CDATA[gmail]]></category>
		<category><![CDATA[googlemail]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[postfix]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://www.optimasolutions.co.uk/?p=193</guid>
		<description><![CDATA[When I was setting up my latest virtual server (courtesy of the ever fantastic VPS.net cloud), I wanted to come up with a simple hourly backup policy for the mySQL databases that reside on the machine. Every hour, I wanted to dump the databases, tar/zip them up in a single archive and email it with [...]]]></description>
			<content:encoded><![CDATA[<p>When I was setting up my latest virtual server (courtesy of the ever fantastic <a href="http://manage.aff.biz/z/155/CD2751/&amp;dp=1247" target="_blank">VPS.net</a> cloud), I wanted to come up with a simple hourly backup policy for the mySQL databases that reside on the machine. Every hour, I wanted to dump the databases, tar/zip them up in a single archive and email it with an appropriate date/time stamp to a backup store email account.</p>
<p>I&#8217;m a long time user of Google Apps for email, and an even longer time user of regular Gmail. As Google Apps (or a regular Gmail account) has a lot of storage space, it seems perfect for the job. I thought I&#8217;d see how easy it was to use one of these as an SMTP relay for any mail the server needed to send &#8211; and in this case &#8211; to send and store my backups.</p>
<p>With a lot of hunting around, I eventually pieced together a solution that worked from a few  different sources. So in the interests of helping anyone who needs something similar, here&#8217;s how I did it. I&#8217;m on Ubuntu 8.04.3 LTS. I&#8217;m guessing later versions will be very similar (if not identical).</p>
<p><strong>1. Set up Google Apps/Gmail accounts</strong></p>
<p>I set up two &#8211; a &#8216;no-reply&#8217; account I would use to send <strong>all</strong> email from the server, and a &#8216;backups&#8217; account for receiving the backup emails.</p>
<p><strong>2. Install and configure Postfix</strong></p>
<p>There are many, many tutorials out there, and believe me a tried a few. <a href="http://behindmyscreen.newsvine.com/_news/2006/12/31/501615-configuringubuntu-postfix-and-gmail-in-101-easy-steps" target="_blank">Here&#8217;s one</a> that actually worked. Well, mostly. The bit about <span style="font-family: Consolas, Monaco, 'Courier New', Courier, monospace; line-height: 18px; font-size: 12px; white-space: pre;">tls_per_site:</span></p>
<pre>smtp.gmail.com MUST
comp1.bob.com MUST
comp2.bob.com MUST
p&gt;</pre>
<p>..skip the <span style="font-family: Consolas, Monaco, 'Courier New', Courier, monospace; line-height: 18px; font-size: 12px; white-space: pre;">p&gt;<span style="font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; line-height: 19px; white-space: normal; font-size: 13px;">bit &#8211; it&#8217;s malformed html.</span></span></p>
<p>Do also make sure that you follow the information about setting up the Equifax certificate rather than the Thawte one &#8211; Google changed this in September and the system will not work if you use the wrong certificate.</p>
<p>Secondly, after following these instructions through any attempt to send mail was met with the following entry in <span style="font-family: Consolas, Monaco, 'Courier New', Courier, monospace; line-height: 18px; font-size: 12px; white-space: pre;">/var/log/mail.log<span style="font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; line-height: 19px; white-space: normal; font-size: 13px;">:</span></span></p>
<pre>postfix/smtp[7275]: connect to 127.0.0.1[127.0.0.1]:10024: Connection refused</pre>
<p>After a lot of looking around, I finally tracked it down to the following line in the main Postfix config file, located in <span style="font-family: Consolas, Monaco, 'Courier New', Courier, monospace; line-height: 18px; font-size: 12px; white-space: pre;">/etc/postfix/main.cf<span style="font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; line-height: 19px; white-space: normal; font-size: 13px;">:</span></span></p>
<pre>content_filter = amavis:[127.0.0.1]:10024</pre>
<p>Seems that this is a spam content filter which wasn&#8217;t installed correctly. In my case, since all I&#8217;m sending is backups, I didn&#8217;t need it. Commenting out this line and reloading Postfix (<span style="font-family: Consolas, Monaco, 'Courier New', Courier, monospace; line-height: 18px; font-size: 12px; white-space: pre;">sudo postfix reload<span style="font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; line-height: 19px; white-space: normal; font-size: 13px;">) sorted this out for me &#8211; mails were now sent.</span></span></p>
<p><strong>3. Set up the database backup system</strong></p>
<p>Again, there are many examples of this out there. I used <a href="http://www.sematopia.com/2006/02/how-to-backup-mysql-database-email-results-using-php/" target="_blank">this one</a> (requires PEAR for PHP), and adjusted it quickly to work on multiple databases. Make sure your backup location is writable by the server.</p>
<p><strong>4. Schedule the backup via CRON</strong></p>
<p>Dead simple &#8211; create a new CRON task for your user account:</p>
<pre>crontab -e</pre>
<p>and enter the following line (replacing the path to your backup script as appropriate):</p>
<pre>@hourly /usr/bin/php -q /home/[yourhome]/bin/backup.php &amp;&gt; /dev/null</pre>
<p>My script runs hourly. Adjust as you need.</p>
<p>And that&#8217;s it. Hourly backups taken to a secure &#8216;offsite&#8217; location with bags of storage space. Just what I was looking for.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.optimasolutions.co.uk/2009/10/30/automatic-mysql-backups-via-email-googlemail-postfix-ubuntu/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
