<?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>Takaitra.com &#187; Linux Administration</title>
	<atom:link href="http://www.takaitra.com/posts/category/how-to/linux/feed" rel="self" type="application/rss+xml" />
	<link>http://www.takaitra.com</link>
	<description>life, ruminations, how-to's</description>
	<lastBuildDate>Mon, 18 Jul 2011 22:09:32 +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>Backup to AWS EBS via Rsync and Boto</title>
		<link>http://www.takaitra.com/posts/384</link>
		<comments>http://www.takaitra.com/posts/384#comments</comments>
		<pubDate>Mon, 18 Jul 2011 16:09:32 +0000</pubDate>
		<dc:creator>Takaitra</dc:creator>
				<category><![CDATA[How-To's]]></category>
		<category><![CDATA[Linux Administration]]></category>
		<category><![CDATA[Amazon]]></category>
		<category><![CDATA[AWS]]></category>
		<category><![CDATA[backup]]></category>
		<category><![CDATA[boto]]></category>
		<category><![CDATA[Debian]]></category>
		<category><![CDATA[EBS]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[rsync]]></category>

		<guid isPermaLink="false">http://www.takaitra.com/?p=384</guid>
		<description><![CDATA[Amazon Web Services Elastic Block Storage provides cheap, reliable storage—perfect for backups. The idea is to temporarily spin up an EC2 instance, attach your EBS volume to it and upload your files. Transferring the data via rsync allows for incremental backups which is very fast and reduces costs. Once the backup is complete, the EC2 [...]]]></description>
			<content:encoded><![CDATA[<p>Amazon Web Services <a href="http://aws.amazon.com/ebs/">Elastic Block Storage</a> provides cheap, reliable storage—perfect for backups. The idea is to temporarily spin up an <a href="http://aws.amazon.com/ec2/">EC2</a> instance, attach your EBS volume to it and upload your files. Transferring the data via rsync allows for incremental backups which is very fast and reduces costs. Once the backup is complete, the EC2 instance is shutdown. The whole process can be repeated as often as needed by attaching a new EC2 instance to the same EBS volume. I backup 8 GB from my own server weekly using this method. The backup takes about 3 minutes and my monthly bill from Amazon is less than $1.</p>
<h3>Setup</h3>
<ol>
<li>If you don&#8217;t already have one, <a href="https://aws-portal.amazon.com/gp/aws/developer/registration/index.html">create an account with AWS</a>.</li>
<li>Take note of your <a href="https://aws-portal.amazon.com/gp/aws/developer/account/index.html?ie=UTF8&amp;action=access-key">access key</a>. You will need to place it in the script in order to connect to the AWS EC2 API.</li>
<li>Create an <a href="http://docs.amazonwebservices.com/AWSSecurityCredentials/1.0/AboutAWSCredentials.html#">Amazon EC2 key pair</a>. You need this to launch and connect to your EC2 instance. Download the private key and store in on your system. In my example, I have the private key stored at /home/takaitra/.ec2/takaitra-aws-key.pem</li>
<li>Create an EBS volume in your preferred zone (location). Make sure it is large enough to store your backups.</li>
<li>Create a security group called &#8220;rsync&#8221; that allows connections on two inbound TCP ports: 22 (for SSH) and 873 (for rsync).</li>
<li>Ensure a recent version of Python and <a href="http://code.google.com/p/boto/">Boto</a> are installed on your system. In Debian, this is accomplished by running the command &#8216;apt-get install python-boto&#8217;</li>
</ol>
<h3>The Script</h3>
<p>The below script automates the entire backup process via boto (A Python interface to AWS). Make sure to configure the VOLUME_ID, ZONE and BACKUP_DIRS variables with your own values. Also update SSH_OPTS to point to the private key of your EC2 key pair. &lt;aws access key&gt; and &lt;aws secret key&gt; need to be filled in on line 19.</p>
<pre class="brush: python; title: ; notranslate">#!/usr/bin/env python

import os
from boto.ec2.connection import EC2Connection
import time

IMAGE           = 'ami-8e1fece7' # Basic 64-bit Amazon Linux AMI
KEY_NAME        = 'takaitra-key'
INSTANCE_TYPE   = 't1.micro'
VOLUME_ID       = 'vol-########'
ZONE            = 'us-east-1a' # Availability zone must match the volume's
SECURITY_GROUPS = ['rsync'] # Security group allows SSH
SSH_OPTS        = '-o StrictHostKeyChecking=no -i /home/takaitra/.ec2/takaitra-aws-key.pem'
BACKUP_DIRS     = ['/etc', '/opt/', '/root', '/home', '/usr/local', '/var/www']
DEVICE          = '/dev/sdh'

# Create the EC2 instance
print 'Starting an EC2 instance of type {0} with image {1}'.format(INSTANCE_TYPE, IMAGE)
conn = EC2Connection('&lt;aws access key&gt;', '&lt;aws secret key&gt;')
reservation = conn.run_instances(IMAGE, instance_type=INSTANCE_TYPE, key_name=KEY_NAME, placement=ZONE, security_groups=SECURITY_GROUPS)
instance = reservation.instances[0]
time.sleep(10) # Sleep so Amazon recognizes the new instance
while not instance.update() == 'running':
    time.sleep(3) # Let the instance start up
time.sleep(10) # Still feeling sleepy
print 'Started the instance: {0}'.format(instance.dns_name)

# Attach and mount the backup volume
print 'Attaching volume {0} to device {1}'.format(VOLUME_ID, DEVICE)
volume = conn.get_all_volumes(volume_ids=[VOLUME_ID])[0]
volumestatus = volume.attach(instance.id, DEVICE)
while not volume.status == 'in-use':
    time.sleep(3) # Wait for the volume to attach
    volume.update()
time.sleep(10) # Still feeling sleepy
print 'Volume is attached'
os.system(&quot;ssh -t {0} ec2-user@{1} \&quot;sudo mkdir /mnt/data-store &amp;&amp; sudo mount {2} /mnt/data-store\&quot;&quot;.format(SSH_OPTS, instance.dns_name, DEVICE))

# Rsync
print 'Beginning rsync'
for backup_dir in BACKUP_DIRS:
    os.system(&quot;sudo rsync -e \&quot;ssh {0}\&quot; -avz --delete {2} ec2-user@{1}:/mnt/data-store{2}&quot;.format(SSH_OPTS, instance.dns_name, backup_dir))
print 'Rsync complete'

# Unmount and detach the volume, terminate the instance
print 'Unmounting and detaching volume'
os.system(&quot;ssh -t {0} ec2-user@{1} \&quot;sudo umount /mnt/data-store\&quot;&quot;.format(SSH_OPTS, instance.dns_name))
volume.detach()
while not volume.status == 'available':
    time.sleep(3) # Wait for the volume to detatch
    volume.update()
print 'Volume is detatched'
print 'Stopping instance'
instance.stop()</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.takaitra.com/posts/384/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>SpamAssassin on Debian</title>
		<link>http://www.takaitra.com/posts/4</link>
		<comments>http://www.takaitra.com/posts/4#comments</comments>
		<pubDate>Tue, 21 Oct 2008 18:49:33 +0000</pubDate>
		<dc:creator>Takaitra</dc:creator>
				<category><![CDATA[Linux Administration]]></category>
		<category><![CDATA[Debian]]></category>
		<category><![CDATA[Exim]]></category>
		<category><![CDATA[spam]]></category>
		<category><![CDATA[SpamAssassin]]></category>

		<guid isPermaLink="false">http://www.takaitra.com/blog/?p=4</guid>
		<description><![CDATA[Prerequisites A current Debian system with an MTA installed and working. This guide is specific to Exim4 although many of the steps would apply to other MTA&#8217;s as well. Also, the guide assumes you store your mail in Maildir format. If you store your mail in single files (mbox), you will have to adjust some [...]]]></description>
			<content:encoded><![CDATA[<h3>Prerequisites</h3>
<p>A current Debian system with an MTA installed and working. This guide is specific to Exim4 although many of the steps would apply to other MTA&#8217;s as well. Also, the guide assumes you store your mail in Maildir format. If you store your mail in single files (mbox), you will have to adjust some of the commands below.</p>
<h3>Install Packages</h3>
<p>Use aptitude or apt-get to install the packages &#8216;spamassassin&#8217; and &#8216;sa-exim.&#8217;</p>
<h3>Configuration</h3>
<p>Create a file called .forward in your home directory with the following content. If needed, update the save command to point to the location of your junk/spam directory.</p>
<pre># Exim filter
if $h_X-Spam-Status: CONTAINS "Yes"
or
$h_X-Spam-Flag: CONTAINS "Yes"
then
save $home/Maildir/.Junk/
finish
endif</pre>
<p>Edit /etc/exim4/sa-exim.conf and comment out the second SAEximRunCond attribute like so:</p>
<pre># Remove or comment out the following line to enable sa-exim
#SAEximRunCond: 0</pre>
<p>Edit /etc/default/spamassassin and change the ENABLED flag to 1.</p>
<p>Finally, start spamassassin and configure it to start at boot if needed:</p>
<pre># /etc/init.d/spamassassin start
# update-rc.d spamassassin defaults</pre>
<p>&nbsp;</p>
<h3>Optimization and Maintenence</h3>
<p>Take a look at the log file /var/log/exim4/mainlog. You should see SpamAssassin doing its thing for any new emails coming in. You will see what spam ranking it assigns to the message and what its fate is (allowed, allowed but flagged, or permanently rejected).</p>
<p>A good way to increase the accuracy of SpamAssasin is to teach it. First, organize your spam and non-spam (which we will call &#8220;ham&#8221;) into separate folders. Try to make sure you don&#8217;t miscategorize any. For this to work well, you will need over a hundred of each type of email&#8211;the more the better. Then, run the &#8216;sa-learn&#8217; command on the folders. For example, assuming your ham is in your inbox and your spam is in a folder called Junk:</p>
<pre>$ sa-learn --ham --showdots /home/username/Maildir/cur/*
$ sa-learn --spam --showdots /home/username/Maildir/.Junk/cur/*</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.takaitra.com/posts/4/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mailman and Exim4 on Debian</title>
		<link>http://www.takaitra.com/posts/14</link>
		<comments>http://www.takaitra.com/posts/14#comments</comments>
		<pubDate>Thu, 18 Sep 2008 11:57:16 +0000</pubDate>
		<dc:creator>Takaitra</dc:creator>
				<category><![CDATA[Linux Administration]]></category>
		<category><![CDATA[Debian]]></category>
		<category><![CDATA[etch]]></category>
		<category><![CDATA[Exim]]></category>
		<category><![CDATA[Mailman]]></category>

		<guid isPermaLink="false">http://www.takaitra.com/blog/?p=14</guid>
		<description><![CDATA[Update 10/21/2008: By the way, this article now appears on the Debian Administration web site! I recently installed Mailman on on my server to provide a mailing list for my extended family. While in the end, I was able to scrounge up the articles I needed by searching the web, many of them were woefully [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Update 10/21/2008</strong>: By the way, this article now <a href="http://www.debian-administration.org/articles/617">appears on the Debian Administration web site</a>!</p>
<p>I recently installed Mailman on on my server to provide a mailing list for my extended family. While in the end, I was able to scrounge up the articles I needed by searching the web, many of them were woefully outdated. Here is a short article that pulls together my research and describes in one place what is needed to get Mailman running happily under Debian etch with Exim4.</p>
<h2>Prerequisites</h2>
<p>This guide assumes that you are running a recent release of Debian and have Exim4 installed and working.</p>
<h2>Installing and Configuring Mailman</h2>
<p>To install mailman, simply run the following command:</p>
<pre>apt-get install mailman</pre>
<p>During the install, you will be prompted to choose which languages you want mailman to support.</p>
<p>After the install is complete, follow the instructions given during the install and setup the Mailman-specific mailing list.</p>
<pre>newlist mailman</pre>
<p>There are just a few changes that must be made to the basic configuration. Open /etc/mailman/mm_cfg.py and edit the following items:</p>
<pre># Default domain for email addresses of newly created mailing lists
DEFAULT_EMAIL_HOST = 'list.example.org'

# Default host for the web interface of newly created mailing lists
DEFAULT_URL_HOST   = 'list.example.org'

# Uncomment this. In this setup, the alias file won't need to be changed.
MTA=None   # Misnomer, suppresses alias output on newlist</pre>
<p>The last line makes no functional changes to mailman but will stop commands like &#8220;newlist&#8221; from outputing messages we won&#8217;t need. Restart mailman so that the configuration changes take effect:</p>
<pre>/etc/init.d/mailman restart</pre>
<p>Now would be a good time to set up any other mailing lists you will need using the same &#8220;newlist&#8221; command. If your list will be using anything other than the DEFAULT_URL_HOST we set up earlier as its web interface hostname, make sure to pass that to newlist with the -u flag.</p>
<h2>Exim Configuration</h2>
<p>The classic way of integrating Mailman with your MTA is to add each mailing list address to /etc/alias as a pipe to the mailman process. This is no longer the recommended way to configure Mailman with Exim. In fact, when I did try to add a piped alias, Exim choked on it because its default configuration no longer allows these for security reasons. So instead of adding dozens of lines to our alias file, we will be following the <a rel="nofollow" href="http://www.exim.org/howto/mailman21.html#exconf">exim.org how-to</a> to allow all Mailman addresses to automatically be handled by Exim.</p>
<p>Assuming you are using the split config, you will need to create the files listed below. If you are using a single file for configuration, you will need to find the appropriate places to insert the items.</p>
<p>/etc/exim4/conf.d/main/04_mailman_options:</p>
<pre># Mailman macro definitions

# Home dir for the Mailman installation
MM_HOME=/var/lib/mailman

# User and group for Mailman
MM_UID=list
MM_GID=list

#
# Domains that your lists are in - colon separated list
# you may wish to add these into local_domains as well
domainlist mm_domains=list.example.org

# The path of the Mailman mail wrapper script
MM_WRAP=MM_HOME/mail/mailman
#
# The path of the list config file (used as a required file when
# verifying list addresses)
MM_LISTCHK=MM_HOME/lists/${lc::$local_part}/config.pck</pre>
<p>/etc/exim4/conf.d/router/450_mailman_aliases:</p>
<pre>mailman_router:
driver = accept
domains = +mm_domains
require_files = MM_LISTCHK
local_part_suffix_optional
local_part_suffix = -admin : \
-bounces   : -bounces+*  : \
-confirm   : -confirm+*  : \
-join      : -leave      : \
-owner     : -request    : \
-subscribe : -unsubscribe
transport = mailman_transport
</pre>
<p>/etc/exim4/conf.d/transport/40_mailman_pipe:</p>
<pre>mailman_transport:
driver = pipe
command = MM_WRAP \
'${if def:local_part_suffix \
{${sg{$local_part_suffix}{-(\\w+)(\\+.*)?}{\$1}}} \
{post}}' \
$local_part
current_directory = MM_HOME
home_directory = MM_HOME
user = MM_UID
group = MM_GID
</pre>
<p>After you finish creating the various configuration files, run the following commands to build the updated configuration file and restart exim:</p>
<pre>update-exim4.conf
/etc/init.d/exim4 restart</pre>
<p>&nbsp;</p>
<h2>Apache Configuration</h2>
<p>mailman uses CGI to create a web interface for its mailing lists. We need to configure Apache in order to get this piece working. First create a file to store some new aliases for the web server.</p>
<p>/etc/apache2/conf.d/mailman:</p>
<pre>Alias /pipermail /var/lib/mailman/archives/public
Alias /images/mailman /usr/share/images/mailman
&lt;directory /var/lib/mailman/archives/public&gt;
DirectoryIndex index.html
&lt;/directory&gt;</pre>
<p>Then create (or edit) a VirtualHost entry to allow the scripts to run.</p>
<p>/etc/apache2/sites-available/list.example.org:</p>
<pre>&lt;virtualhost *:80&gt;
ServerName list.example.org
ServerAdmin webmaster@list.example.org
DocumentRoot /var/www/
&lt;directory /var/www/&gt;
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
# This directive allows us to have apache2's default start page
# in /apache2-default/, but still have / go to the right place
RedirectMatch ^/$ /cgi-bin/mailman/listinfo
&lt;/directory&gt;

ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
&lt;directory "/usr/lib/cgi-bin"&gt;
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
&lt;/directory&gt;
&lt;/virtualhost&gt;</pre>
<p>If this is a new file, remember to symlink it to the sites-enabled directory.</p>
<p>Finally, restart Apache so that the changes take effect.</p>
<pre>/etc/init.d/apache2 restart</pre>
<p>&nbsp;</p>
<h2>Administer your List</h2>
<p>That completes the setup! You can begin administering your new list at <a rel="nofollow" href="http://list.example.org/cgi-bin/mailman/listinfo">http://list.example.org/cgi-bin/mailman/listinfo</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.takaitra.com/posts/14/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

