d41e5ca07b
Signed-off-by: Alexander Bokovoy <abokovoy@redhat.com>
107 lines
3.6 KiB
Diff
107 lines
3.6 KiB
Diff
From cb16071635e8c60faa5b6062ed1dd61c3f133fa3 Mon Sep 17 00:00:00 2001
|
|
From: Rob Crittenden <rcritten@redhat.com>
|
|
Date: Wed, 7 Feb 2024 13:42:11 -0500
|
|
Subject: ipa-restore: adapt for 389-ds switch to LMDB
|
|
|
|
ipa-restore is relying on the presence of specific directories,
|
|
e.g. /var/lib/dirsrv/slapd-<INSTANCE>/db/ipaca, to detect
|
|
which backends are in use (userRoot or ipaca).
|
|
|
|
With the switch to LMDB, these directories do not exist and the
|
|
restore fails finding the ipaca backend.
|
|
|
|
Use lib389.cli_ctl.dblib.run_dbscan utility instead to
|
|
check which backends are present.
|
|
|
|
This method was been introduced in 389ds 2.1.0 and works with
|
|
Berkeley DB and LMDB.
|
|
|
|
Fixes: https://pagure.io/freeipa/issue/9526
|
|
|
|
Signed-off-by: Rob Crittenden <rcritten@redhat.com>
|
|
---
|
|
ipaserver/install/ipa_restore.py | 45 +++++++++++++++++++++++++++-----
|
|
1 file changed, 38 insertions(+), 7 deletions(-)
|
|
|
|
diff --git a/ipaserver/install/ipa_restore.py b/ipaserver/install/ipa_restore.py
|
|
index 5b7ac61d08f..88b34477049 100644
|
|
--- a/ipaserver/install/ipa_restore.py
|
|
+++ b/ipaserver/install/ipa_restore.py
|
|
@@ -50,6 +50,8 @@
|
|
from ipaplatform import services
|
|
from ipaplatform.paths import paths
|
|
|
|
+from lib389.cli_ctl.dblib import run_dbscan
|
|
+
|
|
try:
|
|
from ipaserver.install import adtrustinstance
|
|
except ImportError:
|
|
@@ -65,6 +67,29 @@
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
+backends = [] # global to save running dbscan multiple times
|
|
+
|
|
+
|
|
+def get_backends(db_dir):
|
|
+ """Retrieve the set of backends directly from the current database"""
|
|
+ global backends
|
|
+
|
|
+ if backends:
|
|
+ return backends
|
|
+
|
|
+ output = run_dbscan(['-L', db_dir])
|
|
+ output = output.replace(db_dir + '/', '')
|
|
+ output = output.split('\n')
|
|
+ for line in output:
|
|
+ if '/' not in line:
|
|
+ continue
|
|
+ backends.append(line.split('/')[0].strip().lower())
|
|
+ backends = set(backends)
|
|
+ if 'changelog' in backends:
|
|
+ backends.remove('changelog')
|
|
+
|
|
+ return backends
|
|
+
|
|
|
|
def recursive_chown(path, uid, gid):
|
|
'''
|
|
@@ -295,8 +320,9 @@ def run(self):
|
|
if options.backend:
|
|
for instance in self.instances:
|
|
db_dir = (paths.SLAPD_INSTANCE_DB_DIR_TEMPLATE %
|
|
- (instance, options.backend))
|
|
- if os.path.exists(db_dir):
|
|
+ (instance, ""))
|
|
+ backends = get_backends(db_dir)
|
|
+ if options.backend.lower() in backends:
|
|
break
|
|
else:
|
|
raise admintool.ScriptError(
|
|
@@ -304,15 +330,20 @@ def run(self):
|
|
|
|
self.backends = [options.backend]
|
|
|
|
+ missing_backends = []
|
|
for instance, backend in itertools.product(self.instances,
|
|
self.backends):
|
|
db_dir = (paths.SLAPD_INSTANCE_DB_DIR_TEMPLATE %
|
|
- (instance, backend))
|
|
- if os.path.exists(db_dir):
|
|
- break
|
|
- else:
|
|
+ (instance, ""))
|
|
+ backends = get_backends(db_dir)
|
|
+ if backend.lower() not in backends:
|
|
+ missing_backends.append(backend)
|
|
+
|
|
+ if missing_backends:
|
|
raise admintool.ScriptError(
|
|
- "Cannot restore a data backup into an empty system")
|
|
+ "Cannot restore a data backup into an empty system. "
|
|
+ "Missing backend(s) %s" % ', '.join(missing_backends)
|
|
+ )
|
|
|
|
logger.info("Performing %s restore from %s backup",
|
|
restore_type, self.backup_type)
|