1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-22 22:04:08 +03:00

dbcheck: added --reindex option

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>
This commit is contained in:
Andrew Tridgell 2011-07-12 11:05:43 +10:00
parent 6bc1957a54
commit 0ab3086b46
2 changed files with 20 additions and 3 deletions

View 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)

View 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)