dbcheck: added --reindex option
authorAndrew Tridgell <tridge@samba.org>
Tue, 12 Jul 2011 01:05:43 +0000 (11:05 +1000)
committerAndrew Tridgell <tridge@samba.org>
Wed, 13 Jul 2011 10:51:05 +0000 (12:51 +0200)
this allows you to force a reindex of the database

Pair-Programmed-With: Amitay Isaacs <amitay@gmail.com>
Pair-Programmed-With: Andrew Bartlett <abartlet@samba.org>

source4/scripting/python/samba/dbchecker.py
source4/scripting/python/samba/netcmd/dbcheck.py

index f89e2df878652ec045feb29686f7d10d7e8a3af6..1f250662ea142318a17aa73fbd9db70c42066fd0 100644 (file)
@@ -477,3 +477,13 @@ class dbcheck(object):
                 self.fix_metadata(dn, att)
 
         return error_count
+
+    ###############################################
+    # re-index the database
+    def reindex_database(self):
+        '''re-index the whole database'''
+        m = ldb.Message()
+        m.dn = ldb.Dn(self.samdb, "@ATTRIBUTES")
+        m['add']    = ldb.MessageElement('NONE', ldb.FLAG_MOD_ADD, 'force_reindex')
+        m['delete'] = ldb.MessageElement('NONE', ldb.FLAG_MOD_DELETE, 'force_reindex')
+        return self.do_modify(m, [], 're-indexed database', validate=False)
index 203d447b123ef011a2bce855b2690a0e0583ee4e..823ec7a101fb248f08074109baf177e2e0c43adf 100644 (file)
@@ -56,11 +56,12 @@ class cmd_dbcheck(Command):
         Option("--quiet", dest="quiet", action="store_true", default=False,
             help="don't print details of checking"),
         Option("--attrs", dest="attrs", default=None, help="list of attributes to check (space separated)"),
+        Option("--reindex", dest="reindex", default=False, action="store_true", help="force database re-index"),
         Option("-H", help="LDB URL for database or target server (defaults to local SAM database)", type=str),
         ]
 
     def run(self, DN=None, H=None, verbose=False, fix=False, yes=False, cross_ncs=False, quiet=False,
-            scope="SUB", credopts=None, sambaopts=None, versionopts=None, attrs=None):
+            scope="SUB", credopts=None, sambaopts=None, versionopts=None, attrs=None, reindex=False):
 
         lp = sambaopts.get_loadparm()
 
@@ -101,11 +102,17 @@ class cmd_dbcheck(Command):
             samdb.transaction_start()
 
         chk = dbcheck(samdb, samdb_schema=samdb_schema, verbose=verbose, fix=fix, yes=yes, quiet=quiet)
-        error_count = chk.check_database(DN=DN, scope=search_scope, controls=controls, attrs=attrs)
+
+        if reindex:
+            print("Re-indexing...")
+            error_count = 0
+            if chk.reindex_database():
+                print("completed re-index OK")
+        else:
+            error_count = chk.check_database(DN=DN, scope=search_scope, controls=controls, attrs=attrs)
 
         if yes and fix:
             samdb.transaction_commit()
 
         if error_count != 0:
             sys.exit(1)
-