3 # Generic storage hook for writing LBS backups directly to Amazon's Simple
4 # Storage Service (S3), or any other service supported by the Python storage
7 # Storage protocol: After launching this script (with the remote location
8 # specified on the command-line), send any number of commands as lines to
9 # stdin. Available commands are:
10 # PUT <type> <name> <local file>
12 # Tokens are whitespace-separated, but may contain any characters by
13 # URI-encoding them. After completing each operation, a response line is
14 # written to stdout, which is either "OK" (for success) or "ERR" (if an error
17 import os, sys, traceback
19 # Automatically set Python path, based on script directory. This should be
20 # removed if the tools are properly installed somewhere.
21 script_directory = os.path.dirname(sys.argv[0])
22 sys.path.append(os.path.join(script_directory, 'python'))
25 from cumulus import store
27 remote = store.open(sys.argv[1])
29 cmd = sys.stdin.readline()
31 cmd = [cumulus.uri_decode(s) for s in cmd.strip().split()]
35 remote.put(cmd[1], cmd[2], open(cmd[3], 'r'))
36 sys.stdout.write('OK\n')
37 elif cmd[0] == 'LIST':
38 files = remote.list(cmd[1])
40 sys.stdout.write("* " + cumulus.uri_encode(f) + "\n")
41 sys.stdout.write('OK\n')
44 sys.stdout.write('ERR\n')