diff options
author | Andrew Bartlett <abartlet@samba.org> | 2016-08-29 18:36:19 +1200 |
---|---|---|
committer | Karolin Seeger <kseeger@samba.org> | 2016-10-20 10:45:27 +0200 |
commit | 68598e4d196ab8f4dfcab044e61746571e3238d7 (patch) | |
tree | fc53b36a912376d3cd7e143d8d894a718f4321c5 /python | |
parent | 1902436de96eeba04c60765b92e78bac2c51109f (diff) | |
download | samba-68598e4d196ab8f4dfcab044e61746571e3238d7.tar.gz |
samba-tool: Add command-line tool to trigger tombstone expunge
This allows us to carefully test the garbage collection of tombstoned objects
without running the full server and waiting for the timer to expire
Signed-off-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Garming Sam <garming@catalyst.net.nz>
BUG: https://bugzilla.samba.org/show_bug.cgi?id=12382
(cherry picked from commit 55b9b9a969b0e7ef6590710fda85265fc3146159)
Diffstat (limited to 'python')
-rw-r--r-- | python/samba/netcmd/domain.py | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/python/samba/netcmd/domain.py b/python/samba/netcmd/domain.py index fd26d939cf6..dc1356decba 100644 --- a/python/samba/netcmd/domain.py +++ b/python/samba/netcmd/domain.py @@ -32,6 +32,7 @@ import random import tempfile import logging import subprocess +import time from getpass import getpass from samba.net import Net, LIBNET_JOIN_AUTOMATIC import samba.ntacls @@ -3747,6 +3748,72 @@ class cmd_domain_trust_namespaces(DomainTrustCommand): tln=local_tdo_info.domain_name.string) return +class cmd_domain_tombstones_expunge(Command): + """Expunge tombstones from the database. + +This command expunges tombstones from the database.""" + synopsis = "%prog NC [NC [...]] [options]" + + takes_options = [ + Option("-H", "--URL", help="LDB URL for database or target server", type=str, + metavar="URL", dest="H"), + Option("--current-time", + help="The current time to evaluate the tombstone lifetime from, expressed as YYYY-MM-DD", + type=str), + Option("--tombstone-lifetime", help="Number of days a tombstone should be preserved for", type=int), + ] + + takes_args = ["nc*"] + + takes_optiongroups = { + "sambaopts": options.SambaOptions, + "credopts": options.CredentialsOptions, + "versionopts": options.VersionOptions, + } + + def run(self, *ncs, **kwargs): + sambaopts = kwargs.get("sambaopts") + credopts = kwargs.get("credopts") + versionpts = kwargs.get("versionopts") + H = kwargs.get("H") + current_time_string = kwargs.get("current_time") + tombstone_lifetime = kwargs.get("tombstone_lifetime") + lp = sambaopts.get_loadparm() + creds = credopts.get_credentials(lp) + samdb = SamDB(url=H, session_info=system_session(), + credentials=creds, lp=lp) + + if current_time_string is not None: + current_time_obj = time.strptime(current_time_string, "%Y-%m-%d") + current_time = long(time.mktime(current_time_obj)) + + else: + current_time = long(time.time()) + + if len(ncs) == 0: + res = samdb.search(expression="", base="", scope=ldb.SCOPE_BASE, + attrs=["namingContexts"]) + + ncs = [] + for nc in res[0]["namingContexts"]: + ncs.append(str(nc)) + else: + ncs = list(ncs) + + try: + (removed_objects, + removed_links) = samdb.garbage_collect_tombstones(ncs, + current_time=current_time, + tombstone_lifetime=tombstone_lifetime) + + except Exception, err: + raise CommandError("Failed to expunge / garbage collect tombstones", err) + + self.outf.write("Removed %d objects and %d links successfully\n" + % (removed_objects, removed_links)) + + + class cmd_domain_trust(SuperCommand): """Domain and forest trust management.""" @@ -3758,6 +3825,12 @@ class cmd_domain_trust(SuperCommand): subcommands["validate"] = cmd_domain_trust_validate() subcommands["namespaces"] = cmd_domain_trust_namespaces() +class cmd_domain_tombstones(SuperCommand): + """Domain tombstone and recycled object management.""" + + subcommands = {} + subcommands["expunge"] = cmd_domain_tombstones_expunge() + class cmd_domain(SuperCommand): """Domain management.""" @@ -3774,3 +3847,4 @@ class cmd_domain(SuperCommand): subcommands["classicupgrade"] = cmd_domain_classicupgrade() subcommands["samba3upgrade"] = cmd_domain_samba3upgrade() subcommands["trust"] = cmd_domain_trust() + subcommands["tombstones"] = cmd_domain_tombstones() |