<?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>Life Scaling &#187; EBS</title>
	<atom:link href="http://orensol.com/tag/ebs/feed/" rel="self" type="application/rss+xml" />
	<link>http://orensol.com</link>
	<description>Oren Solomianik's Blog</description>
	<lastBuildDate>Mon, 21 Jun 2010 08:10:03 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Cron Script To Snapshot Any Attached EBS Volume</title>
		<link>http://orensol.com/2009/08/10/cron-script-to-snapshot-any-attached-ebs-volume/</link>
		<comments>http://orensol.com/2009/08/10/cron-script-to-snapshot-any-attached-ebs-volume/#comments</comments>
		<pubDate>Mon, 10 Aug 2009 08:12:40 +0000</pubDate>
		<dc:creator>Oren</dc:creator>
				<category><![CDATA[Cloud Computing]]></category>
		<category><![CDATA[EC2]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Scaling]]></category>
		<category><![CDATA[Automatic]]></category>
		<category><![CDATA[cron]]></category>
		<category><![CDATA[EBS]]></category>
		<category><![CDATA[Script]]></category>
		<category><![CDATA[Snapshot]]></category>
		<category><![CDATA[Volume]]></category>
		<category><![CDATA[XFS]]></category>

		<guid isPermaLink="false">http://orensol.com/?p=267</guid>
		<description><![CDATA[<p>If you would like to cron snapshots of any attached volume to an instance, you can use the following script. It uses the EC2 command line tools to see what volumes are currently attached to this instance, and takes a snapshot. Make sure to replace all the variables on the top of the script to [...]]]></description>
			<content:encoded><![CDATA[<p>If you would like to cron snapshots of any attached volume to an instance, you can use the following script. It uses the EC2 command line tools to see what volumes are currently attached to this instance, and takes a snapshot. Make sure to replace all the variables on the top of the script to match your own.</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>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">JAVA_HOME</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>java<span style="color: #000000; font-weight: bold;">/</span>default
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">EC2_HOME</span>=<span style="color: #000000; font-weight: bold;">/</span>vol<span style="color: #000000; font-weight: bold;">/</span>snap<span style="color: #000000; font-weight: bold;">/</span>ec2-api-tools-<span style="color: #000000;">1.3</span>-<span style="color: #000000;">26369</span>
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">EC2_PRIVATE_KEY</span>=<span style="color: #7a0874; font-weight: bold;">&#91;</span>PATH-TO-YOUR-PRIVATE-KEY<span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">EC2_CERT</span>=<span style="color: #7a0874; font-weight: bold;">&#91;</span>PATH-TO-YOUR-CERT<span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">AWS_ACCESS_KEY_ID</span>=<span style="color: #ff0000;">&quot;[YOUR-ACCESS-KEY]&quot;</span>
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">AWS_SECRET_ACCESS_KEY</span>=<span style="color: #ff0000;">&quot;[YOUR-SECRET-KEY]&quot;</span>
&nbsp;
<span style="color: #007800;">INSTANCE_ID</span>=<span style="color: #000000; font-weight: bold;">`</span>curl <span style="color: #660033;">-s</span> http:<span style="color: #000000; font-weight: bold;">//</span>169.254.169.254<span style="color: #000000; font-weight: bold;">/</span>latest<span style="color: #000000; font-weight: bold;">/</span>meta-data<span style="color: #000000; font-weight: bold;">/</span>instance-id<span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Instance ID is <span style="color: #007800;">$INSTANCE_ID</span>&quot;</span>
<span style="color: #007800;">VOLUMES</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #007800;">$EC2_HOME</span><span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>ec2-describe-volumes <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #ff0000;">&quot;ATTACHMENT&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$INSTANCE_ID</span>&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $2}'</span><span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Volumes are: <span style="color: #007800;">$VOLUMES</span>&quot;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">for</span> VOLUME <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #007800;">$VOLUMES</span>; <span style="color: #000000; font-weight: bold;">do</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Snapping Volume <span style="color: #007800;">$VOLUME</span>&quot;</span>
        <span style="color: #007800;">DEVICE</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #007800;">$EC2_HOME</span><span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>ec2-describe-volumes <span style="color: #007800;">$VOLUME</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #ff0000;">&quot;ATTACHMENT&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$INSTANCE_ID</span>&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $4}'</span><span style="color: #000000; font-weight: bold;">`</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Device is <span style="color: #007800;">$DEVICE</span>&quot;</span>
        <span style="color: #007800;">MOUNTPOINT</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">df</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$DEVICE</span>&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $6}'</span><span style="color: #000000; font-weight: bold;">`</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Mountpoint is <span style="color: #007800;">$MOUNTPOINT</span>&quot;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;"># Snapshot</span>
        <span style="color: #007800;">SNAPSHOT_ID</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #007800;">$EC2_HOME</span><span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>ec2-create-snapshot <span style="color: #007800;">$VOLUME</span><span style="color: #000000; font-weight: bold;">`</span>
&nbsp;
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Snapshotted: <span style="color: #007800;">$SNAPSHOT_ID</span>&quot;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">done</span></pre></div></div>

<p>If you&#8217;re wondering why $MOUNTPOINT is important (it&#8217;s not used here after all), it&#8217;s because you might want to freeze your filesystem if it&#8217;s XFS, so you could safely take a snapshot of a MySQL database for example. So you could easily wrap the snapshot create command with this:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">        <span style="color: #666666; font-style: italic;"># freeze</span>
        xfs_freeze <span style="color: #660033;">-f</span> <span style="color: #007800;">$MOUNTPOINT</span>
&nbsp;
        <span style="color: #666666; font-style: italic;"># Snapshot</span>
        <span style="color: #007800;">SNAPSHOT_ID</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #007800;">$EC2_HOME</span><span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>ec2-create-snapshot <span style="color: #007800;">$VOLUME</span><span style="color: #000000; font-weight: bold;">`</span>
&nbsp;
        <span style="color: #666666; font-style: italic;"># unfreeze</span>
        xfs_freeze <span style="color: #660033;">-u</span> <span style="color: #007800;">$MOUNTPOINT</span></pre></div></div>

<p>And if you are indeed using this script to snapshot a volume with MySQL on it, you need also to flush tables with read lock, and gather information on master and slave positions. For this task you can use <a href="http://twitter.com/esh" target="_blank">Eric Hammond</a>&#8217;s <a href="http://ec2-snapshot-xfs-mysql.notlong.com/" target="_blank">script</a>, and incorporate it to the cron script. (You can read more about MySQL and XFS on EC2 <a href="http://developer.amazonwebservices.com/connect/entry.jspa?externalID=1663" target="_blank">on the AWS site</a>).</p>
]]></content:encoded>
			<wfw:commentRss>http://orensol.com/2009/08/10/cron-script-to-snapshot-any-attached-ebs-volume/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>How to delete those old EC2 EBS snapshots</title>
		<link>http://orensol.com/2009/02/12/how-to-delete-those-old-ec2-ebs-snapshots/</link>
		<comments>http://orensol.com/2009/02/12/how-to-delete-those-old-ec2-ebs-snapshots/#comments</comments>
		<pubDate>Thu, 12 Feb 2009 17:57:44 +0000</pubDate>
		<dc:creator>Oren</dc:creator>
				<category><![CDATA[Cloud Computing]]></category>
		<category><![CDATA[EC2]]></category>
		<category><![CDATA[Scaling]]></category>
		<category><![CDATA[AWS]]></category>
		<category><![CDATA[Bulk]]></category>
		<category><![CDATA[Delete]]></category>
		<category><![CDATA[EBS]]></category>
		<category><![CDATA[Multiple]]></category>
		<category><![CDATA[Old]]></category>
		<category><![CDATA[Snapshots]]></category>

		<guid isPermaLink="false">http://orensol.com/?p=104</guid>
		<description><![CDATA[<p><a href="http://aws.amazon.com/ebs/" target="_blank">EBS snapshots</a> are a very powerful feature of <a href="http://aws.amazon.com/ec2/" target="_blank">Amazon EC2</a>. An EBS volume is readily available, elastic block storage device that can be attached, detached and re-attached to any instance in its availability zone. There are <a href="http://blog.rightscale.com/2008/08/20/amazon-ebs-explained/" target="_blank">numerous advantages</a> to using EBS over the local block storage devices of an [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://aws.amazon.com/ebs/" target="_blank">EBS snapshots</a> are a very powerful feature of <a href="http://aws.amazon.com/ec2/" target="_blank">Amazon EC2</a>. An EBS volume is readily available, elastic block storage device that can be attached, detached and re-attached to any instance in its availability zone. There are <a href="http://blog.rightscale.com/2008/08/20/amazon-ebs-explained/" target="_blank">numerous advantages</a> to using EBS over the local block storage devices of an instance, and one of the most important of them is the ability to take a snapshot of the data on the volume.</p>
<p>Since snapshots are incremental by nature, after an initial snapshot of a volume, the following snapshots are quick and easy. Moreover, snapshots are always processed by Amazon&#8217;s processing power and not by the cpu of your instance, and are stored redundantly on S3. This is why using these snapshots in your backup methodology is a great idea (provided that you freeze/unfreeze your filesystem during the snapshot call, using <a href="http://en.wikipedia.org/wiki/Logical_Volume_Manager_(Linux)" target="_blank">LVM</a> or <a href="http://en.wikipedia.org/wiki/XFS" target="_blank">XFS</a> for example).</p>
<p>But, and this is a really annoying but &#8211; snapshots are &#8220;easy come hard to go&#8221;. They are so convenient to use and so reliable, that it&#8217;s natural to use a cronned script to make a daily, or hell &#8212; hourly! &#8212; backup of your volume. But then, those snapshots keep piling up, and the only way to delete a snapshot is to call a single API call for a specific snapshot.If you have 5 volumes you back up hourly, you reach the 500 snapshots limit withing 4.5 days. Not very reliable now, huh?</p>
<p>I have been searching for a while for an option to bulk delete snapshots. The EC2 API is missing this feature, and the excellent <a href="http://developer.amazonwebservices.com/connect/entry.jspa?externalID=609" target="_blank">ElasticFox</a> add-on is not compensating. You just can&#8217;t bulk delete snapshots.</p>
<p>That is, until now <img src='http://orensol.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> . I <a href="http://developer.amazonwebservices.com/connect/thread.jspa?messageID=116355" target="_blank">asked</a> in the AWS Forum if there is anything that can be done about this problem. They replied it&#8217;s a good idea, but if I really wanted it to be implemented quickly, I should build my own solution using the API. So I took the offer, and came up with a PHP command line tool that tries to emulate a &#8220;ec2-delete-old-snapshots&#8221; command, until one is added to the API.</p>
<p>The tool is <a href="http://code.google.com/p/ec2-delete-old-snapshots/" target="_blank">available on Google Code for checkout</a>. It uses the <a href="http://developer.amazonwebservices.com/connect/entry.jspa?externalID=1669" target="_blank">PHP EC2 library </a>which I bundled in (hope I didn&#8217;t break any licensing issue, please alert me if I did).</p>
<p>Usage is easy:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">php ec2-delete-old-snapshots.php <span style="color: #660033;">-v</span> vol-id <span style="color: #7a0874; font-weight: bold;">&#91;</span>-v vol-id ...<span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #660033;">-o</span> days</pre></div></div>

<p>If you wanted to delete ec2 snapshots older than 7 days for 2 volumes you have, you would use:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">php ec2-delete-old-snapshots.php <span style="color: #660033;">-v</span> vol-aabbccdd <span style="color: #660033;">-v</span> vol-bbccddee <span style="color: #660033;">-o</span> <span style="color: #000000;">7</span></pre></div></div>

<p>Hope this helps all you people out there who need such a thing. I will be happy to receive <a href="http://twitter.com/orensol" target="_blank">feedback</a> (and bug fixes) if you start using this.</p>
]]></content:encoded>
			<wfw:commentRss>http://orensol.com/2009/02/12/how-to-delete-those-old-ec2-ebs-snapshots/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->