From 946dfc783cde9015cc7f288b69008ff22436f255 Mon Sep 17 00:00:00 2001 From: Gary Lockyer Date: Thu, 22 Mar 2018 12:50:45 +1300 Subject: [PATCH] upgradeprovision: detect and handle lmdb databases Signed-off-by: Gary Lockyer Reviewed-by: Andrew Bartlett Autobuild-User(master): Andrew Bartlett Autobuild-Date(master): Fri Apr 6 05:12:11 CEST 2018 on sn-devel-144 --- source4/scripting/bin/samba_upgradeprovision | 26 +++++++++++++++++--- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/source4/scripting/bin/samba_upgradeprovision b/source4/scripting/bin/samba_upgradeprovision index e0db12e0818..62b7001f565 100755 --- a/source4/scripting/bin/samba_upgradeprovision +++ b/source4/scripting/bin/samba_upgradeprovision @@ -36,11 +36,13 @@ sys.path.insert(0, "bin/python") import ldb import samba import samba.getopt as options +from samba.samdb import get_default_backend_store from base64 import b64encode from samba.credentials import DONT_USE_KERBEROS from samba.auth import system_session, admin_session from samba import tdb_util +from samba import mdb_util from ldb import (SCOPE_SUBTREE, SCOPE_BASE, FLAG_MOD_REPLACE, FLAG_MOD_ADD, FLAG_MOD_DELETE, MessageElement, Message, Dn, LdbError) @@ -1366,7 +1368,7 @@ def update_samdb(ref_samdb, samdb, names, provisionUSNs, schema, prereloadfunc): return 0 -def backup_provision(paths, dir, only_db): +def backup_provision(samdb, paths, dir, only_db): """This function backup the provision files so that a rollback is possible @@ -1374,8 +1376,20 @@ def backup_provision(paths, dir, only_db): :param dir: Directory where to store the backup :param only_db: Skip sysvol for users with big sysvol """ + + # Currently we default to tdb for the backend store type + # + backend_store = "tdb" + res = samdb.search(base="@PARTITION", + scope=ldb.SCOPE_BASE, + attrs=["backendStore"]) + if "backendStore" in res[0]: + backend_store = res[0]["backendStore"][0] + + if paths.sysvol and not only_db: copytree_with_xattrs(paths.sysvol, os.path.join(dir, "sysvol")) + tdb_util.tdb_copy(paths.samdb, os.path.join(dir, os.path.basename(paths.samdb))) tdb_util.tdb_copy(paths.secrets, os.path.join(dir, os.path.basename(paths.secrets))) tdb_util.tdb_copy(paths.idmapdb, os.path.join(dir, os.path.basename(paths.idmapdb))) @@ -1399,8 +1413,12 @@ def backup_provision(paths, dir, only_db): for ldb_name in os.listdir(samldbdir): if not ldb_name.endswith("-lock"): - tdb_util.tdb_copy(os.path.join(samldbdir, ldb_name), - os.path.join(dir, "sam.ldb.d", ldb_name)) + if backend_store == "mdb" and ldb_name != "metadata.tdb": + mdb_util.mdb_copy(os.path.join(samldbdir, ldb_name), + os.path.join(dir, "sam.ldb.d", ldb_name)) + else: + tdb_util.tdb_copy(os.path.join(samldbdir, ldb_name), + os.path.join(dir, "sam.ldb.d", ldb_name)) def sync_calculated_attributes(samdb, names): @@ -1571,7 +1589,7 @@ if __name__ == '__main__': ldbs = get_ldbs(paths, creds, session, lp) backupdir = tempfile.mkdtemp(dir=paths.private_dir, prefix="backupprovision") - backup_provision(paths, backupdir, opts.db_backup_only) + backup_provision(ldbs.sam, paths, backupdir, opts.db_backup_only) try: ldbs.startTransactions()