# Confluence 6 选项 2 – 转移 Crowd/Jira 应用程序中的用户和用户

**URL:** <https://www.isharkfly.com/t/confluence-6-2-crowd-jira/1431>\
**Category:** 文档交付\
**Tags:** confluence\
**Created:** [January 14, 2021, 6:20pm UTC](https://www.isharkfly.com/t/confluence-6-2-crowd-jira/1431 "2021-01-14T18:20:10Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![honeymoose](https://www.isharkfly.com/user_avatar/www.isharkfly.com/honeymoose/32/20796_2.png) [@honeymoose](https://www.isharkfly.com/u/honeymoose)\
**Post date:** [January 14, 2021, 6:20pm UTC](https://www.isharkfly.com/t/confluence-6-2-crowd-jira/1431/1 "2021-01-14T18:20:10Z")

</div>

当你打算合并的外部目录服务器（Crowd 或 Jira 应用）有大量的用户到 Confluence 数据库中的时候，请使用这个选项。你需要有基本的 SQL 知识才能完成这个任务。  
下面的 SQL 命令假设你使用的数据库为 **MySQL** 数据库。如果你使用的数据库不是 MySQL 数据库的话，你需要针对你使用的数据库对你的脚本进行一些修改后才能执行。  
**第 1 步. 创建备份** 创建备份是在你对系统进行操作时候出现错误后恢复的唯一办法。

- 从 Confluence 中，你可以创建一个完整的 XML 站点备份包括所有的附件。
- 停止 Confluence。
- 将你服务器上的 Confluence home 和 安装目录中的所有文件和目录拷贝到系统的其他地方备份。
- 针对你的外部应用程序，重复上面的步骤。
- 从你的 MySQL 数据库管理工具中，为 Crowd/Jira 和 Confluence 都创建一个备份。

**第 2 步. 替换 Confluence 用户管理** 使用下面的 SQL 脚本备份外部应用程序中的用户和用户组到 Confluence 表中。下面的脚本是针对 MySQL 数据库设计运行的，如果你使用其他的数据库，你需要对脚本进行修改。  
**找到你目录使用的 ID**

- 运行下面的脚本，然后对返回的结果数进行记录，这个 ID 将会在后面的 参数中引用。

select id from cwd\_directory where directory\_name=‘Confluence Internal Directory’;

- 针对用户目录关里界面，找到你希望移动的用户，用户组名字。运行下面的脚本，然后对返回的结果数进行记录，这个 ID 将会在后面的 参数中引用。

select id from cwd\_directory where directory\_name=‘’;

**移动用户组到 Confluence**

- 在你的内部目录中，外部目录的名字是相同情况是被允许的，希望找到这些名字，请运行下面的脚本：

select distinct a.id, a.directory\_id, a.group\_name, d.directory\_name from cwd\_group a join cwd\_group b on a.group\_name=b.group\_name join cwd\_directory d on d.id=a.directory\_id where a.directory\_id != b.directory\_id;

- 如果上面的脚本有返回插件结果，针对每一条记录表明的是名字出现了重复，在 Confluence 的内部目录中找到这些重复名字的 ID（）和外部应用（）。运行下面的脚本：

update cwd\_group\_attribute set group\_id=, directory\_id= where group\_id=;  
update cwd\_membership set child\_group\_id= where child\_group\_id=;  
update cwd\_membership set parent\_id= where parent\_id=;  
delete from cwd\_group where id=;

- 移动所有外部应用中的所有组到 Confluence 内部目录中。

update cwd\_group set directory\_id= where directory\_id=;

**移动用户到 Confluence**

- 在内部目录中是允许有多个相同的用户名的，如果这些用户组在不同的外部应用目录中的话。找到这些用户，运行：

select distinct a.id, a.directory\_id, a.user\_name, d.directory\_name from cwd\_user a join cwd\_user b on a.user\_name=b.user\_name join cwd\_directory d on d.id=a.directory\_id where a.directory\_id != b.directory\_id;

- 如果上面的脚本返回了多条记录的话，表明的是你的系统中有多个用户具有相同的用户名在不同的外部目录中。在 Confluence 的内部目录中找到这些重复名字的 ID（(）和外部应用（）。运行下面的脚本：

update cwd\_membership set child\_user\_id= where child\_user\_id=;  
update cwd\_user\_credential\_record set user\_id= where user\_id=;  
update cwd\_user\_attribute set user\_id=, directory\_id= where user\_id=;  
delete from cwd\_user where id=;

- 移动所有外部应用中的所有用户到 Confluence 内部目录中。

update cwd\_user set directory\_id= where directory\_id=;

**删除外部应用目录**

- 你需要移动你的系统中的目录顺序，将内部用户目录移动到系统目录列表中的最顶端，然后激活它。

update cwd\_app\_dir\_mapping set list\_index = 0 where directory\_id = ;

- 如果你具有超过 2 个的用户目录，你需要将你的内部目录移动到顶部（list\_index 0）需要删除的外部目录在这个目录的后面。

select d.id, d.directory\_name, m.list\_index from cwd\_directory d join cwd\_app\_dir\_mapping m on d.id=m.directory\_id order by m.list\_index;

```
* 修改列表索引，这样这些目录将会按照你希望的顺序进行排序。用户目录的排序可以使用下面的方法进行重排序

```

update cwd\_app\_dir\_mapping set list\_index = where directory\_id = ;

- 检查内部目录是否被启用。

select id, directory\_name, active from cwd\_directory where id = ;

```
* 如果内部目录不是激活的，请激活它

```

update cwd\_directory set active = ‘T’ where id = ;

- 当所有的目录排序是正确的话，从目录列表中删除外部应用目录：

delete from cwd\_app\_dir\_operation where app\_dir\_mapping\_id = (select id from cwd\_app\_dir\_mapping where directory\_id = );  
delete from cwd\_app\_dir\_mapping where directory\_id = ;

- 如果被删除的外部目录在系统中与其他的表有约束的话，你需要根据这些约束从数据库中先删除其他表中的数据：

delete from cwd\_directory\_attribute where directory\_id=;  
delete from cwd\_directory\_operation where directory\_id=;

- 所有引用的外部目录现在应该可以从系统中被删除了。使用下面的命令进行删除：

delete from cwd\_directory where id = ;

**重置密码**

- 所有在你删除的外部目录中的用户现在还不能登录系统，包括外部目录的管理员。这些用户需要先重置密码后才能登录系统。你可以通知你的用户使用登录页面的 \*\*忘记你的密码（Forgot your password）\*\*连接重置密码。可选的你可以使用[Restore Passwords To Recover Admin User Rights](https://www.cwiki.us/display/CONFLUENCEWIKI/Restore+Passwords+To+Recover+Admin+User+Rights)页面的内容重置管理员的密码，然后通过管理员界面中的管理用户选项为你的用户重置密码。
