summaryrefslogtreecommitdiff
path: root/source4
diff options
context:
space:
mode:
Diffstat (limited to 'source4')
-rw-r--r--source4/scripting/python/samba/dbchecker.py10
-rw-r--r--source4/scripting/python/samba/netcmd/dbcheck.py13
2 files changed, 20 insertions, 3 deletions
diff --git a/source4/scripting/python/samba/dbchecker.py b/source4/scripting/python/samba/dbchecker.py
index f89e2df878..1f250662ea 100644
--- a/source4/scripting/python/samba/dbchecker.py
+++ b/source4/scripting/python/samba/dbchecker.py
@@ -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)
diff --git a/source4/scripting/python/samba/netcmd/dbcheck.py b/source4/scripting/python/samba/netcmd/dbcheck.py
index 203d447b12..823ec7a101 100644
--- a/source4/scripting/python/samba/netcmd/dbcheck.py
+++ b/source4/scripting/python/samba/netcmd/dbcheck.py
@@ -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)
-