Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Handy bits and bobs for recovering from a SolrCloud disaster
#!/usr/bin/bash
# We're only processing one solr collection named notices
for x in `seq 1 8`; do
curl "http://localhost:8983/solr/admin/cores?action=UNLOAD&core=notices_shard${x}_replica3
rm -rf /var/lib/solr/data/notices_shard${x}_replica3/*
mkdir -p /var/lib/solr/data/notices_shard${x}_replica3/data
mkdir -p /var/lib/solr/data/notices_shard${x}_replica3/tlog
scp -P 222 -r good_server:/mnt/solr/${date -I}/snapshot.notices_shard${x}_replica1 /var/lib/solr/data/notices_shard${x}_replica3/data/index
curl "http://localhost:8983/solr/admin/cores?schema=schema.xml&shard=shard${x}&instanceDir=notices_shard${x}_replica3&indexInfo=false&name=notices_shard8_replica3
&action=CREATE&config=solrconfig.xml&dataDir=data&collection=notices&wt=json"
done
#!/usr/bin/env ruby
# Backup the shards hosted on a solr node via solr's snapshots
# Run this as the solr user
require 'json'
require 'open-uri'
require 'fileutils'
FileUtils.mkdir_p(backup_path = "/mnt/solr/#{Date.today}")
solr_host = ENV["SOLR_HOST"] || "http://localhost:8983"
shards = JSON.parse(open("#{solr_host}/solr/admin/cores?action=status&wt=json").read)["status"].keys
shards.each do |shard|
print "\nBacking up #{shard} at #{Time.now} "
if !(result = JSON.parse(open("#{solr_host}/solr/#{shard}/replication?command=backup&location=#{backup_path}&name=#{shard}&wt=json").read))["exception"].nil?
puts result.inspect
next
end
sleep 10
until (result = JSON.parse(open("#{solr_host}/solr/#{shard}/replication?command=details&wt=json").read)) && result["details"] && result["details"]["backup"] && result["details"]["backup"][5] == "success" && Time.parse(result["details"]["backup"][1]) > Time.now - 3600 do
print "."
sleep 10
end
puts "\nDone at #{Time.now}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment