Skip to content

Commit

Permalink
feat: ldap2pgsql migration
Browse files Browse the repository at this point in the history
Signed-off-by: Mustafa Baser <mbaser@mail.com>
  • Loading branch information
devrimyatar committed Jun 30, 2024
1 parent 8f9eb14 commit aef75e1
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 42 deletions.
5 changes: 4 additions & 1 deletion setup_app/installers/rdbm.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,11 @@ def prepare(self):
self.gluu_attributes += schema_.get('attributeTypes', [])


@property
def output_dir(self):
return os.path.join(Config.outputFolder, Config.rdbm_type)

def install(self):
self.output_dir = os.path.join(Config.outputFolder, Config.rdbm_type)
if not os.path.exists(self.output_dir):
self.createDirs(self.output_dir)

Expand Down
39 changes: 0 additions & 39 deletions tools/ldap_to_mysql/README.md

This file was deleted.

68 changes: 68 additions & 0 deletions tools/ldap_to_rdbm/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# Gluu OpenDJ to MySQL Migration

This script migrates data from OpenDJ to MySQL. Please note that this tool is experimental.
Note!: Test this script on non-production server.

# Prerequisites

* Insptall `python3-ldap` package.

On RHEL-8/CentOS-8-AppStream: `yum install python3-ldap`

On Ubuntun: `apt install python3-ldap`

* If you are migration to MySQL

Install MySQL that upports a native JSON data type (See https://dev.mysql.com/doc/refman/5.7/en/json.html).
MySQL Server shipped with >=Ubuntu 20 and >=RHEL 8/CentOS-8-Appstream is fine.
Create a database, namely `gluudb`, and create
a user, namely `gluu`. User should have all previleges on created database. Sample MySQL commands
(If you installed MySQL on a seperate server, modify commands accordingly):

```
CREATE DATABASE gluudb;
CREATE USER 'gluu'@'localhost' IDENTIFIED BY 'TopSecret';
GRANT ALL PRIVILEGES ON gluudb.* TO 'gluu'@'localhost';
```

* If you are migration to PostgreSQL

Install postgresql server on your system (version should be at least 14.0) or any host that can be reachable from gluu host.
Add the following line at the beginning of file `pg_hba.conf` (You can learn location of this file by executing command `sudo su - postgres -c 'psql -U postgres -d postgres -t -c "SHOW hba_file;"'`):

`host gluudb gluu 0.0.0.0/0 md5`

To crate database, user and adjust previleges, connect to postgresql server bu command
`sudo su - postgres -c 'psql'`

Execute the following sql commands:

```
CREATE DATABASE gluudb;
CREATE USER gluu WITH PASSWORD 'TopSecret';
GRANT ALL PRIVILEGES ON DATABASE gluudb TO gluu;
ALTER DATABASE gluudb OWNER TO gluu;
```

# Migration

- Download migration script:
```
wget https://raw.githubusercontent.com/GluuFederation/community-edition-setup/tools/ldap_to_rdbm/ldap2rdbm.py -O /install/community-edition-setup/ldap2rdbm.py
```
- Execute script (for MySQL):
```
cd /install/community-edition-setup/
python3 ldap2rdbm.py -rdbm-type="mysql" -rdbm-user="gluu" -rdbm-password="TopSecret" -rdbm-db="gluudb" -rdbm-host="localhost"
```
- Execute script (for PostgreSQL):
```
cd /install/community-edition-setup/
python3 ldap2rdbm.py -rdbm-type="pgsql" -rdbm-user="gluu" -rdbm-password="TopSecret" -rdbm-db="gluudb" -rdbm-host="localhost" -rdbm-port="5432"
```
Replace `localhost` with hostname of RDBM server
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@


parser = argparse.ArgumentParser(description="Gluu CE LDAP to RDBM migrator script")
parser.add_argument('-remote-rdbm', choices=['mysql'], help="Enables using remote RDBM server", default='mysql')
parser.add_argument('-rdbm-type', choices=['mysql', 'pgsql'], help="Enables using remote RDBM server", default='mysql')
parser.add_argument('-rdbm-user', help="RDBM username", required = True)
parser.add_argument('-rdbm-password', help="RDBM password", required = True)
parser.add_argument('-rdbm-port', help="RDBM port", type=int)
parser.add_argument('-rdbm-db', help="RDBM database", required = True)
parser.add_argument('-rdbm-host', help="RDBM host", required = True)
argsp = parser.parse_args()
rdbm_config_params = ('rdbm_user', 'rdbm_password', 'rdbm_host', 'rdbm_db', 'rdbm_host', 'rdbm_port')
rdbm_config_params = ('rdbm_type', 'rdbm_user', 'rdbm_password', 'rdbm_host', 'rdbm_db', 'rdbm_host', 'rdbm_port')
argsp_dict = { a: getattr(argsp, a) for a in rdbm_config_params }
sys.argv = [sys.argv[0]]

Expand Down

0 comments on commit aef75e1

Please sign in to comment.