3 # Cumulus: Efficient Filesystem Backup to the Cloud
4 # Copyright (C) 2008, 2010 The Cumulus Developers
5 # See the AUTHORS file for a list of contributors.
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License along
18 # with this program; if not, write to the Free Software Foundation, Inc.,
19 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 # Generic storage hook for writing LBS backups directly to Amazon's Simple
22 # Storage Service (S3), or any other service supported by the Python storage
25 # Storage protocol: After launching this script (with the remote location
26 # specified on the command-line), send any number of commands as lines to
27 # stdin. Available commands are:
28 # PUT <type> <name> <local file>
30 # Tokens are whitespace-separated, but may contain any characters by
31 # URI-encoding them. After completing each operation, a response line is
32 # written to stdout, which is either "OK" (for success) or "ERR" (if an error
35 import os, sys, traceback
37 # Automatically set Python path, based on script directory. This should be
38 # removed if the tools are properly installed somewhere.
39 script_directory = os.path.dirname(sys.argv[0])
40 sys.path.append(os.path.join(script_directory, 'python'))
43 from cumulus import store
45 remote = store.open(sys.argv[1])
47 cmd = sys.stdin.readline()
49 cmd = [cumulus.uri_decode(s) for s in cmd.strip().split()]
53 remote.put(cmd[1], cmd[2], open(cmd[3], 'r'))
54 sys.stdout.write('OK\n')
55 elif cmd[0] == 'LIST':
56 files = remote.list(cmd[1])
58 sys.stdout.write("* " + cumulus.uri_encode(f) + "\n")
59 sys.stdout.write('OK\n')
62 sys.stdout.write('ERR\n')