<?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; XFS</title>
	<atom:link href="http://orensol.com/tag/xfs/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>
	</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! -->