Articles in this section
Category / Section

Load user data from LDIF to Gluu OpenDJ

Published:
1 min read

Load user data from LDIF

This script help Gluu Server administrator who are using “Gluu-OpenDJ” to load users from backup ldif

Prerequisite

  • There must be an LDIF containing all users’ information in Gluu LDAP format. That means: this LDIF is extracted from another Gluu Server by ldapsearch or any other standard OpenDJ tool.
  • Python 3 is required.
  • Python-ldap required.

How to use

  • Your backup LDIF is ready in the same directory where you are going to download the script.
  • You have Python 3 installed.
  • You have the Python-LDAP package installed.
  • Download the script - Download ‘ldif.py’ from the location: https://raw.githubusercontent.com/abilian/ldif/master/ldif.py
  • Add the name of the LDIF in myLdifParser("YOUR_LDIF_FILE_NAME", writer) location of the code.
  • Run script: python3 bulk_load_ldif.py

Script

from collections import OrderedDict
from ldif import LDIFParser, LDIFWriter
class myLdifParser(LDIFParser):
    def __init__(self, ldif_file, ldif_writer):
        self.ldif_file = ldif_file
        self.ldif_writer = ldif_writer
        self.entries = []

    def parse(self):
        with open(self.ldif_file, 'rb') as f:
            parser = LDIFParser(f)
            for dn, entry in parser.parse():
               entry_list = list(entry.items())
               entry_list.insert(0, ('changetype', ['add']))
               new_entry = OrderedDict(entry_list)
               self.ldif_writer.unparse(dn, new_entry)


f = open('new.ldif', 'wb')
writer = LDIFWriter(f, cols=1000)
parser = myLdifParser("YOUR_LDIF_FILE_NAME", writer)
parser.parse()
f.close()
Was this article useful?
Like
Dislike
Help us improve this page
Please provide feedback or comments
Access denied
Access denied