]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
1220. [func] Extended rndc dumpdb to support dumping of zones and
authorMark Andrews <marka@isc.org>
Thu, 13 Jun 2002 05:12:54 +0000 (05:12 +0000)
committerMark Andrews <marka@isc.org>
Thu, 13 Jun 2002 05:12:54 +0000 (05:12 +0000)
                        view selection: 'dumpdb [-all|-zones|-cache] [view]'.

CHANGES
bin/named/control.c
bin/named/include/named/server.h
bin/named/server.c

diff --git a/CHANGES b/CHANGES
index 46c5d7d923beed175c3d7fe3c46c998252f59b4e..42af1ee1a10163c98849c801c15c772a07681b22 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,6 @@
+1220.  [func]          Extended rndc dumpdb to support dumping of zones and
+                       view selection: 'dumpdb [-all|-zones|-cache] [view]'.
+
 1219.  [func]          New category 'update-security'.
 
 1218.  [port]          Compaq Trucluster support.
index 4061f816f88085a6e0c28ec7048702497bf9072f..5ff74b8d5d441d570f49451e445ac018d6f9122e 100644 (file)
@@ -15,7 +15,7 @@
  * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: control.c,v 1.12 2002/02/20 03:33:12 marka Exp $ */
+/* $Id: control.c,v 1.13 2002/06/13 05:12:51 marka Exp $ */
 
 #include <config.h>
 
@@ -103,7 +103,7 @@ ns_control_docommand(isccc_sexpr_t *message, isc_buffer_t *text) {
        } else if (command_compare(command, NS_COMMAND_QUERYLOG)) {
                result = ns_server_togglequerylog(ns_g_server);
        } else if (command_compare(command, NS_COMMAND_DUMPDB)) {
-               ns_server_dumpdb(ns_g_server);
+               ns_server_dumpdb(ns_g_server, command);
                result = ISC_R_SUCCESS;
        } else if (command_compare(command, NS_COMMAND_TRACE)) {
                result = ns_server_setdebuglevel(ns_g_server, command);
index d8f9379cc13f44e614d2a0eacf2e10e3652bf32b..26c3480dd69557abff1f1a2d2e13425cf674aa0f 100644 (file)
@@ -15,7 +15,7 @@
  * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: server.h,v 1.65 2002/02/20 03:33:33 marka Exp $ */
+/* $Id: server.h,v 1.66 2002/06/13 05:12:54 marka Exp $ */
 
 #ifndef NAMED_SERVER_H
 #define NAMED_SERVER_H 1
@@ -159,7 +159,7 @@ ns_server_dumpstats(ns_server_t *server);
  * Dump the current cache to the dump file.
  */
 isc_result_t
-ns_server_dumpdb(ns_server_t *server);
+ns_server_dumpdb(ns_server_t *server, char *args);
 
 /*
  * Change or increment the server debug level.
index 5092cf5b3099f6879d48db235da269dd7433bcca..fead20c07c7f647bcb7151417f239e1397106c53 100644 (file)
@@ -15,7 +15,7 @@
  * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: server.c,v 1.376 2002/05/08 04:45:40 marka Exp $ */
+/* $Id: server.c,v 1.377 2002/06/13 05:12:53 marka Exp $ */
 
 #include <config.h>
 
@@ -2761,23 +2761,80 @@ ns_server_dumpstats(ns_server_t *server) {
        return (result);
 }
 
+static isc_result_t
+printzone(dns_zone_t *zone, void *uap) {
+       FILE *fp = uap;
+       char buf[1024+32];
+       isc_result_t result;
+
+       dns_zone_name(zone, buf, sizeof(buf));
+       fprintf(fp, ";\n; Zone dump of '%s'\n;\n", buf);
+       result = dns_zone_dumptostream(zone, fp);
+       if (result == ISC_R_NOTIMPLEMENTED) {
+               fprintf(fp, "; %s\n", dns_result_totext(result));
+               result = ISC_R_SUCCESS;
+       }
+       return (result);
+}
+
 isc_result_t
-ns_server_dumpdb(ns_server_t *server) {
+ns_server_dumpdb(ns_server_t *server, char *args) {
        FILE *fp = NULL;
        dns_view_t *view;
        isc_result_t result;
+       isc_boolean_t zones = ISC_FALSE;
+       isc_boolean_t cache = ISC_TRUE;
+       char *ptr;
+       const char *sep;
 
        CHECKM(isc_stdio_open(server->dumpfile, "w", &fp),
               "could not open dump file");
 
+       /* Skip the command name. */
+       ptr = next_token(&args, " \t");
+       if (ptr == NULL)
+               return (ISC_R_UNEXPECTEDEND);
+
+       sep = (*args == '\0') ? "" : ": ";
+       isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
+                     NS_LOGMODULE_SERVER, ISC_LOG_INFO,
+                     "dumpdb started%s%s", sep, args);
+
+       ptr = next_token(&args, " \t");
+       if (ptr != NULL && strcmp(ptr, "-all") == 0) {
+               zones = ISC_TRUE;
+               cache = ISC_TRUE;
+               ptr = next_token(&args, " \t");
+       } else if (ptr != NULL && strcmp(ptr, "-cache") == 0) {
+               zones = ISC_FALSE;
+               cache = ISC_TRUE;
+               ptr = next_token(&args, " \t");
+       } else if (ptr != NULL && strcmp(ptr, "-zones") == 0) {
+               zones = ISC_TRUE;
+               cache = ISC_FALSE;
+               ptr = next_token(&args, " \t");
+       } 
+
        for (view = ISC_LIST_HEAD(server->viewlist);
             view != NULL;
             view = ISC_LIST_NEXT(view, link))
        {
-               if (view->cachedb != NULL)
+               if (ptr != NULL && strcmp(view->name, ptr) != 0)
+                       continue;
+               fprintf(fp, ";\n; Start view %s\n;\n", view->name);
+               if (cache && view->cachedb != NULL)
                        CHECKM(dns_view_dumpdbtostream(view, fp),
-                              "could not dump view databases");
-       }
+                              "could not dump cache");
+               if (zones && view->zonetable != NULL)
+                       CHECKM(dns_zt_apply(view->zonetable, ISC_TRUE,
+                                           printzone, fp),
+                              "could not dump zones");
+       }
+       fprintf(fp, "; Dump complete\n");
+       result = isc_stdio_flush(fp);
+       isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
+                     NS_LOGMODULE_SERVER, ISC_LOG_INFO,
+                     "dumpdb complete");
  cleanup:
        if (fp != NULL)
                (void)isc_stdio_close(fp);