From b41d7697d060b3675ae160ef8b88c51e642b0c99 Mon Sep 17 00:00:00 2001 From: Michael Vrable Date: Wed, 9 Apr 2008 11:26:03 -0700 Subject: [PATCH] Implement a simple backend script to store data to Amazon S3. This currently doesn't quite use the interface expected by lbs. The interfaces will be matched soon. --- contrib/lbs-store-s3 | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100755 contrib/lbs-store-s3 diff --git a/contrib/lbs-store-s3 b/contrib/lbs-store-s3 new file mode 100755 index 0000000..340253a --- /dev/null +++ b/contrib/lbs-store-s3 @@ -0,0 +1,31 @@ +#!/usr/bin/python +# +# Storage hook for writing LBS backups directly to Amazon's Simple Storage +# Service (S3). +# +# Command-line arguments: +# +# Most options are controlled by environment variables: +# AWS_ACCESS_KEY_ID Amazon Web Services credentials +# AWS_SECRET_ACCESS_KEY " " +# LBS_S3_BUCKET S3 bucket in which data should be stored +# LBS_S3_PREFIX Path prefix to add to pathnames (include trailing +# slash) +# +# This script depends upon the boto Python library for interacting with Amazon +# S3. + +import os, sys +import boto +from boto.s3.bucket import Bucket +from boto.s3.key import Key + +prefix = os.environ.get('LBS_S3_PREFIX', "") +bucket_name = os.environ['LBS_S3_BUCKET'] +(local_path, file_type, remote_path) = sys.argv[1:4] + +conn = boto.connect_s3() +bucket = Bucket(conn, bucket_name) +k = Key(bucket) +k.key = prefix + file_type + "/" + remote_path +k.set_contents_from_filename(local_path) -- 2.20.1