Backup and Restore Solr Collection

Director, Sitecore Practice
  • Twitter
  • LinkedIn

Backup and Restore Solr Collection

Introduction

This blog will go through the necessary steps in backing up and restoring an active SolrCloud core in a Sitecore environment. Note that this is for informational purposes only; since all these steps are manually done, I recommend only as a last resort.

Find active collection

There are two ways to find the active collection. The first is to select the main alias in the collection dropdown in Solr and clicking on overview.

The second way is to check and see what Sitecore thinks the main alias in the core database is by querying the Properties table. The two should always match.

SELECT TOP (1000) [ID]
       ,[KEY]
       ,[VALUE]
 FROM [dbo].[Properties]
 where [KEY] like '%collection'

From both queries, we see that the active collection (i.e. the collection that is in the mainAlias) is sitecore_web_index.

Backup collection

To backup a Solr collection, you can utilize the Collections API. You can use postman or just visit the URL in a browser.

{baseUrl}/solr/admin/collections?action=BACKUP&name={name of backup}&collection={core name}&location=tmp

Example

https://mysolrinstance.com/solr/admin/collections?action=BACKUP&name=sitecore_web_index20221129&collection=sitecore_web_index&location=tmp

Restore collection

The approach we re going to take to restore a collection to the active slot is to first restore it to the rebuild alias and then swap. Restoring to the mainAlias is a multi-step process because of the following restrictions:

  • You cannot restore to a core that already exists
  • You cannot delete a core that has an alias
  • There is no swap command we must use two CREATEALIAS commands

To restore a Solr collection to the main alias:

1. Delete the RebuildAlias (this is so we can delete the core that is being used as rebuild)

/solr/admin/collections?action=DELETEALIAS&name=sitecore_web_indexRebuildAlias

make sure the name of your rebuild alias matches the one you configured

2, Delete the core that was RebuildAlias
It was a coincidence that my rebuild collection was _rebuild. If your rebuild collection was sitecore_web_index, place that instead.

/solr/admin/collections?action=DELETE&name=sitecore_web_index_rebuild

3. Restore your backup to the old rebuild core (which was just deleted)

/solr/admin/collections?action=RESTORE&name={name of backup}&collection=sitecore_web_index_rebuild&location=tmp

4. Recreate the RebuildAlias
Again, make sure the rebuildAlias and the collection is correct.

/solr/admin/collections?action=CREATEALIAS&name=sitecore_web_indexRebuildAlias&collections=sitecore_web_index_rebuild

5. Swap - there's no way to directly swap, so we have to do 2 create commands. We do not have to delete the Alias first and CreateAlias will repoint.

  • Set main alias to the rebuild core
/solr/admin/collections?action=CREATEALIAS&name=sitecore_web_indexMainAlias&collections=sitecore_web_indexRebuildAlias
  • Set rebuild alias to the previously active core
/solr/admin/collections?action=CREATEALIAS&name=sitecore_web_indexRebuildAlias&collections=sitecore_web_index

6. Confirm Aliases in Solr

/solr/admin/collections?action=LISTALIASES

7. Once we ve swapped in Solr, we ll need to update Sitecore so that it is aware of the swap. In SQL, first find the exact [Key] using the previous command

SELECT TOP (1000) [ID]
       ,[KEY]
       ,[VALUE]
 FROM [dbo].[Properties]
 where [KEY] like '%collection'

Then replace the appropriate [Value] and [Key] in the below script and execute to swap the two entries.

/*
  Set the active collection to match solr. Replace value with the correct collection and xxxx with your correct instance
*/
UPDATE [dbo].[Properties]
SET [Value] = 'sitecore_web_index_rebuild'
WHERE [KEY] = 'CORE_SITECORE_WEB_INDEX_XXXX_SOLR_ACTIVE_COLLECTION'

/*
  Set the rebuild collection to match solr. Replace value with the correct collection and xxxx with your correct instance
*/
UPDATE [dbo].[Properties]
SET [Value] = 'sitecore_web_index'
WHERE [KEY] = 'CORE_SITECORE_WEB_INDEX_XXXX_SOLR_REBUILD_COLLECTION'

After updating the DB, restart the CM server so that Sitecore gets the updated values.

Related Blogs

Latest Blogs