<?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>Favoretti's Braindumps</title>
	<atom:link href="http://favoretti.net/wp/feed/" rel="self" type="application/rss+xml" />
	<link>http://favoretti.net/wp</link>
	<description>Miscellaneous notes about nothing</description>
	<lastBuildDate>Sat, 17 Mar 2012 11:21:12 +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 Zimbra using LVM</title>
		<link>http://favoretti.net/wp/2012/03/17/backing-up-zimbra-using-lvm/</link>
		<comments>http://favoretti.net/wp/2012/03/17/backing-up-zimbra-using-lvm/#comments</comments>
		<pubDate>Sat, 17 Mar 2012 10:34:43 +0000</pubDate>
		<dc:creator>favoretti</dc:creator>
				<category><![CDATA[Braindump]]></category>

		<guid isPermaLink="false">http://favoretti.net/wp/?p=194</guid>
		<description><![CDATA[Now, since we moved to Zimbra I wanted to actually have it backed up. Small script to do it using LVM: #!/bin/bash DATE=`date -u +%d%m%Y` &#160; echo &#34;`date +%k:%M:%S` Backup started.&#34; # Stop zimbra, create a snapshot volume, start zimbra echo -n &#34;`date +%k:%M:%S` Stopping zimbra... &#34; /etc/init.d/zimbra stop 2&#38;&#62; /dev/null echo &#34; done.&#34; echo [...]]]></description>
			<content:encoded><![CDATA[<p>Now, since we moved to Zimbra I wanted to actually have it backed up.<br />
Small script to do it using LVM:</p>


<div class="wp-geshi-highlight-wrap5"><div class="wp-geshi-highlight-wrap4"><div class="wp-geshi-highlight-wrap3"><div class="wp-geshi-highlight-wrap2"><div class="wp-geshi-highlight-wrap"><div class="wp-geshi-highlight"><div class="bash"><pre class="de1"><span class="co0">#!/bin/bash</span>
<span class="re2">DATE</span>=<span class="sy0">`</span><span class="kw2">date</span> <span class="re5">-u</span> +<span class="sy0">%</span>d<span class="sy0">%</span>m<span class="sy0">%</span>Y<span class="sy0">`</span>
&nbsp;
<span class="kw3">echo</span> <span class="st0">&quot;<span class="es5">`date +%k:%M:%S`</span> Backup started.&quot;</span>
<span class="co0"># Stop zimbra, create a snapshot volume, start zimbra</span>
<span class="kw3">echo</span> <span class="re5">-n</span> <span class="st0">&quot;<span class="es5">`date +%k:%M:%S`</span> Stopping zimbra... &quot;</span>
<span class="sy0">/</span>etc<span class="sy0">/</span>init.d<span class="sy0">/</span>zimbra stop <span class="nu0">2</span><span class="sy0">&amp;&gt;</span> <span class="sy0">/</span>dev<span class="sy0">/</span>null
<span class="kw3">echo</span> <span class="st0">&quot; done.&quot;</span>
<span class="kw3">echo</span> <span class="re5">-n</span> <span class="st0">&quot;<span class="es5">`date +%k:%M:%S`</span> Creating snapshot volume... &quot;</span>
<span class="sy0">/</span>usr<span class="sy0">/</span>sbin<span class="sy0">/</span>lvcreate <span class="re5">-L</span> 5G <span class="re5">-s</span> <span class="re5">-n</span> vol_zimbrabackup <span class="sy0">/</span>dev<span class="sy0">/</span>vg0<span class="sy0">/</span>vol_zimbrarh <span class="nu0">2</span><span class="sy0">&gt;</span> <span class="sy0">/</span>dev<span class="sy0">/</span>null <span class="nu0">1</span><span class="sy0">&gt;</span> <span class="sy0">/</span>dev<span class="sy0">/</span>null
<span class="kw3">echo</span> <span class="st0">&quot; done.&quot;</span>
<span class="kw3">echo</span> <span class="re5">-n</span> <span class="st0">&quot;<span class="es5">`date +%k:%M:%S`</span> Starting zimbra... &quot;</span>
<span class="sy0">/</span>etc<span class="sy0">/</span>init.d<span class="sy0">/</span>zimbra start <span class="nu0">2</span><span class="sy0">&amp;&gt;</span> <span class="sy0">/</span>dev<span class="sy0">/</span>null
<span class="kw3">echo</span> <span class="st0">&quot; done.&quot;</span>
&nbsp;
<span class="co0"># Mount the snapshot, create a backup tarball, unmount snapshot, remove the volume</span>
<span class="kw3">echo</span> <span class="re5">-n</span> <span class="st0">&quot;<span class="es5">`date +%k:%M:%S`</span> Mounting snapshot... &quot;</span>
<span class="sy0">/</span>bin<span class="sy0">/</span><span class="kw2">mount</span> <span class="sy0">/</span>dev<span class="sy0">/</span>vg0<span class="sy0">/</span>vol_zimbrabackup <span class="sy0">/</span>zimbrabackup <span class="nu0">2</span><span class="sy0">&gt;</span> <span class="sy0">/</span>dev<span class="sy0">/</span>null <span class="nu0">1</span><span class="sy0">&gt;</span> <span class="sy0">/</span>dev<span class="sy0">/</span>null
<span class="kw3">echo</span> <span class="st0">&quot; done.&quot;</span>
<span class="kw3">echo</span> <span class="re5">-n</span> <span class="st0">&quot;<span class="es5">`date +%k:%M:%S`</span> Packing up stuff... &quot;</span>
<span class="sy0">/</span>bin<span class="sy0">/</span><span class="kw2">tar</span> jcf <span class="sy0">/</span>var<span class="sy0">/</span>backup<span class="sy0">/</span>zimbra-<span class="re1">$DATE</span>.tar.bz2 <span class="sy0">/</span>zimbrabackup<span class="sy0">/*</span> <span class="nu0">2</span><span class="sy0">&amp;&gt;</span> <span class="sy0">/</span>dev<span class="sy0">/</span>null
<span class="kw3">echo</span> <span class="st0">&quot; done.&quot;</span>
<span class="kw3">echo</span> <span class="re5">-n</span> <span class="st0">&quot;<span class="es5">`date +%k:%M:%S`</span> Un-mounting snapshot... &quot;</span>
<span class="sy0">/</span>bin<span class="sy0">/</span><span class="kw2">umount</span> <span class="sy0">/</span>zimbrabackup
<span class="kw3">echo</span> <span class="st0">&quot; done.&quot;</span>
<span class="kw3">echo</span> <span class="re5">-n</span> <span class="st0">&quot;<span class="es5">`date +%k:%M:%S`</span> Removing the snapshot... &quot;</span>
<span class="sy0">/</span>usr<span class="sy0">/</span>sbin<span class="sy0">/</span>lvremove <span class="re5">-f</span> <span class="sy0">/</span>dev<span class="sy0">/</span>vg0<span class="sy0">/</span>vol_zimbrabackup <span class="nu0">2</span><span class="sy0">&gt;</span> <span class="sy0">/</span>dev<span class="sy0">/</span>null <span class="nu0">1</span><span class="sy0">&gt;</span> <span class="sy0">/</span>dev<span class="sy0">/</span>null
<span class="kw3">echo</span> <span class="st0">&quot; done.&quot;</span>
&nbsp;
<span class="co0"># Cleanup logs older than a week</span>
<span class="kw3">echo</span> <span class="re5">-n</span> <span class="st0">&quot;<span class="es5">`date +%k:%M:%S`</span> Cleaning up old stuff... &quot;</span>
<span class="sy0">/</span>usr<span class="sy0">/</span>bin<span class="sy0">/</span><span class="kw2">find</span> <span class="sy0">/</span>var<span class="sy0">/</span>backup<span class="sy0">/</span>zimbra<span class="sy0">*</span>.bz2 <span class="re5">-type</span> f <span class="re5">-mtime</span> +<span class="nu0">7</span> <span class="sy0">|</span> <span class="kw2">xargs</span> <span class="kw2">rm</span> <span class="re5">-f</span> <span class="nu0">2</span><span class="sy0">&amp;&gt;</span> <span class="sy0">/</span>dev<span class="sy0">/</span>null
<span class="kw3">echo</span> <span class="st0">&quot; done.&quot;</span>
<span class="kw3">echo</span> <span class="st0">&quot;<span class="es5">`date +%k:%M:%S`</span> Backup done.&quot;</span></pre></div></div></div></div></div></div></div>


]]></content:encoded>
			<wfw:commentRss>http://favoretti.net/wp/2012/03/17/backing-up-zimbra-using-lvm/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Migrating from Scalix to Zimbra</title>
		<link>http://favoretti.net/wp/2012/03/17/migrating-from-scalix-to-zimbra/</link>
		<comments>http://favoretti.net/wp/2012/03/17/migrating-from-scalix-to-zimbra/#comments</comments>
		<pubDate>Sat, 17 Mar 2012 10:32:44 +0000</pubDate>
		<dc:creator>favoretti</dc:creator>
				<category><![CDATA[Braindump]]></category>

		<guid isPermaLink="false">http://favoretti.net/wp/?p=187</guid>
		<description><![CDATA[So, this week I again got a feeling that Scalix is not coming back from the dead as a company. After waiting for more than a year for new versions &#8211; I gave up. Search for a new solution ended up on choosing Zimbra Opensource Edition. Considering that I wasn&#8217;t able to find any real [...]]]></description>
			<content:encoded><![CDATA[<p>So, this week I again got a feeling that <a href="http://www.scalix.com">Scalix</a> is not coming back from the dead as a company. After waiting for more than a year for new versions &#8211; I gave up.</p>
<p>Search for a new solution ended up on choosing <a href="http://www.zimbra.com">Zimbra</a> Opensource Edition.</p>
<p>Considering that I wasn&#8217;t able to find any real guide to migration, I decided to lay down my experiences over here for my own use and for whoever might find this useful.</p>
<p><span id="more-187"></span></p>
<p>Setup was smooth. We&#8217;re running CentOS 5 on our mailserver, so I just picked the RH5 rpms, did</p>
<pre># ./install.sh --platform-override</pre>
<p>and it installed without problems.</p>
<p>Granted that we ran Scalix on the same box, I moved all Zimbra&#8217;s standard ports to +60000, so that IMAP was running on 60143, POP on 60110, web on 60080, etc.</p>
<p>After installing I went looking for a way to bulk-create my users.<br />
Provided &#8216;zmprov&#8217; command helped out in that:</p>
<pre>zimbra$ zmprov createAccount user@vlfn.nl displayName 'Firstname Lastname' givenName Firstname sn Lastname</pre>
<p>To later migrate the mail, I just set all the passwords to a default one for now:</p>
<pre>zimbra$ zmprov ma user@vlfn.nl userPassword foobar</pre>
<p>Now I wanted Zimbra to actually start receiving mail for the users.<br />
Stop sendmail and SMTP relay of Scalix:</p>
<pre>
# /etc/init.d/sendmail stop
# omoff -d0 "SMTP Relay"
</pre>
<p>Move Zimbra SMTP port into place:</p>
<pre>zimbra$ zmprov ms groupserve.vlfn.nl zimbraSmtpPort 25</pre>
<p>Restart Zimbra. Voila, Zimbra now receives your incoming mail. Whatever Scalix received in the meantime will be migrated in a few.</p>
<p>After that I needed to migrate users&#8217; mail of course.<br />
A few googling minutes and <a href="http://imapsync.lamiral.info/">imapsync</a> found itself.</p>
<p>I&#8217;ve created all users with standard password for now, to be able to use imapsync. More on restoring original passwords below.</p>
<p>You can access user&#8217;s mailbox as sxadmin in Scalix without knowing user password, so that is the functionality that I abused to achieve what I wanted.<br />
Scalix virtually raped IMAP protocol, by adding custom flags that Zimbra doesn&#8217;t understand, so I ended up stripping all the &#8216;X-*&#8217; flags from mails. Final command to migrate user&#8217;s mail looked like:</p>
<pre># /usr/bin/imapsync --nofoldersizes --skipsize --allowsizemismatch --regexflag s/\\X-*//g --noauthmd5 --buffersize 8192000 --nosyncacls --subscribe --syncinternaldates --host1 vlfn.nl --user1 mboxadmin:sxadmin:user --password1 sxadminpass --host2 vlfn.nl --port2 60143 --user2 user@vlfn.nl --password2=foobar</pre>
<p>A few words on the flags:<br />
&#8211;nofoldersizes and &#8211;skipsize will just make process faster as it won&#8217;t calculate the size of the folders and will not use message size comparison (in essence, there&#8217;s nothing to compare to in the new installation, so it saves an extra call to the new server)<br />
&#8211;buffersize increased to 8M helps zimbra to process stuff faster.<br />
&#8211;user1 format of &#8220;mboxadmin:sxadmin:user&#8221; allows you to access user&#8217;s mailbox with sxadmin password</p>
<p>Another handy tweak is increasing Zimbra&#8217;s indexing batch size to 20, so that it reruns its mail indexing not after each mail, but after every 20:</p>
<pre>zimbra$ zmprov mc vlfn.nl zimbraBatchedIndexingSize 20</pre>
<p>did that trick for me.</p>
<p>Note that this is where alternative ports for Zimbra come into place. In essence I&#8217;m running 2 servers next to each other on the same machine.</p>
<p>This process took a while. My mailbox is about 12GB in size, with around 80000 mails in it, it took somewhat 3,5 hours to migrate.</p>
<p>After mail has been migrated I needed to restore users&#8217;s original passwords.</p>
<p>First step was to extract current user passwords in crypted form from existing scalix installation.</p>
<pre># omsearch -d userlist -t h -e s=*</pre>
<p>extracted all the needed information and with a few awk tricks I managed to extract UL-AUTH-ID and UL-PWD out of the &#8220;/&#8221;-delimited fields.</p>
<p>After that I replaced all the escaped slashes in the passwords and created a command to update passwords for the users:</p>
<pre>zimbra$ zmprov ma user@vlfn.nl userPassword '{crypt}$1$izF4C3VL$Mw.xYuDwa21UL4dB5.CO.1'</pre>
<p>At this point we&#8217;re almost good to go. Now we just need to kill Scalix, move Zimbra IMAP to normal port, configure Apache to proxy Zimbra&#8217;s virtual host and go have our evening coffee.</p>
<p>Killing scalix is easy:</p>
<pre>
# /etc/init.d/scalix stop
# /etc/init.d/scalix-postgres stop
# /etc/init.d/scalix-tomcat stop
# chkconfig --level 345 scalix off
# chkconfig --level 345 scalix-postgres off
# chkconfig --level 345 scalix-tomcat off
</pre>
<p>Now, let&#8217;s move Zimbra services into place:</p>
<pre>
zimbra$ zmprov ms groupserve.vlfn.nl zimbraImapBindPort 143
zimbra$ zmprov ms groupserve.vlfn.nl zimbraPop3BindPort 110
</pre>
<p>And restart Zimbra:</p>
<pre>
# /etc/init.d/zimbra restart
</pre>
<p>At this point, you can happily inform your users that they can access stuff via IMAP/SMTP.</p>
<p>Now for the webmail. I run Apache, so I didn&#8217;t want Zimbra to be the only thing hoggering the HTTP(s) ports. Therefore, as I already mentioned above, I told it to bind itself on a +60000 range.</p>
<p>Create a separate virtualhost in apache config:</p>


<div class="wp-geshi-highlight-wrap5"><div class="wp-geshi-highlight-wrap4"><div class="wp-geshi-highlight-wrap3"><div class="wp-geshi-highlight-wrap2"><div class="wp-geshi-highlight-wrap"><div class="wp-geshi-highlight"><div class="html"><pre class="de1">&lt;VirtualHost *:80&gt;
   ServerName webmail.vlfn.nl
   ServerAdmin webmailadmin@vlfn.nl
   ProxyPass / http://webmail.vlfn.nl:60080/
   ProxyPassReverse / http://webmail.vlfn.nl:60080/
   ErrorLog logs/zimbra-error.log
   CustomLog logs/zimbra-access.log common
&lt;/VirtualHost&gt;</pre></div></div></div></div></div></div></div>


<p>And if you please a /webmail redirect from your normal website:</p>
<pre>
Redirect /webmail http://webmail.vlfn.nl
</pre>
<p>Restart apache.</p>
<p>Now go grab that coffee. You surely deserve one.</p>
]]></content:encoded>
			<wfw:commentRss>http://favoretti.net/wp/2012/03/17/migrating-from-scalix-to-zimbra/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>How to install Adobe Photoshop CS5 on a case-sensitive MacOS volume</title>
		<link>http://favoretti.net/wp/2012/01/21/how-to-install-adobe-photoshop-cs5-on-a-case-sensitive-macos-volume/</link>
		<comments>http://favoretti.net/wp/2012/01/21/how-to-install-adobe-photoshop-cs5-on-a-case-sensitive-macos-volume/#comments</comments>
		<pubDate>Sat, 21 Jan 2012 11:52:56 +0000</pubDate>
		<dc:creator>favoretti</dc:creator>
				<category><![CDATA[Braindump]]></category>

		<guid isPermaLink="false">http://favoretti.net/wp/?p=181</guid>
		<description><![CDATA[https://bitbucket.org/lokkju/adobe_case_sensitive_volumes This is just incredible. I&#8217;m sooooo thankful to this guy. Millions of kudos.]]></description>
			<content:encoded><![CDATA[<p><a href="https://bitbucket.org/lokkju/adobe_case_sensitive_volumes">https://bitbucket.org/lokkju/adobe_case_sensitive_volumes</a></p>
<p>This is just incredible. I&#8217;m sooooo thankful to this guy. Millions of kudos.</p>
]]></content:encoded>
			<wfw:commentRss>http://favoretti.net/wp/2012/01/21/how-to-install-adobe-photoshop-cs5-on-a-case-sensitive-macos-volume/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>+1, really +1</title>
		<link>http://favoretti.net/wp/2012/01/06/1-really-1/</link>
		<comments>http://favoretti.net/wp/2012/01/06/1-really-1/#comments</comments>
		<pubDate>Fri, 06 Jan 2012 14:46:28 +0000</pubDate>
		<dc:creator>favoretti</dc:creator>
				<category><![CDATA[Braindump]]></category>

		<guid isPermaLink="false">http://favoretti.net/wp/?p=173</guid>
		<description><![CDATA[Oh so true.]]></description>
			<content:encoded><![CDATA[<p><a href="http://favoretti.net/wp/wp-content/uploads/2012/01/1523205_460s_v1.jpg"><img src="http://favoretti.net/wp/wp-content/uploads/2012/01/1523205_460s_v1.jpg" alt="" title="1523205_460s_v1" width="419" height="324" class="alignleft size-full wp-image-174" /></a><br />
Oh so true.</p>
]]></content:encoded>
			<wfw:commentRss>http://favoretti.net/wp/2012/01/06/1-really-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>And in 2 smooth moves I got myself a new desktop.</title>
		<link>http://favoretti.net/wp/2011/11/26/and-in-2-smooth-moves-i-got-myself-a-new-desktop/</link>
		<comments>http://favoretti.net/wp/2011/11/26/and-in-2-smooth-moves-i-got-myself-a-new-desktop/#comments</comments>
		<pubDate>Sat, 26 Nov 2011 10:37:52 +0000</pubDate>
		<dc:creator>favoretti</dc:creator>
				<category><![CDATA[Braindump]]></category>
		<category><![CDATA[ilikeit]]></category>
		<category><![CDATA[macos]]></category>
		<category><![CDATA[macpro]]></category>

		<guid isPermaLink="false">http://favoretti.net/wp/2011/11/26/and-in-2-smooth-moves-i-got-myself-a-new-desktop/</guid>
		<description><![CDATA[Having been totally annoyed by constant windows quirks, being a unix admin and being used to easily tunnel SSH connections and whatnot on a mac, one day I got totally pissed off by not being able to do that easily on windows machine, so I rushed into a mac reseller demanding a mac pro&#8230; So, [...]]]></description>
			<content:encoded><![CDATA[<p>Having been totally annoyed by constant windows quirks, being a unix admin and being used to easily tunnel SSH connections and whatnot on a mac, one day I got totally pissed off by not being able to do that easily on windows machine, so I rushed into a mac reseller demanding a mac pro&#8230; So, there it went <img src='http://favoretti.net/wp/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p><span id="more-170"></span></p>
<p>Box was a bit dirty, but who cares, it&#8217;s all about the contents!</p>
<p><img src="http://favoretti.net/wp/wp-content/uploads/2011/11/myWPEdit_Image_1322303795.jpg" alt="myWPEdit Image" /></p>
<p>Your quick geek-a-lion “unboxing” <img src='http://favoretti.net/wp/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><img src="http://favoretti.net/wp/wp-content/uploads/2011/11/myWPEdit_Image_1322303829.jpg" alt="myWPEdit Image" /></p>
<p>There, happy now!</p>
<p><small><img src="http://favoretti.net/wp/wp-content/uploads/2011/11/myWPEdit_Image_1322303855.jpg" alt="myWPEdit Image" /></small><small>￼</small></p>
]]></content:encoded>
			<wfw:commentRss>http://favoretti.net/wp/2011/11/26/and-in-2-smooth-moves-i-got-myself-a-new-desktop/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>F6 :(</title>
		<link>http://favoretti.net/wp/2011/11/02/f6/</link>
		<comments>http://favoretti.net/wp/2011/11/02/f6/#comments</comments>
		<pubDate>Wed, 02 Nov 2011 12:13:35 +0000</pubDate>
		<dc:creator>favoretti</dc:creator>
				<category><![CDATA[Braindump]]></category>

		<guid isPermaLink="false">http://favoretti.net/wp/2011/11/02/f6/</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[<p><img src="http://favoretti.net/wp/wp-content/uploads/2011/11/myWPEdit_Image_1320236011.jpg" alt="myWPEdit Image" style="float:left;" /></p>
]]></content:encoded>
			<wfw:commentRss>http://favoretti.net/wp/2011/11/02/f6/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Python script to clean up binlogs based on number</title>
		<link>http://favoretti.net/wp/2011/10/25/python-script-to-clean-up-binlogs-based-on-number/</link>
		<comments>http://favoretti.net/wp/2011/10/25/python-script-to-clean-up-binlogs-based-on-number/#comments</comments>
		<pubDate>Tue, 25 Oct 2011 11:06:13 +0000</pubDate>
		<dc:creator>favoretti</dc:creator>
				<category><![CDATA[Braindump]]></category>

		<guid isPermaLink="false">http://favoretti.net/wp/?p=162</guid>
		<description><![CDATA[I stumbled on a problem in MySQL that you can only rotate binlogs based on age. In certain cases it wasn&#8217;t sufficient. Scripts that I&#8217;ve found on the net (mysql doc, etc) were all in PHP/perl&#8230; So I took a bit of liberty and stole one idea from mysql&#8217;s doc comments and turned it into [...]]]></description>
			<content:encoded><![CDATA[<p>I stumbled on a problem in MySQL that you can only rotate binlogs based on age. In certain cases it wasn&#8217;t sufficient. Scripts that I&#8217;ve found on the net (mysql doc, etc) were all in PHP/perl&#8230; So I took a bit of liberty and stole one idea from mysql&#8217;s doc comments and turned it into a piece of Python code. (uyes, ai luv python&#8230; hisssssssss).</p>


<div class="wp-geshi-highlight-wrap5"><div class="wp-geshi-highlight-wrap4"><div class="wp-geshi-highlight-wrap3"><div class="wp-geshi-highlight-wrap2"><div class="wp-geshi-highlight-wrap"><div class="wp-geshi-highlight"><div class="python"><pre class="de1"><span class="co1">#!/usr/bin/env python</span>
<span class="co1">#</span>
<span class="co1"># Since MySQL is unable to purge logs based on number of logs and does it only based on days</span>
<span class="co1"># I stole this idea from mysql.com. It was in PHP, I rewrote it in Python &lt;3</span>
<span class="co1">#</span>
<span class="co1">#         vllazarenko@ebay.com</span>
<span class="co1">#</span>
<span class="co1"># Questions? Do mail or pass by.</span>
<span class="co1">#</span>
<span class="co1">#</span>
&nbsp;
<span class="kw1">import</span> <span class="kw3">sys</span>
<span class="kw1">import</span> MySQLdb
&nbsp;
<span class="st0">&quot;&quot;&quot; If you want to smurf, smurf over here &quot;&quot;&quot;</span>
&nbsp;
slaveHost<span class="sy0">=</span><span class="st0">&quot;localhost&quot;</span>
slaveUser<span class="sy0">=</span><span class="st0">&quot;root&quot;</span>
slavePass<span class="sy0">=</span><span class="st0">&quot;rootpass&quot;</span>
slaveDb<span class="sy0">=</span><span class="st0">&quot;&quot;</span>
&nbsp;
masterHost<span class="sy0">=</span><span class="st0">&quot;masterhost&quot;</span>
masterUser<span class="sy0">=</span><span class="st0">&quot;root&quot;</span>
masterPass<span class="sy0">=</span><span class="st0">&quot;rootpass&quot;</span>
masterDb<span class="sy0">=</span><span class="st0">&quot;&quot;</span>
&nbsp;
keepLogs <span class="sy0">=</span> <span class="nu0">5</span>
&nbsp;
&nbsp;
<span class="st0">&quot;&quot;&quot; Please don't smurf after this line, unless you're an experienced smurf &quot;&quot;&quot;</span>
&nbsp;
<span class="kw1">try</span>:
     connSlave <span class="sy0">=</span> MySQLdb.<span class="me1">connect</span><span class="br0">&#40;</span>slaveHost<span class="sy0">,</span>
        	                 slaveUser<span class="sy0">,</span>
                	         slavePass<span class="sy0">,</span>
                        	 slaveDb<span class="br0">&#41;</span>
<span class="kw1">except</span> MySQLdb.<span class="me1">Error</span><span class="sy0">,</span> e:
     <span class="kw1">print</span> <span class="st0">&quot;SLAVE: Error %d: %s&quot;</span> % <span class="br0">&#40;</span>e.<span class="me1">args</span><span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span><span class="sy0">,</span> e.<span class="me1">args</span><span class="br0">&#91;</span><span class="nu0">1</span><span class="br0">&#93;</span><span class="br0">&#41;</span>
     <span class="kw3">sys</span>.<span class="me1">exit</span> <span class="br0">&#40;</span><span class="nu0">1</span><span class="br0">&#41;</span>
&nbsp;
<span class="kw1">try</span>:
	connMaster <span class="sy0">=</span> MySQLdb.<span class="me1">connect</span><span class="br0">&#40;</span>masterHost<span class="sy0">,</span>
        	                     masterUser<span class="sy0">,</span>
                	             masterPass<span class="sy0">,</span>
                        	     masterDb<span class="br0">&#41;</span>
<span class="kw1">except</span> MySQLdb.<span class="me1">Error</span><span class="sy0">,</span> e:
     <span class="kw1">print</span> <span class="st0">&quot;MASTER: Error %d: %s&quot;</span> % <span class="br0">&#40;</span>e.<span class="me1">args</span><span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span><span class="sy0">,</span> e.<span class="me1">args</span><span class="br0">&#91;</span><span class="nu0">1</span><span class="br0">&#93;</span><span class="br0">&#41;</span>
     <span class="kw3">sys</span>.<span class="me1">exit</span> <span class="br0">&#40;</span><span class="nu0">1</span><span class="br0">&#41;</span>
&nbsp;
cursSlave <span class="sy0">=</span> connSlave.<span class="me1">cursor</span><span class="br0">&#40;</span>MySQLdb.<span class="me1">cursors</span>.<span class="me1">DictCursor</span><span class="br0">&#41;</span>
cursMaster <span class="sy0">=</span> connMaster.<span class="me1">cursor</span><span class="br0">&#40;</span>MySQLdb.<span class="me1">cursors</span>.<span class="me1">DictCursor</span><span class="br0">&#41;</span>
&nbsp;
cursSlave.<span class="me1">execute</span><span class="br0">&#40;</span><span class="st0">&quot;SHOW SLAVE STATUS&quot;</span><span class="br0">&#41;</span>
row <span class="sy0">=</span> cursSlave.<span class="me1">fetchone</span><span class="br0">&#40;</span><span class="br0">&#41;</span>
&nbsp;
<span class="kw1">if</span> row<span class="br0">&#91;</span><span class="st0">&quot;Slave_IO_Running&quot;</span><span class="br0">&#93;</span> <span class="sy0">!=</span> <span class="st0">&quot;Yes&quot;</span>:
	<span class="kw1">print</span> <span class="st0">&quot;Alert. Slave IO not running.&quot;</span>
<span class="kw1">if</span> row<span class="br0">&#91;</span><span class="st0">&quot;Slave_SQL_Running&quot;</span><span class="br0">&#93;</span> <span class="sy0">!=</span> <span class="st0">&quot;Yes&quot;</span>:
	<span class="kw1">print</span> <span class="st0">&quot;Alert. Slave SQL not running.&quot;</span> 
<span class="kw1">if</span> row<span class="br0">&#91;</span><span class="st0">&quot;Last_Error&quot;</span><span class="br0">&#93;</span> <span class="sy0">!=</span> <span class="st0">&quot;&quot;</span>:
	<span class="kw1">print</span> <span class="st0">&quot;Alert. Error on slave: %s&quot;</span> % row<span class="br0">&#91;</span><span class="st0">&quot;Last_Error&quot;</span><span class="br0">&#93;</span>
&nbsp;
masterLog <span class="sy0">=</span> row<span class="br0">&#91;</span><span class="st0">&quot;Master_Log_File&quot;</span><span class="br0">&#93;</span>
<span class="kw1">print</span> <span class="st0">&quot;Current Master file on which Slave is acting: %s&quot;</span> % masterLog
&nbsp;
cursMaster.<span class="me1">execute</span><span class="br0">&#40;</span><span class="st0">&quot;SHOW MASTER LOGS&quot;</span><span class="br0">&#41;</span>
rows <span class="sy0">=</span> cursMaster.<span class="me1">fetchall</span><span class="br0">&#40;</span><span class="br0">&#41;</span>
&nbsp;
<span class="kw1">if</span> cursMaster.<span class="me1">rowcount</span> <span class="sy0">==</span> <span class="nu0">0</span>:
	<span class="kw1">print</span> <span class="st0">&quot;No master logs found.&quot;</span>
	<span class="kw3">sys</span>.<span class="me1">exit</span><span class="br0">&#40;</span><span class="nu0">1</span><span class="br0">&#41;</span>
&nbsp;
lognames <span class="sy0">=</span> <span class="kw2">list</span><span class="br0">&#40;</span><span class="br0">&#41;</span>
&nbsp;
<span class="kw1">for</span> row <span class="kw1">in</span> rows:
	lognames.<span class="me1">append</span><span class="br0">&#40;</span>row<span class="br0">&#91;</span><span class="st0">&quot;Log_name&quot;</span><span class="br0">&#93;</span><span class="br0">&#41;</span>
&nbsp;
marker <span class="sy0">=</span> lognames.<span class="me1">index</span><span class="br0">&#40;</span>masterLog<span class="br0">&#41;</span>
delMarker <span class="sy0">=</span> marker - keepLogs<span class="sy0">;</span>
&nbsp;
<span class="kw1">if</span> delMarker <span class="sy0">&lt;</span> <span class="nu0">2</span>:
	<span class="kw1">print</span> <span class="st0">&quot;Not purging below 2 logs.&quot;</span>
	<span class="kw3">sys</span>.<span class="me1">exit</span><span class="br0">&#40;</span><span class="nu0">1</span><span class="br0">&#41;</span>
&nbsp;
<span class="kw1">print</span> <span class="st0">&quot;Going to purge logs up to %s.&quot;</span> % lognames<span class="br0">&#91;</span>delMarker<span class="br0">&#93;</span>
&nbsp;
delQuery <span class="sy0">=</span> <span class="st0">&quot;PURGE MASTER LOGS TO '%s'&quot;</span> % lognames<span class="br0">&#91;</span>delMarker<span class="br0">&#93;</span>
<span class="co1"># cursMaster.execute(delQuery)</span>
&nbsp;
<span class="kw1">print</span> <span class="st0">&quot;Master binlogs were purged. The oldest log now available on the master is %s.&quot;</span> % lognames<span class="br0">&#91;</span>delMarker<span class="br0">&#93;</span>
&nbsp;
cursSlave.<span class="me1">close</span><span class="br0">&#40;</span><span class="br0">&#41;</span>
connSlave.<span class="me1">close</span><span class="br0">&#40;</span><span class="br0">&#41;</span>
cursMaster.<span class="me1">close</span><span class="br0">&#40;</span><span class="br0">&#41;</span>
connMaster.<span class="me1">close</span><span class="br0">&#40;</span><span class="br0">&#41;</span></pre></div></div></div></div></div></div></div>


]]></content:encoded>
			<wfw:commentRss>http://favoretti.net/wp/2011/10/25/python-script-to-clean-up-binlogs-based-on-number/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Just me&#8230;</title>
		<link>http://favoretti.net/wp/2011/10/17/just-me/</link>
		<comments>http://favoretti.net/wp/2011/10/17/just-me/#comments</comments>
		<pubDate>Mon, 17 Oct 2011 11:58:54 +0000</pubDate>
		<dc:creator>favoretti</dc:creator>
				<category><![CDATA[Braindump]]></category>

		<guid isPermaLink="false">http://favoretti.net/wp/2011/10/17/just-me/</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[<p><a href="http://favoretti.net/wp/wp-content/uploads/2011/10/360903_460s_v1.jpg"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="360903_460s_v1" border="0" alt="360903_460s_v1" src="http://favoretti.net/wp/wp-content/uploads/2011/10/360903_460s_v1_thumb.jpg" width="147" height="244" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://favoretti.net/wp/2011/10/17/just-me/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Music&#8230;</title>
		<link>http://favoretti.net/wp/2011/10/17/music/</link>
		<comments>http://favoretti.net/wp/2011/10/17/music/#comments</comments>
		<pubDate>Mon, 17 Oct 2011 11:31:14 +0000</pubDate>
		<dc:creator>favoretti</dc:creator>
				<category><![CDATA[Braindump]]></category>

		<guid isPermaLink="false">http://favoretti.net/wp/?p=153</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[<p><a href="http://favoretti.net/wp/wp-content/uploads/2011/10/362559_700b.jpg"><img class="aligncenter size-full wp-image-154" title="362559_700b" src="http://favoretti.net/wp/wp-content/uploads/2011/10/362559_700b.jpg" alt="" width="400" height="389" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://favoretti.net/wp/2011/10/17/music/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Want an iPhone 4G upgraded to 4S? No problem.</title>
		<link>http://favoretti.net/wp/2011/10/05/want-an-iphone-4g-upgraded-to-4s-no-problem/</link>
		<comments>http://favoretti.net/wp/2011/10/05/want-an-iphone-4g-upgraded-to-4s-no-problem/#comments</comments>
		<pubDate>Wed, 05 Oct 2011 15:29:56 +0000</pubDate>
		<dc:creator>favoretti</dc:creator>
				<category><![CDATA[Braindump]]></category>

		<guid isPermaLink="false">http://favoretti.net/wp/?p=150</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[<p><a href="http://favoretti.net/wp/wp-content/uploads/2011/10/post-1-13178225277185.jpg"><img class="size-full wp-image-151 alignleft" title="post-1-13178225277185" src="http://favoretti.net/wp/wp-content/uploads/2011/10/post-1-13178225277185.jpg" alt="" width="372" height="426" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://favoretti.net/wp/2011/10/05/want-an-iphone-4g-upgraded-to-4s-no-problem/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

