#!/usr/bin/python # # Cumulus: Efficient Filesystem Backup to the Cloud # Copyright (C) 2008, 2010 The Cumulus Developers # See the AUTHORS file for a list of contributors. # # 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., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # Generic storage hook for writing LBS backups directly to Amazon's Simple # Storage Service (S3), or any other service supported by the Python storage # implementation. # # Storage protocol: After launching this script (with the remote location # specified on the command-line), send any number of commands as lines to # stdin. Available commands are: # PUT # LIST # Tokens are whitespace-separated, but may contain any characters by # URI-encoding them. After completing each operation, a response line is # written to stdout, which is either "OK" (for success) or "ERR" (if an error # occurred). import os, sys, traceback # Automatically set Python path, based on script directory. This should be # removed if the tools are properly installed somewhere. script_directory = os.path.dirname(sys.argv[0]) sys.path.append(os.path.join(script_directory, 'python')) import cumulus from cumulus import store remote = store.open(sys.argv[1]) while True: cmd = sys.stdin.readline() if cmd == "": break cmd = [cumulus.uri_decode(s) for s in cmd.strip().split()] try: if cmd[0] == 'PUT': remote.put(cmd[1], cmd[2], open(cmd[3], 'r')) sys.stdout.write('OK\n') elif cmd[0] == 'LIST': files = remote.list(cmd[1]) for f in files: sys.stdout.write("* " + cumulus.uri_encode(f) + "\n") sys.stdout.write('OK\n') except Exception: traceback.print_exc() sys.stdout.write('ERR\n') sys.stdout.flush() remote.close()