{"id":472,"date":"2012-08-13T23:51:12","date_gmt":"2012-08-13T21:51:12","guid":{"rendered":"http:\/\/sematext.solr.pl\/?p=472"},"modified":"2020-11-11T23:51:42","modified_gmt":"2020-11-11T22:51:42","slug":"backing-up-your-index","status":"publish","type":"post","link":"https:\/\/solr.pl\/en\/2012\/08\/13\/backing-up-your-index\/","title":{"rendered":"Backing Up Your Index"},"content":{"rendered":"<p>Did you ever wonder if you can create a backup of your index with the tools available in Solr ? For exmaple after every <em>commit<\/em> or <em>optimize<\/em> operation ? Or may you would like to create backups with the HTTP API call ? Lets see what possibilities Solr has to offer.<\/p>\n\n\n<!--more-->\n\n\n<h3>The Beginning<\/h3>\n<p>We decided to write about index backups even though this functionality is fairly simple. We noticed that many people tend to forget about this functionality, not only when it comes to Apache Solr. We hope that this blog entry, will help you remember about backup creation functionality, when you need it. But now, lets start from the beginning &#8211; before we started the tests, we looked at the directory where Solr keeps its indices and this is what we saw:\n<\/p>\n<pre class=\"brush:bash\">drwxrwxr-x 2 gr0 gr0 4096 2012-08-12 20:17 index\ndrwxrwxr-x 2 gr0 gr0 4096 2012-08-12 20:16 spellchecker<\/pre>\n<h3>Manual Backup<\/h3>\n<p>In order to create a backup of your index with the use of HTTP API you have to have replication handler configured. If you have it, then you need to send the <em>command<\/em> parameter with <em>backup<\/em> value to the master server replication handler, for example like this:\n<\/p>\n<pre class=\"brush:xml\">curl 'http:\/\/localhost:8983\/solr\/replication?command=backup'<\/pre>\n<p>The above will tell Solr to create a new backup of the current index. Lets now look how the directory where indices live looks like after running the above command:\n<\/p>\n<pre class=\"brush:bash\">drwxrwxr-x 2 gr0 gr0 4096 2012-08-12 20:18 index\ndrwxrwxr-x 2 gr0 gr0 4096 2012-08-12 20:19 snapshot.20120812201917\ndrwxrwxr-x 2 gr0 gr0 4096 2012-08-12 20:16 spellchecker<\/pre>\n<p>As you can see, there is a new directory created &#8211; <em>snapshot.20120812201917<\/em>. We can assume, that we got what we wanted \ud83d\ude42<\/p>\n<h3>Automatic Backup<\/h3>\n<p>In addition to manual backup creation, you can also configure Solr to create indices after <em>commit<\/em> or <em>optimize<\/em> operation. Please remember though, that if your index is changing rapidly it is usually a bad idea to create backup after each&nbsp;commit operation.&nbsp; But lets get back to automatic backups. In order to configure Solr to create backups for us, you need to add the following line to replication handler configuration:\n<\/p>\n<pre class=\"brush:xml\">&lt;str name=\"backupAfter\"&gt;commit&lt;\/str&gt;<\/pre>\n<p>So, the full replication handler configuration (on the <em>master<\/em> server) would look like this:\n<\/p>\n<pre class=\"brush:xml\">&lt;requestHandler name=\"\/replication\" &gt;\n &lt;lst name=\"master\"&gt;\n  &lt;str name=\"replicateAfter\"&gt;commit&lt;\/str&gt;\n  &lt;str name=\"replicateAfter\"&gt;startup&lt;\/str&gt;\n  &lt;str name=\"confFiles\"&gt;schema.xml,stopwords.txt&lt;\/str&gt;\n  &lt;str name=\"backupAfter\"&gt;commit&lt;\/str&gt;\n &lt;\/lst&gt;\n&lt;\/requestHandler&gt;<\/pre>\n<p>After sending two <em>commit<\/em> operation our dictionary with indices looks like this:\n<\/p>\n<pre class=\"brush:bash\">drwxrwxr-x 2 gr0 gr0 4096 2012-08-12 21:12 index\ndrwxrwxr-x 2 gr0 gr0 4096 2012-08-12 21:12 snapshot.20120812211203\ndrwxrwxr-x 2 gr0 gr0 4096 2012-08-12 21:12 snapshot.20120812211216\ndrwxrwxr-x 2 gr0 gr0 4096 2012-08-12 20:16 spellchecker<\/pre>\n<p>As you can see, Solr did what we wanted to be done.<\/p>\n<h3>Keeping Order<\/h3>\n<p>It is possible to control the maximum amount of backups that should be stored on disk. In order to configure that number you need to add the following line to your replication handler configuration:\n<\/p>\n<pre class=\"brush:xml\">&lt;str name=\"maxNumberOfBackups\"&gt;10&lt;\/str&gt;<\/pre>\n<p>The above configuration value tells Solr to keep maximum of ten backups of your index. Of course you can delete created backups (manually for example) if you don&#8217;t need them anymore.<\/p>","protected":false},"excerpt":{"rendered":"<p>Did you ever wonder if you can create a backup of your index with the tools available in Solr ? For exmaple after every commit or optimize operation ? Or may you would like to create backups with the HTTP<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":"","_links_to":"","_links_to_target":""},"categories":[27],"tags":[488,315,195,487],"class_list":["post-472","post","type-post","status-publish","format-standard","hentry","category-solr-en","tag-backup-2","tag-handler","tag-index-2","tag-replication"],"_links":{"self":[{"href":"https:\/\/solr.pl\/en\/wp-json\/wp\/v2\/posts\/472","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/solr.pl\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/solr.pl\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/solr.pl\/en\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/solr.pl\/en\/wp-json\/wp\/v2\/comments?post=472"}],"version-history":[{"count":1,"href":"https:\/\/solr.pl\/en\/wp-json\/wp\/v2\/posts\/472\/revisions"}],"predecessor-version":[{"id":473,"href":"https:\/\/solr.pl\/en\/wp-json\/wp\/v2\/posts\/472\/revisions\/473"}],"wp:attachment":[{"href":"https:\/\/solr.pl\/en\/wp-json\/wp\/v2\/media?parent=472"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/solr.pl\/en\/wp-json\/wp\/v2\/categories?post=472"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/solr.pl\/en\/wp-json\/wp\/v2\/tags?post=472"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}