Created
June 3, 2015 10:19
-
-
Save abhi-bit/b9b8a5eb75235a2195ba to your computer and use it in GitHub Desktop.
cbbackup wrapper to back up vbuckets in batches
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import argparse | |
import gevent | |
from gevent.subprocess import Popen | |
vbucket_count = 1024 | |
backup_script = "/opt/couchbase/bin/cbbackup" | |
parser = argparse.ArgumentParser(description="cbbackup wrapper to back up vbuckets in batches") | |
parser.add_argument('-b', action='store', dest='batch_size', type=int, | |
help='Number of vbuckets to back up parallely') | |
parser.add_argument('-u', action='store', dest='username', | |
help='Username') | |
parser.add_argument('-p', action='store', dest='password', | |
help='Password') | |
parser.add_argument('-n', action='store', dest='cluster', | |
help='Cluster url. Ex: http://localhost:8091') | |
parser.add_argument('-d', action='store', dest='backup_dir', | |
help='Backup dir') | |
results = parser.parse_args() | |
def backup(vbucket_id): | |
command = backup_script + ' ' + results.cluster + ' ' + results.backup_dir + \ | |
' -i ' + str(vbucket_id) + ' -u ' + results.username + \ | |
' -p ' + results.password | |
proc = Popen(command, shell=True) | |
output, err = proc.communicate() | |
def vbucket_mapping(gid): | |
workers = [] | |
start_index = gid * (results.batch_size) | |
end_index = (gid + 1) * (results.batch_size) | |
if (end_index < vbucket_count): | |
vbucket_list = [id for id in xrange(start_index, end_index )] | |
for vbucket_id in vbucket_list: | |
workers.append(gevent.spawn(backup, vbucket_id)) | |
gevent.joinall(workers) | |
else: | |
vbucket_list = [id for id in xrange(start_index, vbucket_count)] | |
for vbucket_id in vbucket_list: | |
workers.append(gevent.spawn(backup, vbucket_id)) | |
gevent.joinall(workers) | |
print vbucket_list | |
if __name__ == "__main__": | |
if (vbucket_count % results.batch_size) == 0: | |
for id in range(vbucket_count/results.batch_size): | |
vbucket_mapping(id) | |
else: | |
for id in range(vbucket_count/results.batch_size + 1): | |
vbucket_mapping(id) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment