Permalink
Browse files

Trying to restore views, along with documents. Still not working for …

…views. Just docs
  • Loading branch information...
hardlifeofapo committed Aug 30, 2012
1 parent c4f2d9e commit 3f869e4f8e6dd4b9904842ba6289bed584d7d09f
Showing with 27 additions and 16 deletions.
  1. +3 −4 exporter.py
  2. +24 −12 restorer.py
View
@@ -23,8 +23,7 @@
SECRET_ACCESS_KEY = 'PRIVATE_KEY'
CB_BUCKET_NAME = 'default'
S3_BUCKET_NAME = 'buck_up'
-SERVER_NAME = '176.58.119.212'
-SERVER_PORT = '8091'
+SERVER_NAME = 'localhost'
class Exporter(object):
@@ -37,20 +36,20 @@ def __init__(self):
def run(self):
ini = int( time.time() )
url = '/usr/bin/curl http://%s:%s/%s/_all_docs?include_docs=true'% (SERVER_NAME, 8092, CB_BUCKET_NAME )
+ print url
p = subprocess.Popen(url, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
output, errors = p.communicate()
output = json.loads(output)
items = output['rows']
-
# Create does not create again a bucket if that bucket already exists.
s3_bucket = self.conn.create_bucket(self.s3BucketName)
for item in items:
k = Key(s3_bucket)
k.key = item["doc"]["_id"]
print "Saving %s" % (item["doc"]["_id"])
- # json.dumps is needed to prevent unicode representation of strings in python, like u'a_string'
+ # json.dumps is needed to prevent storage of python's unicode representation of strings, like u'a_string'
k.set_contents_from_string( json.dumps(item["doc"], sort_keys=True) )
fin = int( time.time() )
View
@@ -22,9 +22,9 @@
SECRET_ACCESS_KEY = 'PRIVATE_KEY'
CB_BUCKET_NAME = 'default'
S3_BUCKET_NAME = 'buck_up'
-SERVER_NAME = 'your_ip_goes_here'
+SERVER_NAME = 'your_server_ip_goes_here'
SERVER_PORT = '8091'
-USERNAME = 'your_couchbase_username' #couchbase username
+USERNAME = 'your_couchbase_user' #couchbase username
PASSWORD = 'your_couchbase_password' #couchbase password
@@ -50,17 +50,29 @@ def run(self):
rs = s3_bucket.list()
for key in rs:
- key = s3_bucket.get_key(key.name)
- contents = json.loads(key.get_contents_as_string())
+ key = s3_bucket.get_key(key.name)
+ contents = json.loads(key.get_contents_as_string())
- # See http://www.couchbase.com/issues/browse/MB-5302
- del(contents['_id'])
- del(contents['_rev'])
- del(contents['$flags'])
- del(contents['$expiration'])
- print "Restoring %s"%(str(key.key))
-
- self.cb_bucket[str(key.key)] = json.dumps(contents)
+ print contents
+
+ try:
+ # Try to restore a view. I have no idea on how to do this
+ design_doc = { "views": json.dumps(contents['views']) }
+ #print "design document"
+ #print design_doc
+ #print ""
+ # save a design document
+ #self.cb_bucket['_design/testing'] = json.dumps(design_doc)
+ except:
+ # See http://www.couchbase.com/issues/browse/MB-5302
+ del(contents['_id'])
+ del(contents['_rev'])
+ del(contents['$flags'])
+ del(contents['$expiration'])
+
+ print "Restoring document: %s"%(str(key.key))
+
+ self.cb_bucket[str(key.key)] = json.dumps(contents)
fin = int( time.time() )
total = (fin - ini) #in seconds

0 comments on commit 3f869e4

Please sign in to comment.