Skip to content

Commit

Permalink
MB-15599: Interpret current directory as abs path
Browse files Browse the repository at this point in the history
Change-Id: Idffe186238ec0cc2a3f151423ca4ecefbaa64c30
Reviewed-on: http://review.couchbase.org/52983
Reviewed-by: Bin Cui <bin.cui@gmail.com>
Tested-by: Bin Cui <bin.cui@gmail.com>
  • Loading branch information
Bin Cui authored and bcui6611 committed Jul 10, 2015
1 parent c353ecf commit 4945905
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 21 deletions.
20 changes: 11 additions & 9 deletions cbbackupwrapper
Expand Up @@ -144,7 +144,7 @@ def findAllVbucketsForBucket(node, bucket, path, port, restport, username, passw
response = urllib2.urlopen(request)
except:
print('Authorization failed. Please check username and password.')
exit(1)
sys.exit(1)
data = json.loads(response.read())
vbucketserverdata = data['vBucketServerMap']
vbucketdata = vbucketserverdata['vBucketMap']
Expand Down Expand Up @@ -187,7 +187,7 @@ def findAllVbucketsForBucket(node, bucket, path, port, restport, username, passw
if serverindex == -1:
print serverindex
print 'Could not find node:port in server list.'
exit(1)
sys.exit(1)

if single_node:
# iterate through all vbuckets and see which are active on this node
Expand Down Expand Up @@ -215,7 +215,7 @@ def getBuckets(node, rest_port, username, password):
response = urllib2.urlopen(request)
except:
print('Authorization failed. Please check username and password.')
exit(1)
sys.exit(1)
bucketsOnCluster = []
data = json.loads(response.read())
for item in data:
Expand Down Expand Up @@ -249,22 +249,24 @@ if __name__ == '__main__':
# Remove any white-spaces from start and end of strings
backupDir = backupDir.strip()
path = args.path.strip()
if path == ".":
path = os.path.abspath(path)

# Check to see if root backup directory exists
if not os.path.isdir(backupDir):
try:
os.makedirs(backupDir)
except:
exit("Cannot create backup root directory:%s" % backupDir)
sys.exit("Cannot create backup root directory:%s" % backupDir)

# Check to see if path is correct
if not os.path.isdir(path):
print 'The path to cbbackup does not exist'
print 'Please run with a different path'
exit(1)
sys.exit(1)
if not os.path.isfile(os.path.join(path, 'cbbackup')):
print 'cbbackup could not be found in ' + path
exit(1)
sys.exit(1)

# Check to see if log directory exists if not create it
dir = os.path.join(backupDir, 'logs')
Expand All @@ -275,7 +277,7 @@ if __name__ == '__main__':
os.mkdir(dir)
except:
print('Error trying to create directory ' + dir)
exit(1)
sys.exit(1)

# Separate out node and REST port
matchObj = re.match(r'^http://(.*):(\d+)$', cluster, re.I)
Expand All @@ -285,7 +287,7 @@ if __name__ == '__main__':
else:
print("Please enter the source as http://hostname:port")
print("For example http://localhost:8091 or http://127.0.0.1:8091")
exit(1)
sys.exit(1)

# Check to see if backing-up all buckets or just a specified bucket
if args.bucket_source == '':
Expand All @@ -300,7 +302,7 @@ if __name__ == '__main__':
if len(bucketList) == 0:
print 'Bucket ' + args.bucket_source + ' does not exist'
print 'Please enter a different bucket'
exit(1)
sys.exit(1)

# For each bucket
for item in bucketList:
Expand Down
24 changes: 12 additions & 12 deletions cbrestorewrapper
Expand Up @@ -87,7 +87,7 @@ def getBuckets(node, rest_port, username, password):
response = urllib2.urlopen(request)
except:
print('Authorization failed. Please check username and password.')
exit(1)
sys.exit(1)
bucketsOnCluster = []
data = json.loads(response.read())
for item in data:
Expand Down Expand Up @@ -116,15 +116,15 @@ if __name__ == '__main__':
if not os.path.isdir(backupDir):
print '\n\nThe directory ' + backupDir + ' does not exist'
print 'Please enter a different backup directory\n'
exit(1)
sys.exit(1)
# Check to see if path is correct
if not os.path.isdir(path):
print 'The path to cbrestore does not exist'
print 'Please run with a different path'
exit(1)
sys.exit(1)
if not os.path.isfile(os.path.join(path, 'cbrestore')):
print 'cbrestore could not be found in ' + path
exit(1)
sys.exit(1)

# Check to see if log directory exists if not create it
dir = os.path.join(backupDir, 'logs')
Expand All @@ -135,7 +135,7 @@ if __name__ == '__main__':
os.mkdir(dir)
except:
print('Error trying to create directory ' + dir)
exit(1)
sys.exit(1)

# Separate out node and REST port
matchObj = re.match(r'^http://(.*):(\d+)$', cluster, re.I)
Expand All @@ -145,13 +145,13 @@ if __name__ == '__main__':
else:
print("Please enter the destination as http://hostname:port")
print("For example http://localhost:8091 or http://127.0.0.1:8091")
exit(1)
sys.exit(1)

# Check to see if restoring all buckets or just a specified bucket
if args.bucket_source == '':
if not args.bucket_destination == '':
print 'please specify a bucket_source'
exit(1)
sys.exit(1)
bucketList = getBuckets(
node, rest, args.username, args.password)
else:
Expand All @@ -167,7 +167,7 @@ if __name__ == '__main__':
if len(bucketList) == 0:
print 'Bucket ' + bucket_target + ' does not exist'
print 'Please enter a different bucket'
exit(1)
sys.exit(1)

# Handle the case when path has spaces
if os.name == 'nt':
Expand All @@ -190,12 +190,12 @@ if __name__ == '__main__':
vbucketList = getVbucketsToRestore(backupDir, args.bucket_source.strip())
if len(vbucketList) == 0:
print 'Error reading source backup vBuckets for bucket', args.bucket_source.strip()
exit(1)
sys.exit(1)
else:
vbucketList = getVbucketsToRestore(backupDir, bucket)
if len(vbucketList) == 0:
print 'Error reading source backup vBuckets for bucket', bucket
exit(1)
sys.exit(1)
for vbuckets in vbucketList:
# Invoke cbrestore on each of the active vbuckets that reside on
# the node
Expand Down Expand Up @@ -224,7 +224,7 @@ if __name__ == '__main__':
print 'Did not restore anything'
print 'Please check that the backup directory contains data to restore'
print 'Also please check that you have the correct buckets created on ' + args.node
exit(1)
sys.exit(1)
else:
print 'Waiting for the restore to complete...'
successCount = 0
Expand All @@ -241,4 +241,4 @@ if __name__ == '__main__':
print 'SUCCESSFULLY COMPLETED!'
else:
print 'ERROR!'
exit(1)
sys.exit(1)

0 comments on commit 4945905

Please sign in to comment.