Skip to content

Instantly share code, notes, and snippets.

@cwilper
Last active December 23, 2015 15:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cwilper/d594491c1dad6d901b0c to your computer and use it in GitHub Desktop.
Save cwilper/d594491c1dad6d901b0c to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# Dumps a subset of one Solr core and loads it into another one.
#
# WARNING: THIS DUMP AND LOAD IS LOSSY -- DO NOT USE IT FOR BACKUPS!
# In particular, multi-valued fields won't import in the target exactly as they were in the source.
#
# Before running, change the variables below as needed for your task.
#
# Set these as appropriate for your dump and load task
SOURCE_URL="http://localhost:8080/solr/core1"
TARGET_URL="http://localhost:8080/solr/core2"
ENCODED_QUERY="*%3A*"
ROWS=100
# Determine list of field names to dump
FIELDS=$(curl -s "$SOURCE_URL/select?q=$ENCODED_QUERY&fl=*&wt=csv&rows=0" | sed 's/,_version_,/,/' | sed 's/,_version_//' | sed 's/_version_,//')
# Dump the results of the query as csv, without _version_
curl -s "$SOURCE_URL/select?q=$ENCODED_QUERY&fl=$FIELDS&wt=csv&rows=$ROWS" > /tmp/solr-dump.csv
# Import the dump into the other solr core
curl "$TARGET_URL/update/csv?commit=true" --data-binary @/tmp/solr-dump.csv -H 'Content-type:text/plain; charset=utf-8'
# Finally, remove the dump file
rm /tmp/solr-dump.csv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment