浏览代码

Bug 194531 - db2bak is too noisy

https://bugzilla.redhat.com/show_bug.cgi?id=194531

Description: Introduced "-q" option to suppress the backing up/
restoring message for each db file.
  Usage: db2bak [archivedir] [-q] [-h]
  Usage: bak2db archivedir [-n backendname] [-q] | [-h]
If "-q" is specified, the verbose messages are not prited to
the standard error, but just to the errors log.

In addition, new log level SLAPI_LOG_BACKLDBM/LDAP_DEBUG_BACKLDBM
has been introduced.
Noriko Hosoi 15 年之前
父节点
当前提交
9f07f9d751

+ 23 - 11
ldap/admin/src/scripts/template-bak2db.in

@@ -12,21 +12,38 @@ export LD_LIBRARY_PATH
 SHLIB_PATH=$LD_LIBRARY_PATH
 SHLIB_PATH=$LD_LIBRARY_PATH
 export SHLIB_PATH
 export SHLIB_PATH
 
 
-if [ $# -lt 1 ] || [ $# -gt 3 ]
+if [ $# -lt 1 ] || [ $# -gt 6 ]
 then
 then
-    echo "Usage: bak2db archivedir [-n backendname]"
+    echo "Usage: bak2db archivedir [-n backendname] [-q] | [-h]"
     exit 1
     exit 1
+elif [ "$1" = "-h" ]
+then
+    echo "Usage: bak2db archivedir [-n backendname] [-q] | [-h]"
+    exit 0
 else
 else
     archivedir=$1
     archivedir=$1
     shift
     shift
 fi
 fi
-while getopts "n:" flag
+benameopt=""
+dlevel=0
+quiet=0
+while getopts "hn:qd:" flag
 do
 do
     case $flag in
     case $flag in
-        n) bename=$OPTARG;;
-        *) echo "Usage: bak2db archivedir [-n backendname]"; exit 2;;
+        h) echo "Usage: bak2db archivedir [-n backendname] [-q] | [-h]"
+           exit 1;;
+        n) benameopt="-n $OPTARG";;
+        q) quiet=1;;
+        d) dlevel=$OPTARG;;
     esac
     esac
 done
 done
+if [ $quiet -eq 0 ]
+then
+  if [ $dlevel -ne 524288 ]
+  then
+    dlevel=`expr $dlevel + 524288`
+  fi
+fi
 
 
 if [ 1 = `expr $archivedir : "\/"` ]
 if [ 1 = `expr $archivedir : "\/"` ]
 then
 then
@@ -37,9 +54,4 @@ else
 fi
 fi
 
 
 cd {{SERVERBIN-DIR}}
 cd {{SERVERBIN-DIR}}
-if [ "$#" -eq 2 ]
-then
-    ./ns-slapd archive2db -D {{CONFIG-DIR}} -a $archivedir -n $bename
-else
-    ./ns-slapd archive2db -D {{CONFIG-DIR}} -a $archivedir
-fi
+./ns-slapd archive2db -D {{CONFIG-DIR}} -a $archivedir $benameopt -d $dlevel

+ 33 - 5
ldap/admin/src/scripts/template-db2bak.in

@@ -12,13 +12,41 @@ export LD_LIBRARY_PATH
 SHLIB_PATH=$LD_LIBRARY_PATH
 SHLIB_PATH=$LD_LIBRARY_PATH
 export SHLIB_PATH
 export SHLIB_PATH
 
 
+if [ $# -gt 4 ]
+then
+    echo "Usage: db2bak [archivedir] [-q] [-h]"
+    exit 1
+fi
+
+bak_dir={{BAK-DIR}}/{{SERV-ID}}-`date +%Y_%m_%d_%H_%M_%S`
+dlevel=0
+quiet=0
 cd {{SERVERBIN-DIR}}
 cd {{SERVERBIN-DIR}}
-if [ "$#" -eq 1 ]
+if [ "$#" -gt 0 ]
+then
+  if [ "$1" != "-q" ] && [ "$1" != "-d" ] && [ "$1" != "-h" ]
+  then
+    bak_dir=$1
+    shift
+  fi
+  while getopts "hqd:" flag
+  do
+    case $flag in
+        h) echo "Usage: db2bak [archivedir] [-q] [-h]"
+           exit 0;;
+        q) quiet=1;;
+        d) dlevel=$OPTARG;;
+    esac
+  done
+fi
+# If not quiet, set LDAP_DEBUG_BACKLDBM to debug level
+if [ $quiet -eq 0 ]
 then
 then
-	bak_dir=$1
-else
-	bak_dir={{BAK-DIR}}/{{SERV-ID}}-`date +%Y_%m_%d_%H_%M_%S`
+  if [ $dlevel -ne 524288 ]
+  then
+    dlevel=`expr $dlevel + 524288`
+  fi
 fi
 fi
 
 
 echo "Back up directory: $bak_dir"
 echo "Back up directory: $bak_dir"
-./ns-slapd db2archive -D {{CONFIG-DIR}} -a $bak_dir
+./ns-slapd db2archive -D {{CONFIG-DIR}} -a $bak_dir -d $dlevel

+ 1 - 0
ldap/include/ldaplog.h

@@ -66,6 +66,7 @@ extern "C" {
 #define LDAP_DEBUG_PLUGIN	0x10000		/* 65536 */
 #define LDAP_DEBUG_PLUGIN	0x10000		/* 65536 */
 #define LDAP_DEBUG_TIMING	0x20000		/*131072 */
 #define LDAP_DEBUG_TIMING	0x20000		/*131072 */
 #define LDAP_DEBUG_ACLSUMMARY	0x40000		/*262144 */
 #define LDAP_DEBUG_ACLSUMMARY	0x40000		/*262144 */
+#define LDAP_DEBUG_BACKLDBM		0x80000		/*524288 */
 
 
 #define LDAP_DEBUG_ALL_LEVELS	0xFFFFF
 #define LDAP_DEBUG_ALL_LEVELS	0xFFFFF
 
 

+ 17 - 17
ldap/servers/slapd/back-ldbm/ldbm_entryrdn.c

@@ -245,7 +245,7 @@ entryrdn_index_entry(backend *be,
             rc = LDAP_INVALID_DN_SYNTAX;
             rc = LDAP_INVALID_DN_SYNTAX;
             goto bail;
             goto bail;
         } else if (rc > 0) {
         } else if (rc > 0) {
-            slapi_log_error(SLAPI_LOG_TRACE, ENTRYRDN_TAG,
+            slapi_log_error(SLAPI_LOG_BACKLDBM, ENTRYRDN_TAG,
                             "entryrdn_index_entry: %s does not belong to "
                             "entryrdn_index_entry: %s does not belong to "
                             "the db\n", slapi_sdn_get_dn(sdn));
                             "the db\n", slapi_sdn_get_dn(sdn));
             rc = DB_NOTFOUND;
             rc = DB_NOTFOUND;
@@ -335,7 +335,7 @@ entryrdn_index_read(backend *be,
         rc = LDAP_INVALID_DN_SYNTAX;
         rc = LDAP_INVALID_DN_SYNTAX;
         goto bail;
         goto bail;
     } else if (rc > 0) {
     } else if (rc > 0) {
-        slapi_log_error(SLAPI_LOG_TRACE, ENTRYRDN_TAG,
+        slapi_log_error(SLAPI_LOG_BACKLDBM, ENTRYRDN_TAG,
                         "entryrdn_index_read: %s does not belong to the db\n",
                         "entryrdn_index_read: %s does not belong to the db\n",
                         slapi_sdn_get_dn(sdn));
                         slapi_sdn_get_dn(sdn));
         rc = DB_NOTFOUND;
         rc = DB_NOTFOUND;
@@ -346,7 +346,7 @@ entryrdn_index_read(backend *be,
     rc = _entryrdn_open_index(be, &ai, &db);
     rc = _entryrdn_open_index(be, &ai, &db);
     if (rc) {
     if (rc) {
         slapi_log_error(SLAPI_LOG_FATAL, ENTRYRDN_TAG,
         slapi_log_error(SLAPI_LOG_FATAL, ENTRYRDN_TAG,
-                        "entryrdn_index_read:: Opening the index failed: "
+                        "entryrdn_index_read: Opening the index failed: "
                         "%s(%d)\n",
                         "%s(%d)\n",
                         rc<0?dblayer_strerror(rc):"Invalid parameter", rc);
                         rc<0?dblayer_strerror(rc):"Invalid parameter", rc);
         goto bail;
         goto bail;
@@ -455,8 +455,8 @@ entryrdn_rename_subtree(backend *be,
         rc = LDAP_INVALID_DN_SYNTAX;
         rc = LDAP_INVALID_DN_SYNTAX;
         goto bail;
         goto bail;
     } else if (rc > 0) {
     } else if (rc > 0) {
-        slapi_log_error(SLAPI_LOG_TRACE, ENTRYRDN_TAG,
-                        "entryrdn_rename_subtree:: %s does not belong to "
+        slapi_log_error(SLAPI_LOG_BACKLDBM, ENTRYRDN_TAG,
+                        "entryrdn_rename_subtree: %s does not belong to "
                         "the db\n", slapi_sdn_get_dn(oldsdn));
                         "the db\n", slapi_sdn_get_dn(oldsdn));
         rc = DB_NOTFOUND;
         rc = DB_NOTFOUND;
         goto bail;
         goto bail;
@@ -497,7 +497,7 @@ entryrdn_rename_subtree(backend *be,
             goto bail;
             goto bail;
         } else {
         } else {
             /* newsupsdn == NULL, so newsrdn is not */
             /* newsupsdn == NULL, so newsrdn is not */
-            slapi_log_error(SLAPI_LOG_TRACE, ENTRYRDN_TAG,
+            slapi_log_error(SLAPI_LOG_BACKLDBM, ENTRYRDN_TAG,
                         "entryrdn_rename_subtree: Renaming suffix %s to %s\n",
                         "entryrdn_rename_subtree: Renaming suffix %s to %s\n",
                         nrdn, slapi_rdn_get_nrdn((Slapi_RDN *)mynewsrdn));
                         nrdn, slapi_rdn_get_nrdn((Slapi_RDN *)mynewsrdn));
         }
         }
@@ -546,8 +546,8 @@ entryrdn_rename_subtree(backend *be,
             rc = LDAP_INVALID_DN_SYNTAX;
             rc = LDAP_INVALID_DN_SYNTAX;
             goto bail;
             goto bail;
         } else if (rc > 0) {
         } else if (rc > 0) {
-            slapi_log_error(SLAPI_LOG_TRACE, ENTRYRDN_TAG,
-                            "entryrdn_rename_subtree:: %s does not belong "
+            slapi_log_error(SLAPI_LOG_BACKLDBM, ENTRYRDN_TAG,
+                            "entryrdn_rename_subtree: %s does not belong "
                             "to the db\n", slapi_sdn_get_dn(mynewsupsdn));
                             "to the db\n", slapi_sdn_get_dn(mynewsupsdn));
             rc = DB_NOTFOUND;
             rc = DB_NOTFOUND;
             goto bail;
             goto bail;
@@ -894,8 +894,8 @@ entryrdn_get_subordinates(backend *be,
                             "\"%s\" to Slapi_RDN\n", slapi_sdn_get_dn(sdn));
                             "\"%s\" to Slapi_RDN\n", slapi_sdn_get_dn(sdn));
             rc = LDAP_INVALID_DN_SYNTAX;
             rc = LDAP_INVALID_DN_SYNTAX;
         } else if (rc > 0) {
         } else if (rc > 0) {
-            slapi_log_error(SLAPI_LOG_TRACE, ENTRYRDN_TAG,
-                            "entryrdn_get_subordinates:: %s does not belong to "
+            slapi_log_error(SLAPI_LOG_BACKLDBM, ENTRYRDN_TAG,
+                            "entryrdn_get_subordinates: %s does not belong to "
                             "the db\n", slapi_sdn_get_dn(sdn));
                             "the db\n", slapi_sdn_get_dn(sdn));
             rc = DB_NOTFOUND;
             rc = DB_NOTFOUND;
         }
         }
@@ -1601,7 +1601,7 @@ _entryrdn_put_data(DBC *cursor, DBT *key, DBT *data, char type)
     if (rc) {
     if (rc) {
         if (DB_KEYEXIST == rc) {
         if (DB_KEYEXIST == rc) {
             /* this is okay */
             /* this is okay */
-            slapi_log_error(SLAPI_LOG_TRACE, ENTRYRDN_TAG,
+            slapi_log_error(SLAPI_LOG_BACKLDBM, ENTRYRDN_TAG,
                             "_entryrdn_put_data: The same key (%s) and the "
                             "_entryrdn_put_data: The same key (%s) and the "
                             "data exists in index\n",
                             "data exists in index\n",
                             (char *)key->data);
                             (char *)key->data);
@@ -2026,7 +2026,7 @@ _entryrdn_insert_key(backend *be,
             } /* if (TMPID == tmpid) */
             } /* if (TMPID == tmpid) */
             rc = 0;
             rc = 0;
         } /* if (DB_KEYEXIST == rc) */
         } /* if (DB_KEYEXIST == rc) */
-        slapi_log_error(SLAPI_LOG_TRACE, ENTRYRDN_TAG,
+        slapi_log_error(SLAPI_LOG_BACKLDBM, ENTRYRDN_TAG,
                         "_entryrdn_insert_key: Suffix %s added: %d\n", 
                         "_entryrdn_insert_key: Suffix %s added: %d\n", 
                         nrdn, rc);
                         nrdn, rc);
         goto bail; /* succeeded or failed, it's done */
         goto bail; /* succeeded or failed, it's done */
@@ -2099,7 +2099,7 @@ _entryrdn_insert_key(backend *be,
             adddata.flags = DB_DBT_USERMEM;
             adddata.flags = DB_DBT_USERMEM;
 
 
             rc = _entryrdn_put_data(cursor, &key, &adddata, RDN_INDEX_SELF);
             rc = _entryrdn_put_data(cursor, &key, &adddata, RDN_INDEX_SELF);
-            slapi_log_error(SLAPI_LOG_TRACE, ENTRYRDN_TAG,
+            slapi_log_error(SLAPI_LOG_BACKLDBM, ENTRYRDN_TAG,
                         "_entryrdn_insert_key: Suffix %s added: %d\n", 
                         "_entryrdn_insert_key: Suffix %s added: %d\n", 
                         slapi_rdn_get_rdn(tmpsrdn), rc);
                         slapi_rdn_get_rdn(tmpsrdn), rc);
         } else {
         } else {
@@ -2201,7 +2201,7 @@ _entryrdn_insert_key(backend *be,
                     /* already in the file */
                     /* already in the file */
                     /* do nothing and return. */
                     /* do nothing and return. */
                     rc = 0;
                     rc = 0;
-                    slapi_log_error(SLAPI_LOG_TRACE, ENTRYRDN_TAG,
+                    slapi_log_error(SLAPI_LOG_BACKLDBM, ENTRYRDN_TAG,
                                     "_entryrdn_insert_key: ID %d is already "
                                     "_entryrdn_insert_key: ID %d is already "
                                     "in the index. NOOP.\n", currid);
                                     "in the index. NOOP.\n", currid);
                 } else { /* different id, error return */
                 } else { /* different id, error return */
@@ -2409,7 +2409,7 @@ retry_get0:
         }
         }
         if (rc) {
         if (rc) {
             if (DB_NOTFOUND == rc) {
             if (DB_NOTFOUND == rc) {
-                slapi_log_error(SLAPI_LOG_TRACE, ENTRYRDN_TAG,
+                slapi_log_error(SLAPI_LOG_BACKLDBM, ENTRYRDN_TAG,
                            "_entryrdn_delete_key: No parent link %s\n", keybuf);
                            "_entryrdn_delete_key: No parent link %s\n", keybuf);
                 goto bail;
                 goto bail;
             } else {
             } else {
@@ -2567,7 +2567,7 @@ _entryrdn_index_read(backend *be,
     /* getting the suffix element */
     /* getting the suffix element */
     rc = _entryrdn_get_elem(cursor, &key, &data, nrdn, elem); 
     rc = _entryrdn_get_elem(cursor, &key, &data, nrdn, elem); 
     if (rc || NULL == *elem) {
     if (rc || NULL == *elem) {
-        slapi_log_error(SLAPI_LOG_TRACE, ENTRYRDN_TAG,
+        slapi_log_error(SLAPI_LOG_BACKLDBM, ENTRYRDN_TAG,
                         "_entryrdn_index_read: Suffix \"%s\" not found: "
                         "_entryrdn_index_read: Suffix \"%s\" not found: "
                         "%s(%d)\n", nrdn, dblayer_strerror(rc), rc);
                         "%s(%d)\n", nrdn, dblayer_strerror(rc), rc);
         rc = DB_NOTFOUND;
         rc = DB_NOTFOUND;
@@ -2644,7 +2644,7 @@ _entryrdn_index_read(backend *be,
         rc = _entryrdn_get_elem(cursor, &key, &data, childnrdn, &tmpelem); 
         rc = _entryrdn_get_elem(cursor, &key, &data, childnrdn, &tmpelem); 
         if (rc) {
         if (rc) {
             slapi_ch_free((void **)&tmpelem);
             slapi_ch_free((void **)&tmpelem);
-            slapi_log_error(SLAPI_LOG_TRACE, ENTRYRDN_TAG,
+            slapi_log_error(SLAPI_LOG_BACKLDBM, ENTRYRDN_TAG,
                             "_entryrdn_index_read: Child link \"%s\" of key "
                             "_entryrdn_index_read: Child link \"%s\" of key "
                             "\"%s\" not found: %s(%d)\n",
                             "\"%s\" not found: %s(%d)\n",
                             childnrdn, keybuf, dblayer_strerror(rc), rc);
                             childnrdn, keybuf, dblayer_strerror(rc), rc);

+ 1 - 0
ldap/servers/slapd/log.c

@@ -102,6 +102,7 @@ static int slapi_log_map[] = {
     LDAP_DEBUG_PLUGIN,		/* SLAPI_LOG_PLUGIN */
     LDAP_DEBUG_PLUGIN,		/* SLAPI_LOG_PLUGIN */
     LDAP_DEBUG_TIMING,		/* SLAPI_LOG_TIMING */
     LDAP_DEBUG_TIMING,		/* SLAPI_LOG_TIMING */
     LDAP_DEBUG_ACLSUMMARY,	/* SLAPI_LOG_ACLSUMMARY */
     LDAP_DEBUG_ACLSUMMARY,	/* SLAPI_LOG_ACLSUMMARY */
+    LDAP_DEBUG_BACKLDBM,	/* SLAPI_LOG_BACKLDBM */
 };
 };
 
 
 #define SLAPI_LOG_MIN	SLAPI_LOG_FATAL		/* from slapi-plugin.h */
 #define SLAPI_LOG_MIN	SLAPI_LOG_FATAL		/* from slapi-plugin.h */

+ 8 - 0
ldap/servers/slapd/main.c

@@ -2579,6 +2579,9 @@ slapd_exemode_db2archive()
 		LDAPDebug(LDAP_DEBUG_ANY, "Initialization Failed 0 %d\n",return_value,0,0);
 		LDAPDebug(LDAP_DEBUG_ANY, "Initialization Failed 0 %d\n",return_value,0,0);
 		return 1;
 		return 1;
 	}
 	}
+	if (!(slapd_ldap_debug & LDAP_DEBUG_BACKLDBM)) {
+		g_set_detached(1);
+	}
 
 
 	memset( &pb, '\0', sizeof(pb) );
 	memset( &pb, '\0', sizeof(pb) );
 	pb.pb_backend = NULL;
 	pb.pb_backend = NULL;
@@ -2630,6 +2633,10 @@ slapd_exemode_archive2db()
 		return 1;
 		return 1;
 	}
 	}
 
 
+	if (!(slapd_ldap_debug & LDAP_DEBUG_BACKLDBM)) {
+		g_set_detached(1);
+	}
+
 	memset( &pb, '\0', sizeof(pb) );
 	memset( &pb, '\0', sizeof(pb) );
 	pb.pb_backend = NULL;
 	pb.pb_backend = NULL;
 	pb.pb_plugin = backend_plugin;
 	pb.pb_plugin = backend_plugin;
@@ -2928,6 +2935,7 @@ static struct slapd_debug_level_entry {
         { LDAP_DEBUG_PLUGIN,	"plugin",			1	},
         { LDAP_DEBUG_PLUGIN,	"plugin",			1	},
         { LDAP_DEBUG_TIMING,	"timing",			0	},
         { LDAP_DEBUG_TIMING,	"timing",			0	},
         { LDAP_DEBUG_ACLSUMMARY,"accesscontrolsummary", 0  },
         { LDAP_DEBUG_ACLSUMMARY,"accesscontrolsummary", 0  },
+        { LDAP_DEBUG_BACKLDBM,  "backend",          0  },
         { LDAP_DEBUG_ALL_LEVELS,"ALL",				0	},
         { LDAP_DEBUG_ALL_LEVELS,"ALL",				0	},
         { 0,                    NULL,               0     }
         { 0,                    NULL,               0     }
 };
 };

+ 2 - 1
ldap/servers/slapd/slapi-plugin.h

@@ -4990,7 +4990,8 @@ int slapi_log_error( int severity, char *subsystem, char *fmt, ... )
 #define SLAPI_LOG_CACHE			13
 #define SLAPI_LOG_CACHE			13
 #define SLAPI_LOG_PLUGIN		14
 #define SLAPI_LOG_PLUGIN		14
 #define SLAPI_LOG_TIMING		15
 #define SLAPI_LOG_TIMING		15
-#define SLAPI_LOG_ACLSUMMARY		16
+#define SLAPI_LOG_BACKLDBM		16
+#define SLAPI_LOG_ACLSUMMARY		17
 
 
 int slapi_is_loglevel_set( const int loglevel );
 int slapi_is_loglevel_set( const int loglevel );