Re-do cumulus side of upload script interface.
[cumulus.git] / contrib / cumulus-store-s3
1 #!/usr/bin/python
2 #
3 # Storage hook for writing LBS backups directly to Amazon's Simple Storage
4 # Service (S3).
5 #
6 # Command-line arguments:
7 #   <local_file> <type> <remote_name>
8 # Most options are controlled by environment variables:
9 #   AWS_ACCESS_KEY_ID       Amazon Web Services credentials
10 #   AWS_SECRET_ACCESS_KEY         "               "
11 #   LBS_S3_BUCKET           S3 bucket in which data should be stored
12 #   LBS_S3_PREFIX           Path prefix to add to pathnames (include trailing
13 #                               slash)
14 #
15 # This script depends upon the boto Python library for interacting with Amazon
16 # S3.
17
18 import os, sys
19 import boto
20 from boto.s3.bucket import Bucket
21 from boto.s3.key import Key
22
23 prefix = os.environ.get('LBS_S3_PREFIX', "")
24 bucket_name = os.environ['LBS_S3_BUCKET']
25 (local_path, file_type, remote_path) = sys.argv[1:4]
26
27 conn = boto.connect_s3()
28 bucket = Bucket(conn, bucket_name)
29 k = Key(bucket)
30 k.key = prefix + file_type + "/" + remote_path
31 k.set_contents_from_filename(local_path)