{"id":2597,"date":"2021-07-01T08:00:54","date_gmt":"2021-07-01T06:00:54","guid":{"rendered":"https:\/\/possiblelossofprecision.net\/?p=2597"},"modified":"2021-11-12T01:07:43","modified_gmt":"2021-11-11T23:07:43","slug":"ldap-server-with-389ds-part-5-backup","status":"publish","type":"post","link":"https:\/\/possiblelossofprecision.net\/?p=2597","title":{"rendered":"LDAP server with 389ds: Part 5 \u2013 Backup"},"content":{"rendered":"<p>Now that our 389ds instance is fully configured and ready to go, let&#8217;s have a look at how to back it up and potentially restore it if a disaster occurs.<\/p>\n<p><!--more--><\/p>\n<h2>6. Creating a backup<\/h2>\n<p>To create a complete backup that allows us to restore the 389ds instance from scratch we need to take care about two things: Firstly, the directory server database, where all the information that makes up the DIT is stored. And secondly, the configuration directory <code>\/etc\/dirsrv\/slapd-INSTANCENAME\/<\/code> where additional files (such as certificates, keys and the <a href=\"https:\/\/ldapwiki.com\/wiki\/RootDSE\">Root Directory Server Agent Service Entry (RootDSE)<\/a> ldif file) are saved.<\/p>\n<p>The integrated backup mechanism of the 389 Directory Server takes care of the database:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\n# dsconf localhost backup create\r\nThe backup create task has finished successfully\r\n<\/pre>\n<p>instructs <code>dsconf<\/code> to create a database dump in <code>\/var\/lib\/dirsrv\/slapd-localhost\/bak\/<\/code>.<br \/>\nTo create a backup of the configuration directory we can simply tar it up:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\ntar caf config_slapd-localhost_$(date +%Y-%m-%d_%H-%M-%S).tar.gz \/etc\/dirsrv\/slapd-localhost\/\r\n<\/pre>\n<h2>7. Restoring a backup<\/h2>\n<h3>7.1. Creating a 389ds instance from scratch<\/h3>\n<p>If disaster struck and we have to create a new 389ds instance from scratch we can use an <em>inf answer file<\/em> just like we did in <a href=\"https:\/\/possiblelossofprecision.net\/?p=2519#2-create-an-instance\">part 1<\/a>:<\/p>\n<pre class=\"brush: plain; highlight: [3]; title: instance.inf; notranslate\" title=\"instance.inf\">\r\n&#x5B;general]\r\nfull_machine_name = ldap.example.com\r\nstart = False\r\n\r\n&#x5B;slapd]\r\ninstance_name = localhost\r\nroot_password = mysecret\r\nport = 389\r\nsecure_port = 636\r\nself_sign_cert = False\r\n\r\n&#x5B;backend-userroot]\r\nsample_entries = yes\r\nsuffix = dc=example,dc=com\r\n<\/pre>\n<p>The only difference is that we don&#8217;t want our instance to immediately start. Instead we&#8217;re going to restore the configuration directory and database first. Of course, you could also stop the instance manually after creation:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\ndscreate from-file instance.inf\r\nrm -rf \/etc\/dirsrv\/slapd-localhost\/*\r\ntar xvf config_slapd-localhost_2021-05-14_10-00-00.tar.gz -C \/\r\n<\/pre>\n<p>This takes care of the configuration directory.<br \/>\nThe database can be restored through <code>dsctl<\/code>. <\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\n# cp -a localhost-2021_05_14_10_00_00 \/var\/lib\/dirsrv\/slapd-localhost\/bak\/\r\n# dsctl localhost bak2db localhost-2021_05_14_10_00_00\r\nbak2db successful\r\n<\/pre>\n<p>One small caveat: The directory from which the database is restored <strong>has to reside<\/strong> in <code>\/var\/lib\/dirsrv\/slapd-INSTANCENAME\/bak\/<\/code>, otherwise <code>dsctl<\/code> will fail with the somewhat unhelpful error message <code>bak2db failed<\/code>.<\/p>\n<p>We can now start our successfully restored 389ds instance:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nsystemctl start dirsrv@localhost.service\r\n<\/pre>\n<h3>7.2. Only restoring the database while server is running<\/h3>\n<p>If you only want to restore the database (maybe because an object in the DIT was accidentally deleted) we don&#8217;t have to stop the server:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\ndsconf localhost backup restore localhost-2021_05_14_10_00_00\r\n<\/pre>\n<p>As before, the directory form which the database is restored has to reside in <code>\/var\/lib\/dirsrv\/slapd-INSTANCENAME\/bak\/<\/code>.<\/p>\n<p>There&#8217;s a lot more information on how to <a href=\"https:\/\/access.redhat.com\/documentation\/en-us\/red_hat_directory_server\/11\/html-single\/administration_guide\/index#backing_up_directory_server\">create<\/a> and <a href=\"https:\/\/access.redhat.com\/documentation\/en-us\/red_hat_directory_server\/11\/html-single\/administration_guide\/index#restoring_directory_server\">restore<\/a> backups in the <a href=\"https:\/\/access.redhat.com\/documentation\/en-us\/red_hat_directory_server\/11\/html-single\/administration_guide\/index\">RHDS11 documentation<\/a> but this should cover the basics.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Now that our 389ds instance is fully configured and ready to go, let&#8217;s have a look at how to back it up and potentially restore it if a disaster occurs.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[84,13,7,83],"class_list":["post-2597","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-389ds","tag-centos","tag-fedora","tag-ldap"],"_links":{"self":[{"href":"https:\/\/possiblelossofprecision.net\/index.php?rest_route=\/wp\/v2\/posts\/2597","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/possiblelossofprecision.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/possiblelossofprecision.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/possiblelossofprecision.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/possiblelossofprecision.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2597"}],"version-history":[{"count":19,"href":"https:\/\/possiblelossofprecision.net\/index.php?rest_route=\/wp\/v2\/posts\/2597\/revisions"}],"predecessor-version":[{"id":2713,"href":"https:\/\/possiblelossofprecision.net\/index.php?rest_route=\/wp\/v2\/posts\/2597\/revisions\/2713"}],"wp:attachment":[{"href":"https:\/\/possiblelossofprecision.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2597"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/possiblelossofprecision.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2597"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/possiblelossofprecision.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2597"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}