{"id":867,"date":"2015-06-22T14:53:50","date_gmt":"2015-06-22T12:53:50","guid":{"rendered":"http:\/\/sematext.solr.pl\/?p=867"},"modified":"2020-11-14T14:54:18","modified_gmt":"2020-11-14T13:54:18","slug":"solr-5-2-quick-look-on-solr-backup-functionality","status":"publish","type":"post","link":"https:\/\/solr.pl\/en\/2015\/06\/22\/solr-5-2-quick-look-on-solr-backup-functionality\/","title":{"rendered":"Solr 5.2: quick look on Solr backup functionality"},"content":{"rendered":"<p>With the lastest release of Solr &#8211; the <a href=\"http:\/\/solr.pl\/en\/2015\/06\/07\/lucene-solr-5-2\/\">5.2<\/a> and <a href=\"http:\/\/solr.pl\/en\/2015\/06\/15\/lucene-and-solr-5-2-1\/\">5.2.1<\/a> we were given the new API &#8211; the backup API based on the replication handler. Because this functionality has been anticipated by some users, we decided to give it a quick look.<\/p>\n\n\n<!--more-->\n\n\n<p>In order to test the new functionality we will do a very simple test:<\/p>\n<ol>\n<li>We will launch Solr in the SolrCloud mode,<\/li>\n<li>We will index a few documents,<\/li>\n<li>We will make the backup using the new API,<\/li>\n<li>We will index another few documents,<\/li>\n<li>Finally we will try to restore the backup done in step 3<\/li>\n<\/ol>\n<p>Let&#8217;s start.<\/p>\n<h3>Starting Solr<\/h3>\n<p>To start Solr in SolrCloud mode, we&#8217;ve used the <em>bin\/solr<\/em> script and we&#8217;ve used the following command:\n<\/p>\n<pre class=\"brush:xml\">bin\/solr -e cloud\n<\/pre>\n<p>For the purpose of the tests we need a single SolrCloud instance, with a single, empty collection (we will use the <em>gettingstarted<\/em> one provided with Solr) and a single shard.<\/p>\n<p>Our cluster topology looked as follows:<\/p>\n<p><a href=\"http:\/\/solr.pl\/wp-content\/uploads\/2015\/06\/Zrzut-ekranu-2015-06-21-o-11.13.31.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter  wp-image-3617\" src=\"http:\/\/solr.pl\/wp-content\/uploads\/2015\/06\/Zrzut-ekranu-2015-06-21-o-11.13.31.png\" alt=\"Zrzut ekranu 2015-06-21 o 11.13.31\" width=\"683\" height=\"36\"><\/a><\/p>\n<h3>Data indexation<\/h3>\n<p>Indexing data is as simple as starting Solr. Because we are using the example <em>gettingstarted<\/em> collection we can send documents without defined structure and Solr will adjust the <em>schema.xml<\/em> to what we need. So, for the purpose of the tests we will index two documents using the following command:\n<\/p>\n<pre class=\"brush:xml\">curl 'localhost:8983\/solr\/gettingstarted\/update?commit=true' -H 'Content-type:application\/xml' --data-binary '\n&lt;add&gt;\n &lt;doc&gt;\n  &lt;field name=\"id\"&gt;1&lt;\/field&gt;\n  &lt;field name=\"name\"&gt;Test document 1&lt;\/field&gt;\n &lt;\/doc&gt;\n &lt;doc&gt;\n  &lt;field name=\"id\"&gt;2&lt;\/field&gt;\n  &lt;field name=\"name\"&gt;Test document 2&lt;\/field&gt;\n &lt;\/doc&gt;\n&lt;\/add&gt;'\n<\/pre>\n<h3>Backup<\/h3>\n<p>Making a backup is again very simple. We just need to run the following command:\n<\/p>\n<pre class=\"brush:xml\">curl 'http:\/\/localhost:8983\/solr\/gettingstarted\/replication?command=backup&amp;name=test&amp;location=\/Users\/gro\/backup\/'\n<\/pre>\n<p>The above command tells Solr, that we want to make a backup of our collection called <em>snapshot.test<\/em> (Solr will add the value of the <em>name<\/em> parameter to the <em>snapshot.<\/em> prefix). The backup itself, will be created in the collection data directory by default &#8211; this is when we will not provide the desired directory using the <em>location<\/em> parameter. In our example, we&#8217;ve provided that parameter and use an absolute path to tell Solr where the backup should be placed.<\/p>\n<p>The response from Solr should be fast and look similar to the following one:\n<\/p>\n<pre class=\"brush:xml\">&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;\n&lt;response&gt;\n &lt;lst name=\"responseHeader\"&gt;&lt;int name=\"status\"&gt;0&lt;\/int&gt;&lt;int name=\"QTime\"&gt;2&lt;\/int&gt;&lt;\/lst&gt;&lt;str name=\"status\"&gt;OK&lt;\/str&gt;\n&lt;\/response&gt;\n<\/pre>\n<p>Of course, if our collection is large, the time needed to create backup will be significantly larger. We can check the status our the backup creation by running the following command:\n<\/p>\n<pre class=\"brush:xml\">curl 'http:\/\/localhost:8983\/solr\/gettingstarted\/replication?command=details'\n<\/pre>\n<h3>Next indexation<\/h3>\n<p>The next step of our simple test is another indexation &#8211; this time adding two new documents using the following command:\n<\/p>\n<pre class=\"brush:xml\">curl 'localhost:8983\/solr\/gettingstarted\/update?commit=true' -H 'Content-type:application\/xml' --data-binary '\n&lt;add&gt;\n &lt;doc&gt;\n  &lt;field name=\"id\"&gt;3&lt;\/field&gt;\n  &lt;field name=\"name\"&gt;Test document 3&lt;\/field&gt;\n &lt;\/doc&gt;\n &lt;doc&gt;\n  &lt;field name=\"id\"&gt;4&lt;\/field&gt;\n  &lt;field name=\"name\"&gt;Test document 4&lt;\/field&gt;\n &lt;\/doc&gt;\n&lt;\/add&gt;'\n<\/pre>\n<p>After the above command, if we would run a simple query like the following one:\n<\/p>\n<pre class=\"brush:xml\">curl 'localhost:8983\/solr\/gettingstarted\/select?q=*:*&amp;rows=0&amp;indent=true'\n<\/pre>\n<p>Solr should respond and inform us that we have four documents in total:\n<\/p>\n<pre class=\"brush:xml\">&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;\n&lt;response&gt;\n &lt;lst name=\"responseHeader\"&gt;\n  &lt;int name=\"status\"&gt;0&lt;\/int&gt;\n  &lt;int name=\"QTime\"&gt;6&lt;\/int&gt;\n  &lt;lst name=\"params\"&gt;\n   &lt;str name=\"q\"&gt;*:*&lt;\/str&gt;\n   &lt;str name=\"indent\"&gt;true&lt;\/str&gt;\n   &lt;str name=\"rows\"&gt;0&lt;\/str&gt;\n  &lt;\/lst&gt;\n &lt;\/lst&gt;\n &lt;result name=\"response\" numFound=\"4\" start=\"0\" maxScore=\"1.0\"&gt;\n &lt;\/result&gt;\n&lt;\/response&gt;\n<\/pre>\n<h3>Restoring our backup<\/h3>\n<p>Now let&#8217;s try restoring our backup and see how many documents we will have after that operation. To restore the bacup we&#8217;ve created we run the following command:\n<\/p>\n<pre class=\"brush:xml\">curl 'http:\/\/localhost:8983\/solr\/gettingstarted\/replication?command=restore&amp;name=test&amp;location=\/Users\/gro\/backup\/'\n<\/pre>\n<p>If everything went well, Solr response should be similar to the following one:\n<\/p>\n<pre class=\"brush:xml\">&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;\n&lt;response&gt;\n &lt;lst name=\"responseHeader\"&gt;&lt;int name=\"status\"&gt;0&lt;\/int&gt;&lt;int name=\"QTime\"&gt;2&lt;\/int&gt;&lt;\/lst&gt;&lt;str name=\"status\"&gt;OK&lt;\/str&gt;\n&lt;\/response&gt;\n<\/pre>\n<p>So let&#8217;s now check how many documents are present in our collection by running the following command:\n<\/p>\n<pre class=\"brush:xml\">curl 'localhost:8983\/solr\/gettingstarted\/select?q=*:*&amp;rows=0&amp;indent=true'\n<\/pre>\n<pre class=\"brush:xml\">&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;\n&lt;response&gt;\n &lt;lst name=\"responseHeader\"&gt;\n  &lt;int name=\"status\"&gt;0&lt;\/int&gt;\n  &lt;int name=\"QTime\"&gt;0&lt;\/int&gt;\n  &lt;lst name=\"params\"&gt;\n   &lt;str name=\"q\"&gt;*:*&lt;\/str&gt;\n   &lt;str name=\"indent\"&gt;true&lt;\/str&gt;\n   &lt;str name=\"rows\"&gt;0&lt;\/str&gt;\n  &lt;\/lst&gt;\n &lt;\/lst&gt;\n &lt;result name=\"response\" numFound=\"2\" start=\"0\"&gt;\n &lt;\/result&gt;\n&lt;\/response&gt;\n<\/pre>\n<p>As we can see, the number of documents in the collection is 2, which mean that our backup has been properly restored.<\/p>\n<h3>Short summary<\/h3>\n<p>As we can see, Solr backup mechanism works flawlessly, however we should remember about few things. When running a few Solr instances on the same physical machine, we should avoid doing backups using absolute paths &#8211; we can end up with shards data being overwritten. Apart from that, its good to finally have fully working and easy to use backup functionality \ud83d\ude42<\/p>","protected":false},"excerpt":{"rendered":"<p>With the lastest release of Solr &#8211; the 5.2 and 5.2.1 we were given the new API &#8211; the backup API based on the replication handler. Because this functionality has been anticipated by some users, we decided to give it<\/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":[590,488,164],"class_list":["post-867","post","type-post","status-publish","format-standard","hentry","category-solr-en","tag-5-2-2","tag-backup-2","tag-solr-2"],"_links":{"self":[{"href":"https:\/\/solr.pl\/en\/wp-json\/wp\/v2\/posts\/867","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=867"}],"version-history":[{"count":1,"href":"https:\/\/solr.pl\/en\/wp-json\/wp\/v2\/posts\/867\/revisions"}],"predecessor-version":[{"id":868,"href":"https:\/\/solr.pl\/en\/wp-json\/wp\/v2\/posts\/867\/revisions\/868"}],"wp:attachment":[{"href":"https:\/\/solr.pl\/en\/wp-json\/wp\/v2\/media?parent=867"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/solr.pl\/en\/wp-json\/wp\/v2\/categories?post=867"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/solr.pl\/en\/wp-json\/wp\/v2\/tags?post=867"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}