Created
July 13, 2010 05:05
-
-
Save statonjr/473476 to your computer and use it in GitHub Desktop.
Silly ruby script to replicate CouchDB databases
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
#!/usr/bin/env ruby | |
require 'optparse' | |
require 'rubygems' | |
require 'json' | |
options = {} | |
data = {} | |
optparse = OptionParser.new do |opts| | |
# Banner that displays at top of help screen | |
opts.banner = "Usage: replicate [options] source target" | |
# Define the options and what they do | |
options[:verbose] = false | |
opts.on('-v', '--verbose', 'Output response from CouchDB') do | |
options[:verbose] = true | |
end | |
options[:continuous] = false | |
opts.on('-c', '--continuous', 'Continuous replication') do | |
data[:continuous] = true | |
end | |
opts.on('-h', '--help', 'Display this screen') do | |
puts opts | |
exit | |
end | |
end | |
# Parse the command line arguments | |
# parse! removes the options | |
optparse.parse! | |
# Handle the ARGVs | |
data[:source] = ARGV[0] | |
data[:target] = ARGV[1] | |
# Need to figure out how to handle the result. Even if CouchDB returns {"ok":true} | |
# replication can still fail. | |
result = %x[curl --silent -X POST http://127.0.0.1:5984/_replicate -d '#{data.to_json}'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment