<?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>Guy Rutenberg &#187; Amazon AWS</title>
	<atom:link href="http://www.guyrutenberg.com/tag/amazon-aws/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.guyrutenberg.com</link>
	<description>Keeping track of what I do</description>
	<lastBuildDate>Wed, 16 Jun 2010 19:53:40 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Using Duplicity and Amazon S3 &#8211; Notes and Examples</title>
		<link>http://www.guyrutenberg.com/2009/12/12/using-duplicity-and-amazon-s3-notes-and-examples/</link>
		<comments>http://www.guyrutenberg.com/2009/12/12/using-duplicity-and-amazon-s3-notes-and-examples/#comments</comments>
		<pubDate>Sat, 12 Dec 2009 10:00:14 +0000</pubDate>
		<dc:creator>Guy</dc:creator>
				<category><![CDATA[Tips]]></category>
		<category><![CDATA[Amazon AWS]]></category>
		<category><![CDATA[backup]]></category>
		<category><![CDATA[duplicity]]></category>

		<guid isPermaLink="false">http://www.guyrutenberg.com/?p=603</guid>
		<description><![CDATA[Up until now I&#8217;ve been doing my backups to Amazon S3 using my s3backup script. While it&#8217;s simple and does what I needed at the time, I&#8217;ve decided to cut some of the costs by switching to incremental backups.

I went on to define what I&#8217;m looking for, and after a short search I&#8217;ve came up [...]]]></description>
			<content:encoded><![CDATA[<p>Up until now I&#8217;ve been doing my backups to Amazon S3 using my <a href="/2008/10/21/s3backup-easy-backups-of-folders-to-amazon-s3/"><code>s3backup</code></a> script. While it&#8217;s simple and does what I needed at the time, I&#8217;ve decided to cut some of the costs by switching to incremental backups.<br />
<span id="more-603"></span><br />
I went on to define what I&#8217;m looking for, and after a short search I&#8217;ve came up with <a href="http://duplicity.nongnu.org/">duplicity</a> which support efficient incremental backups to Amazon S3 (among many other backends). While duplicity has an simple CLI interface, I did come across two pitfalls when using S3.</p>
<p>The first one is that one must export the <code>AWS_ACCESS_KEY_ID</code> and <code>AWS_SECRET_ACCESS_KEY</code> or else you get a error message from the underlying <code>boto</code> library:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">  File &quot;//usr/lib64/python2.5/site-packages/boto/connection.py&quot;, line 148, in __init__
    self.hmac = hmac.new(self.aws_secret_access_key, digestmod=sha)
AttributeError: S3Connection instance has no attribute 'aws_secret_access_key'</pre></div></div>

<p>The second thing to note is that is the way to specify buckets for <code>duplicity</code>. Instead of</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">s3://&lt;bucket-name&gt;/&lt;prefix&gt;</pre></div></div>

<p>which is used by <a href="http://s3tools.logix.cz/s3cmd"><code>s3cmd</code></a> (which is a great tool), it asks to specify it using</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">s3+http://&lt;bucket-name&gt;/&lt;prefix&gt;</pre></div></div>

<p>Being aware of these points can save some time and frustration. In order to automate the backup process one can use <code>cron</code>. For example add the following to your <code>crontab</code></p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">AWS_ACCESS_KEY_ID=&quot;&lt;your-key-id&gt;&quot;
AWS_SECRET_ACCESS_KEY=&quot;&lt;your-secret-access-key&gt;&quot;
0 1 * * 0  duplicity --no-encryption &lt;folder-to-backup&gt; s3+http://&lt;bucket-name&gt;/&lt;prefix&gt; &amp;&gt;&gt; ~/backups.log
AWS_ACCESS_KEY_ID=&quot;&quot;
AWS_SECRET_ACCESS_KEY=&quot;&quot;</pre></div></div>

<p>I unset the environment variables, so it won&#8217;t leak to other cron jobs unnecessarily. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.guyrutenberg.com/2009/12/12/using-duplicity-and-amazon-s3-notes-and-examples/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>s3backup &#8211; Easy backups of Folders to Amazon S3</title>
		<link>http://www.guyrutenberg.com/2008/10/21/s3backup-easy-backups-of-folders-to-amazon-s3/</link>
		<comments>http://www.guyrutenberg.com/2008/10/21/s3backup-easy-backups-of-folders-to-amazon-s3/#comments</comments>
		<pubDate>Tue, 21 Oct 2008 19:24:49 +0000</pubDate>
		<dc:creator>Guy</dc:creator>
				<category><![CDATA[Bash]]></category>
		<category><![CDATA[Amazon AWS]]></category>
		<category><![CDATA[backup]]></category>

		<guid isPermaLink="false">http://www.guyrutenberg.com/?p=142</guid>
		<description><![CDATA[This is an updated version of my previous backups script &#8211; Backup Directories to Amazon S3 Script. The new script works much better and safer. Unlike the old script, the new one creates the tarballs in a temporary file under /tmp, and allows more control over the backup process.


#! /bin/bash
&#160;
# Copyright (C) 2008 by Guy [...]]]></description>
			<content:encoded><![CDATA[<p>This is an updated version of my previous backups script &#8211; <a href="/2008/03/01/backup-directories-to-amazon-s3-script/">Backup Directories to Amazon S3 Script</a>. The new script works much better and safer. Unlike the old script, the new one creates the tarballs in a temporary file under <code>/tmp</code>, and allows more control over the backup process.</p>
<p><span id="more-142"></span></p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">#! /bin/bash
&nbsp;
# Copyright (C) 2008 by Guy Rutenberg
&nbsp;
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the
# Free Software Foundation, Inc.,
# 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
&nbsp;
PROG=s3backup
DESCRIPTION=&quot;Backup directories to Amazon S3&quot;
SYNOPSIS=&quot;${PROG} [options] DIR BUCKET&quot;
VERSION=0.2
&nbsp;
print_usage () {
    echo &quot;Usage: ${SYNOPSIS}&quot;
    echo &quot;Save a backup of DIR to Amazon S3 bucket BUCKET&quot;
}
print_help ()  {
    print_usage
    cat &lt;&lt; EOF
&nbsp;
Options:
    -h, --help          show this help message and exit
    --version           show program's version number and exit
    -f, --full-path     use the path to dir in archive instead of only dir
    -v, --verbose       be verbose about progress
&nbsp;
Example:
    s3backup ~/Documents guyru-backup/
EOF
}
&nbsp;
print_version () {
    echo &quot;$PROG $VERSION&quot;
    echo &quot;Copyright (C) 2008 Guy Rutenberg &lt;http://www.guyrutenberg.com&gt;&quot;
}
&nbsp;
# print only if verbose
vecho () {
    if (( &quot;$VERBOSE&quot; &gt;= &quot;$1&quot; )) ; then
        echo &quot;$2&quot;
    fi
}
VERBOSE=0
TEMP=`getopt -o hvf --long help,version,verbose,full-path -n '${PROG}' -- &quot;$@&quot;`
if [ $? != 0 ] ; then
    print_usage
    exit 1
fi
&nbsp;
eval set -- &quot;$TEMP&quot;
&nbsp;
while true ; do
    case &quot;$1&quot; in
        -h|--help) print_help; exit ;;
        --version) print_version; exit ;;
        -f|--full-path) FULL_PATH=1; shift ;; 
        -v|--verbose) let VERBOSE++ ; shift ;;
        --) shift; break;;
    esac
done
&nbsp;
# no directory passed
if [ -z &quot;$1&quot; ]; then
    echo &quot;$PROG: missing DIR&quot;
    echo &quot;&quot;
    print_usage
    exit 1
fi
&nbsp;
# no bucket passed
if [ -z &quot;$2&quot; ]; then
    echo &quot;$PROG: missing BUCKET&quot;
    echo &quot;&quot;
    print_usage
    exit 2
fi
BUCKET=$2
&nbsp;
&nbsp;
DIR=$(basename &quot;$1&quot;)
DIR_PATH=$(dirname &quot;$1&quot;)
&nbsp;
DATE=$(date +%Y%m%d)
&nbsp;
&nbsp;
if [ -z &quot;$FULL_PATH&quot; ] ; then
    cd &quot;$DIR_PATH&quot;
    TAR_PATH=&quot;$DIR&quot;
else
    TAR_PATH=&quot;$1&quot;
fi
&nbsp;
vecho 1 &quot;Creating tarball&quot;
TARNAME=`mktemp`
TAR_OPTIONS=&quot;-c&quot;
if (( $VERBOSE &gt; 0 )); then
    TAR_OPTIONS+=&quot;v&quot;
fi
tar $TAR_OPTIONS &quot;$TAR_PATH&quot; | bzip2 -9 -c &gt; &quot;${TARNAME}&quot;
&nbsp;
vecho 1 &quot;Sending to Amazon S3&quot;
S3_OPTIONS=&quot;&quot;
if (( $VERBOSE &gt; 0 )); then
    S3_OPTIONS+=&quot;v&quot;
fi
s3cmd put $S3_OPTIONS &quot;$TARNAME&quot; &quot;s3://${BUCKET}$DIR-$DATE.tar.bz2&quot;
&nbsp;
vecho 1 &quot;Deleting intermediate files&quot;
rm &quot;$TARNAME&quot;
&nbsp;
# vim:sw=4:softtabstop=4:expandtab</pre></div></div>

<p>The script can also be downloaded from <a href="/wp-content/uploads/2008/10/s3backup.gz">s3backup.gz</a>.</p>
<p>Script usage is pretty straight forward, just pass the folder to backup as the first argument to the script, and an S3 bucket name, to which the backup will be saved as the second. You can also consult <code>s3backup --help</code>.</p>
<p>Note that you can add a prefix to your backups by adding it to the S3 bucket. For example</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">s3backup ~/Documents bucketname/prefix/</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.guyrutenberg.com/2008/10/21/s3backup-easy-backups-of-folders-to-amazon-s3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Wordpress Backup to Amazon S3 Script</title>
		<link>http://www.guyrutenberg.com/2008/10/11/wordpress-backup-to-amazon-s3-script/</link>
		<comments>http://www.guyrutenberg.com/2008/10/11/wordpress-backup-to-amazon-s3-script/#comments</comments>
		<pubDate>Sat, 11 Oct 2008 09:19:22 +0000</pubDate>
		<dc:creator>Guy</dc:creator>
				<category><![CDATA[Bash]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[Amazon AWS]]></category>
		<category><![CDATA[backup]]></category>

		<guid isPermaLink="false">http://www.guyrutenberg.com/?p=110</guid>
		<description><![CDATA[This is an updated version of my Wordpress Backup Script. The new version basically does the same thing: backup up a wordpress blog (actually any site that consists of files and a MySQL database). The new thing about the script is that instead of only saving the backup locally, it also uploads it to Amazon [...]]]></description>
			<content:encoded><![CDATA[<p>This is an updated version of my <a href="/2008/05/07/wordpress-backup-script/">Wordpress Backup Script</a>. The new version basically does the same thing: backup up a wordpress blog (actually any site that consists of files and a MySQL database). The new thing about the script is that instead of only saving the backup locally, it also uploads it to Amazon S3.</p>
<p><span id="more-110"></span></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: #666666; font-style: italic;"># (C) 2008 Guy Rutenberg</span>
<span style="color: #666666; font-style: italic;"># This is a script that creates backups of my blog.</span>
&nbsp;
<span style="color: #007800;">DB_NAME</span>=database_name
<span style="color: #007800;">DB_USER</span>=database_user
<span style="color: #007800;">DB_PASS</span>=<span style="color: #000000; font-weight: bold;">****</span>
<span style="color: #007800;">DB_HOST</span>=localhost
&nbsp;
<span style="color: #666666; font-style: italic;">#no trailing slash</span>
<span style="color: #007800;">BLOG_DIR</span>=<span style="color: #000000; font-weight: bold;">/</span>path<span style="color: #000000; font-weight: bold;">/</span>to<span style="color: #000000; font-weight: bold;">/</span>blog
<span style="color: #007800;">BACKUP_DIR</span>=<span style="color: #000000; font-weight: bold;">/</span>path<span style="color: #000000; font-weight: bold;">/</span>to<span style="color: #000000; font-weight: bold;">/</span>backups
<span style="color: #007800;">S3BUCKET</span>=s3:<span style="color: #000000; font-weight: bold;">//</span>bucket-name<span style="color: #000000; font-weight: bold;">/</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># end of configuration - you probably don't need to touch anything bellow</span>
<span style="color: #007800;">DUMP_NAME</span>=<span style="color: #800000;">${DB_NAME}</span>-$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">date</span> +<span style="color: #000000; font-weight: bold;">%</span>Y<span style="color: #000000; font-weight: bold;">%</span>m<span style="color: #000000; font-weight: bold;">%</span>d<span style="color: #7a0874; font-weight: bold;">&#41;</span>.sql.bz2
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;dumping database... &quot;</span>
mysqldump <span style="color: #660033;">--user</span>=<span style="color: #800000;">${DB_USER}</span> <span style="color: #660033;">--password</span>=<span style="color: #800000;">${DB_PASS}</span> <span style="color: #660033;">--host</span>=<span style="color: #800000;">${DB_HOST}</span> <span style="color: #800000;">${DB_NAME}</span> \
 <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">bzip2</span> <span style="color: #660033;">-c</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #800000;">${BACKUP_DIR}</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #800000;">${DUMP_NAME}</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;$?&quot;</span> <span style="color: #660033;">-ne</span> <span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
	<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;failed!&quot;</span>
	<span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">1</span>
<span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;done&quot;</span>
&nbsp;
<span style="color: #007800;">TAR_NAME</span>=<span style="color: #800000;">${BLOG_DIR##*/}</span>-$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">date</span> +<span style="color: #000000; font-weight: bold;">%</span>Y<span style="color: #000000; font-weight: bold;">%</span>m<span style="color: #000000; font-weight: bold;">%</span>d<span style="color: #7a0874; font-weight: bold;">&#41;</span>.tar.bz2
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;Creating tarball... &quot;</span>
<span style="color: #c20cb9; font-weight: bold;">tar</span> <span style="color: #660033;">-cjf</span> <span style="color: #800000;">${BACKUP_DIR}</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #800000;">${BLOG_DIR##*/}</span>-$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">date</span> +<span style="color: #000000; font-weight: bold;">%</span>Y<span style="color: #000000; font-weight: bold;">%</span>m<span style="color: #000000; font-weight: bold;">%</span>d<span style="color: #7a0874; font-weight: bold;">&#41;</span>.tar.bz2 <span style="color: #800000;">${BLOG_DIR}</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;$?&quot;</span> <span style="color: #660033;">-ne</span> <span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
	<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;failed!&quot;</span>
	<span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">1</span>
<span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;done&quot;</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;Uploading SQL dump to Amazon S3... &quot;</span>
s3cmd put <span style="color: #800000;">${BACKUP_DIR}</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #800000;">${DUMP_NAME}</span> <span style="color: #800000;">${S3BUCKET}</span><span style="color: #800000;">${DUMP_NAME}</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;$?&quot;</span> <span style="color: #660033;">-ne</span> <span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
	<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;failed!&quot;</span>
	<span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">1</span>
<span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;done&quot;</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;Uploading tarball to Amazon S3... &quot;</span>
s3cmd put <span style="color: #800000;">${BACKUP_DIR}</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #800000;">${TAR_NAME}</span> <span style="color: #800000;">${S3BUCKET}</span><span style="color: #800000;">${TAR_NAME}</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;$?&quot;</span> <span style="color: #660033;">-ne</span> <span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
	<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;failed!&quot;</span>
	<span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">1</span>
<span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;done&quot;</span></pre></div></div>

<p>As with the older <a href="/2008/03/01/backup-directories-to-amazon-s3-script/">Amazon S3 backup script</a>, this one also required you to install the <a href="http://s3tools.logix.cz/s3cmd">s3cmd</a> package.</p>
<p>The first six variables:</p>
<ul>
<li><code>DB_NAME</code></li>
<li><code>DB_USER</code></li>
<li><code>DB_PASS</code></li>
<li><code>DB_HOST</code></li>
<li><code>BLOG_DIR</code></li>
<li><code>BACKUP_DIR</code></li>
</ul>
<p>Are the pretty self explanatory and have the same meaning as in the <a href="/2008/05/07/wordpress-backup-script/">old script</a>.</p>
<p>The script has one new variable: <code>S3BUCKET</code>. This should be set to the S3 bucket to which the backups should be saved. If you want to add some prefix to the backups files on S3 this is the place.</p>
<p>The script keeps the backups both in the local backup directory and the Amazon S3.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.guyrutenberg.com/2008/10/11/wordpress-backup-to-amazon-s3-script/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
		<item>
		<title>Backup Directories To Amazon S3 Script</title>
		<link>http://www.guyrutenberg.com/2008/03/01/backup-directories-to-amazon-s3-script/</link>
		<comments>http://www.guyrutenberg.com/2008/03/01/backup-directories-to-amazon-s3-script/#comments</comments>
		<pubDate>Sat, 01 Mar 2008 20:12:27 +0000</pubDate>
		<dc:creator>Guy</dc:creator>
				<category><![CDATA[Bash]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Amazon AWS]]></category>
		<category><![CDATA[backup]]></category>

		<guid isPermaLink="false">http://www.guyrutenberg.com/2008/03/01/backup-directories-to-amazon-s3-script/</guid>
		<description><![CDATA[This is a small script I wrote today, to automate my backups, which I do on Amazon S3. This is fairly short, yet useful bash script that utilize the s3cmd to do the actual sending of the files.


#! /bin/bash
&#160;
# 2008 (C) Guy Rutenberg
#This is a script to backup a given folder and send them to [...]]]></description>
			<content:encoded><![CDATA[<p>This is a small script I wrote today, to automate my backups, which I do on <a href="http://aws.amazon.com/s3">Amazon S3</a>. This is fairly short, yet useful bash script that utilize the <a href="http://s3tools.logix.cz/s3cmd">s3cmd</a> to do the actual sending of the files.<br />
<span id="more-43"></span></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: #666666; font-style: italic;"># 2008 (C) Guy Rutenberg</span>
<span style="color: #666666; font-style: italic;">#This is a script to backup a given folder and send them to Amazon S3</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#string trailing slash (if exists)</span>
<span style="color: #007800;">DIR</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">${1/%\//}</span>&quot;</span>
<span style="color: #007800;">TARNAME</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">${DIR}</span>-<span style="color: #007800;">$(date +%Y%m%d)</span>.tar.bz2&quot;</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-e</span> <span style="color: #800000;">${TARNAME}</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000; font-weight: bold;">then</span>
	<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Refusing to overwrite existing file - <span style="color: #007800;">${TARNAME}</span>&quot;</span>
	<span style="color: #7a0874; font-weight: bold;">exit</span>
<span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Creating tarball&quot;</span>
<span style="color: #c20cb9; font-weight: bold;">tar</span> <span style="color: #660033;">-vc</span> <span style="color: #ff0000;">&quot;$1&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">bzip2</span> <span style="color: #660033;">-9</span> <span style="color: #660033;">-c</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">${TARNAME}</span>&quot;</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Sending to Amazon S3&quot;</span>
s3cmd put <span style="color: #660033;">-v</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">${TARNAME}</span>&quot;</span> s3:<span style="color: #000000; font-weight: bold;">//</span>guyru-backup<span style="color: #000000; font-weight: bold;">/</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Deleting intermediate files&quot;</span>
<span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">${TARNAME}</span>&quot;</span></pre></div></div>

<p>To use the script just save it somewhere and make it executable. Remember to substitute <code>guyru-backup</code> with your own bucket name. Notice that you must have s3cmd installed (for Gentoo it&#8217;s available under <code>net-misc/s3cmd</code>). s3cmd is one of the best interfaces to the S3 service I&#8217;ve seen, so you&#8217;ll probably want to install it anyway.</p>
<p>The script usage instructions are pretty simple. Just call the script and pass the path to the folder you want to backup as the first argument.</p>
<p>I intend to use this script to fully automate my backups using cron (maybe this way I&#8217;ll remember to the backups regularly).</p>
<p>I hope you will find this script useful. If you have any suggestions or comment please send them.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.guyrutenberg.com/2008/03/01/backup-directories-to-amazon-s3-script/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.621 seconds -->
