> For AI agents: the complete documentation index is available at /resource/ucidm/docs/on-premise/1.9.0/llms.txt, the full documentation bundle is available at /resource/ucidm/docs/on-premise/1.9.0/llms-full.txt.

# ID 情報の再同期

なんらかの理由で LDAP サーバーのエントリが UCIDM API サーバーに ID 連携されていないときに運用対応する方法について説明します。

[Agent モジュール](/resource/ucidm/docs/on-premise/1.9.0/configuration/agent/index.md) のコンテナ内に再同期のための運用ツールが同梱されており、Docker Compose の Agent モジュールの設定内容を再利用できます。

デフォルトでは Docker Compose を /var/opt/osstech/lib/ucidm に配置します。ここではデフォルトの位置にインストールされている前提で作業を進めていきます。

`compose.yml` を配置したディレクトリへ移動します。

```bash
$ cd /var/opt/osstech/lib/ucidm
```

次のように実行してヘルプが表示されることを確認してください。`-it` の後にサービス名を指定します。agent-ldap, agent-ad, agent-meid というサービス名になります。

```bash
$ docker compose exec -it agent-ad /bin/resync help
Usage: resync <flags> <subcommand> <subcommand args>

Subcommands:
	commands         list all command names
	delete           delete entries in the ucidm server
	entry            resync an entry
	flags            describe all known top-level flags
	help             describe subcommands and their syntax
	pass             pass changes to get the latest cookie or deltatoken
	update           update entries in the ucidm server


Use "resync flags" for a list of top-level flags
```

## 個別エントリの再同期 \{#resync-entry}

種別 (ユーザー, グループまたは組織単位) と DN または ID を指定して個別エントリーを再同期します。

DN とユーザーエントリのとき

```bash
$ docker compose exec -it agent-ldap \
  /bin/resync -verbose entry -dn uid=user1,ou=users,dc=example,dc=com -type user
```

DN とグループエントリのとき

```bash
$ docker compose exec -it agent-ad \
  /bin/resync -verbose entry -dn cn=group1,ou=groups,dc=example,dc=com -type group
```

DN と組織単位エントリのとき

```bash
$ docker compose exec -it agent-ad \
  /bin/resync -verbose entry -dn ou=groups,dc=example,dc=com -type ou
```

ID とユーザーエントリのとき

```bash
$ docker compose exec -it agent-meid \
  /bin/resync -verbose entry -id a8d67d70-f83b-453d-9666-1f280a609bf6 -type user
```

## すべてのエントリの再同期 \{#resync-update}

LDAP サーバーまたはクラウドサーバーのすべてのエントリーを UCIDM API サーバーに再同期します。それぞれのサーバーに実行時点で存在しているエントリーを取得します。

デフォルトではドライランモードで実行されて実際にエントリーは更新しません。またデータソースのエントリが UCIDM API サーバーに存在していない場合はコンソールにその情報を表示します。

ユーザーエントリのとき (ドライラン有効)

```bash
$ docker compose exec -it agent-ldap /bin/resync update -type user
```

グループエントリのとき (ドライラン有効)

```bash
$ docker compose exec -it agent-ad /bin/resync update -type group
```

組織単位エントリのとき (ドライラン有効)

```bash
$ docker compose exec -it agent-ad /bin/resync update -type ou
```

ドライランモードを解除して実際に更新するには次のように実行します。

ユーザーエントリのとき (ドライラン無効)

```bash
$ docker compose exec -it agent-ldap /bin/resync update -type user -dryrun=false
```

グループエントリのとき (ドライラン無効)

```bash
$ docker compose exec -it agent-ad /bin/resync update -type group -dryrun=false
```

組織単位エントリのとき (ドライラン無効)

```bash
$ docker compose exec -it agent-ad /bin/resync update -type ou -dryrun=false
```

## UCIDM API サーバーから不整合なユーザーの削除 \{#resync-delete}

UCIDM API サーバーに存在して LDAP サーバーまたはクラウドサーバーに存在しないエントリを UCIDM API サーバーから削除します。

デフォルトではドライランモードで実行されて実際にエントリーは削除しません。UCIDM API サーバーで削除対象となるエントリをチェックして一覧表示します。

ユーザーエントリのとき (ドライラン有効)

```bash
$ docker compose exec -it agent-ldap /bin/resync delete -type user
```

グループエントリのとき (ドライラン有効)

```bash
$ docker compose exec -it agent-ad /bin/resync delete -type group
```

組織単位エントリのとき (ドライラン有効)

```bash
$ docker compose exec -it agent-ad /bin/resync delete -type ou
```

ドライランモードを解除して実際に削除するには次のように実行します。

ユーザーエントリのとき (ドライラン無効)

```bash
$ docker compose exec -it agent-ldap /bin/resync delete -type user -dryrun=false
```

グループエントリのとき (ドライラン無効)

```bash
$ docker compose exec -it agent-ad /bin/resync delete -type group -dryrun=false
```

組織単位エントリのとき (ドライラン無効)

```bash
$ docker compose exec -it agent-ad /bin/resync delete -type ou -dryrun=false
```

## UCIDM 導入時の初回連携の効率化 \{#resync-pass}

LDAP サーバーまたはクラウドサーバーから ID 情報を初回同期するとき、それらのサーバーが長年に渡って運用され、過去の履歴が多い場合、すべての履歴を順番に適用するため、初回同期に数時間や数日といった時間がかかる可能性があります。

Agent モジュールが扱う同期情報と競合しないよう、一時的に Docker Compose の Agent モジュールを停止させてから初回同期を行います。次のようにして初回同期ならびに最新の同期情報を生成します。ここでは agent-meid という Microsoft Entra ID 向けサービスの設定例として紹介します。

```bash
$ docker compose stop agent-meid
$ docker compose run --rm --entrypoint "/bin/resync update -type user -dryrun=false" agent-meid
$ docker compose run --rm --entrypoint "/bin/resync update -type group -dryrun=false" agent-meid
$ docker compose run --rm --entrypoint "/bin/resync pass" agent-meid
```

正常に終了すると volumes/agent-data 配下に保存される同期情報が更新されます。

```bash
$ ls -l volumes/agent-data/meid/
total 8
-rw-r--r--. 1 ucidm ucidm 2750 Jul 18 09:54 msgraph-group.deltatoken
-rw-r--r--. 1 ucidm ucidm 2471 Jul 18 09:54 msgraph-user.deltatoken
```

同期情報が更新されていることを確認したら Agent モジュールを再開させます。

```bash
$ docker compose up -d agent-meid
```

pass サブコマンドを実行したタイミング以降の変更差分のみを検出できるようになります。
