Learn how to perform Apache Solr backup and restore easily using real commands and examples for both SolrCloud and standalone modes. Our Live Support Team is always here to help you.

Simple Guide to Apache Solr Backup and Restore

Securing your Apache Solr data is one of those tasks you don’t think about until something goes wrong. A sudden crash, disk failure, or even a small misconfiguration can cost hours of rebuilding time. That’s why understanding Apache Solr backup and restore is essential for anyone managing a Solr instance. Let’s go through the exact process, no jargon just the real commands and steps that work.

apache solr backup and restore

Apache Solr Backup and Restore Overview

Solr gives you two approaches for creating backups and restoring them, depending on how you run it. If you’re running SolrCloud mode, you’ll be using the Collections API. On the other hand, if Solr runs in standalone mode, you’ll rely on the replication handler.

SolrCloud Backups

When Solr runs in SolrCloud mode, backups are handled through the Collections API. This method supports distributed environments, ensuring that the data across all shards is backed up and can be restored later with the same shard and replica structure.

There are two commands available for this purpose:

  • action=BACKUP: Creates a backup of Solr indexes and configurations.
  • action=RESTORE: Restores Solr indexes and configurations.

Before You Begin

Before starting the backup process in SolrCloud, there are a few critical points to keep in mind:

1. You need a file system mounted on all SolrCloud nodes.

2. It can be a simple NFS file system or distributed systems like GlusterFS or GPFS.

3. This shared location is required because the backup uses the Collection API to read data across multiple shards hosted on different nodes.

The backup image includes:

  • Data
  • Collection configuration
  • ZooKeeper configset

These are later used to restore the collection.

Backup Command

You can trigger a backup using the following command:

http://localhost:8983/solr/admin/collections?action=BACKUP&name=myBackupName&location=/path/to/my/shared/drive&collection=myCollectionName

Here’s a sample backup script that backs up all collections in a single SolrCloud instance:

curl 'http://localhost:8983/solr/admin/collections?action=BACKUP&name=myBackup2020-06-12&collection=books&location=/tmp/fake_shared_fs' -H 'Content-type:application/json'

Once completed, check the directory /tmp/fake_shared_fs, you’ll find the shards and ZooKeeper setup exported.

Checking Backup Status

To see if your backup operation has completed successfully, use the details command via the replication handler:

http://localhost:8983/solr/gettingstarted/replication?command=details

Example Output:

<lst name="backup">
<str name="startTime">Sun Apr 12 16:22:50 DAVT 2015</str>
<int name="fileCount">10</int>
<str name="status">success</str>
<str name="snapshotCompletedAt">Sun Apr 12 16:22:50 DAVT 2015</str>
<str name="snapshotName">my_backup</str>
</lst>

If there’s an issue, you’ll see a snapShootException in the response.

Restore Command

Restoring a backup in SolrCloud is just as straightforward. Use the following command:

http://localhost:8983/solr/admin/collections?action=RESTORE&name=myBackupName&location=/path/to/my/shared/drive&collection=myRestoredCollectionName

Here’s an example of restoring into a new collection:

curl 'http://localhost:8983/solr/admin/collections?action=RESTORE&name=myBackup2020-06-12&location=/tmp/fake_shared_fs&collection=restored_books' -H 'Content-type:application/json'

Checking Restore Status

To monitor the progress or completion of the restore, use this command:

http://localhost:8983/solr/gettingstarted/replication?command=restorestatus

Sample Output:

<response>
<lst name="responseHeader">
<int name="status">0</int>
<int name="QTime">0</int>
</lst>
<lst name="restorestatus">
<str name="snapshotName">snapshot.<name></str>
<str name="status">success</str>
</lst>
</response>

The status field will show one of three states, In Progress, success, or failed. If it fails, an exception field will appear with details.

Conclusion

Performing Apache Solr backup and restore isn’t just routine maintenance, it’s insurance for your data. With a shared file system and the right commands, you can safeguard your entire Solr environment. Remember, it’s always better to have a recent backup ready than to rebuild from scratch later.