summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkopertop <kopertop@604d75c7-a419-0410-a38f-bde1a0bd1dbf>2009-06-15 17:45:29 +0000
committerkopertop <kopertop@604d75c7-a419-0410-a38f-bde1a0bd1dbf>2009-06-15 17:45:29 +0000
commit993152444aa1314a3716f62c7237c454e73b06a5 (patch)
treede45c149e4c2404ad7236738027bae3e444abfc6
parentc3bac148a3075ad2297e9ffc159b84b5de702c52 (diff)
downloadboto-993152444aa1314a3716f62c7237c454e73b06a5.tar.gz
Moved s3put to "bin" directory. Added a sdbadmin
utility that allows users to dump and recover SDB domains to XML files.
-rwxr-xr-xbin/s3put (renamed from s3put)0
-rwxr-xr-xbin/sdbadmin151
-rw-r--r--setup.py1
3 files changed, 152 insertions, 0 deletions
diff --git a/s3put b/bin/s3put
index 30340e8c..30340e8c 100755
--- a/s3put
+++ b/bin/s3put
diff --git a/bin/sdbadmin b/bin/sdbadmin
new file mode 100755
index 00000000..6df2048b
--- /dev/null
+++ b/bin/sdbadmin
@@ -0,0 +1,151 @@
+#!/usr/bin/env python
+# Copyright (c) 2009 Chris Moyer http://kopertop.blogspot.com/
+#
+# Permission is hereby granted, free of charge, to any person obtaining a
+# copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish, dis-
+# tribute, sublicense, and/or sell copies of the Software, and to permit
+# persons to whom the Software is furnished to do so, subject to the fol-
+# lowing conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
+# ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
+# SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+
+#
+# Tools to dump and recover an SDB domain
+#
+VERSION = "%prog version 1.0"
+import boto
+import time
+
+def choice_input(options, default=None, title=None):
+ """
+ Choice input
+ """
+ if title == None:
+ title = "Please choose"
+ print title
+ objects = []
+ for n, obj in enumerate(options):
+ print "%s: %s" % (n, obj)
+ objects.append(obj)
+ choice = int(raw_input(">>> "))
+ try:
+ choice = objects[choice]
+ except:
+ choice = default
+ return choice
+
+def confirm(message="Are you sure?"):
+ choice = raw_input("%s [yN] " % message)
+ return choice and len(choice) > 0 and choice[0].lower() == "y"
+
+
+def dump_db(domain, file_name):
+ """
+ Dump SDB domain to file
+ """
+ doc = domain.to_xml()
+ doc.writexml(open(file_name, "w"))
+
+def empty_db(domain):
+ """
+ Remove all entries from domain
+ """
+ for item in domain:
+ item.delete()
+
+def load_db(domain, file):
+ """
+ Load a domain from a file, this doesn't overwrite any existing
+ data in the file so if you want to do a full recovery and restore
+ you need to call empty_db before calling this
+
+ @param domain: The SDB Domain object to load to
+ @param file: The File to load the DB from
+ """
+ domain.from_xml(file)
+
+if __name__ == "__main__":
+ from optparse import OptionParser
+ parser = OptionParser(version=VERSION, usage="Usage: %prog [--dump|--load|--empty|--list|-l] [options]")
+
+ # Commands
+ parser.add_option("--dump", help="Dump domain to file", dest="dump", default=False, action="store_true")
+ parser.add_option("--load", help="Load domain contents from file", dest="load", default=False, action="store_true")
+ parser.add_option("--empty", help="Empty all contents of domain", dest="empty", default=False, action="store_true")
+ parser.add_option("-l", "--list", help="List All domains", dest="list", default=False, action="store_true")
+
+ parser.add_option("-a", "--all-domains", help="Operate on all domains", action="store_true", default=False, dest="all_domains")
+ parser.add_option("-d", "--domain", help="Do functions on domain (may be more then one)", action="append", dest="domains")
+ parser.add_option("-f", "--file", help="Input/Output file we're operating on", dest="file_name")
+
+ (options, args) = parser.parse_args()
+
+ sdb = boto.connect_sdb()
+
+ if not options.dump and not options.load and not options.empty and not options.list:
+ parser.print_help()
+ exit()
+
+ if options.list:
+ for db in sdb.get_all_domains():
+ print db
+ exit()
+
+ #
+ # Setup
+ #
+ if options.domains:
+ domains = []
+ for domain_name in options.domains:
+ domains.append(sdb.get_domain(domain_name))
+ elif options.all_domains:
+ domains = sdb.get_all_domains()
+ else:
+ domains = [choice_input(options=sdb.get_all_domains(), title="No domain specified, please choose one")]
+
+
+ #
+ # Execute the commands
+ #
+ stime = time.time()
+ if options.empty:
+ if confirm("WARNING!!! Are you sure you want to empty the following domains?: %s" % domains):
+ stime = time.time()
+ for domain in domains:
+ print "--------> Emptying %s <--------" % domain.name
+ empty_db(domain)
+ else:
+ print "Canceling operations"
+ exit()
+
+ if options.dump:
+ for domain in domains:
+ print "--------> Dumping %s <---------" % domain.name
+ if options.file_name:
+ file_name = options.file_name
+ else:
+ file_name = "%s.db" % domain.name
+ dump_db(domain, file_name)
+
+ if options.load:
+ for domain in domains:
+ print "---------> Loading %s <----------" % domain.name
+ if options.file_name:
+ file_name = options.file_name
+ else:
+ file_name = "%s.db" % domain.name
+ load_db(open(file_name, "rb"), domain)
+
+
+ total_time = round(time.time() - stime, 2)
+ print "--------> Finished in %s <--------" % total_time
diff --git a/setup.py b/setup.py
index b73a9459..46faf7aa 100644
--- a/setup.py
+++ b/setup.py
@@ -34,6 +34,7 @@ setup(name = "boto",
long_description="Python interface to Amazon's Web Services.",
author = "Mitch Garnaat",
author_email = "mitch@garnaat.com",
+ scripts = ["bin/sdbadmin", "bin/s3put"],
url = "http://code.google.com/p/boto/",
packages = [ 'boto', 'boto.sqs', 'boto.s3', 'boto.ec2', 'boto.sdb',
'boto.sdb.persist', 'boto.sdb.db', 'boto.sdb.db.manager',