pythonsplunksplunk-querysplunk-sdk

How to migrate entire index data from one Splunk server to another Splunk server


I have a Splunk server with index data for 650k events. I want to migrate the entire data from one instance to another new instance. I tried using a migration script with data field -27D@d but I can only migrate 50k data. -27D@d is the point from where initial data is available. Can you please help me here? Here's the code :

import splunklib.client as client
import splunklib.results as results
import json
import requests

send_string = ""
service=client.connect(host="host1", port=8089,  username="admin", password="xxxx")
rr = results.ResultsReader(service.jobs.export('search index=my_index latest=-27D@d' ))
for result in rr:
    if isinstance(result, results.Message):
        continue
    elif isinstance(result, dict):
        final = dict(result)
        data = final['_raw']
        send_string = json.dumps({"event" : data,"source" : "test"},ensure_ascii=False).encode('utf8')
    url='http://host2:8088/services/collector'
    authHeader = {'Authorization': 'Splunk 5fbxxxx'}
    #Send data to Splunk
    response = requests.post(url, headers=authHeader, data=send_string, verify=False)
    if response.status_code == 200:
        print("Successfully pushed the data to Splunk source")
    else:
        print("Failed to push the data to Splunk source")

Solution

  • If index my_index does not exist on host2 then just copy the directory $SPLUNK_DB/my_index to host2, add my_index to indexes.conf, and restart Splunk.