---
title: "Usercube-Prepare-Synchronization"
description: "Learn how the Identity Manager Prepare-Synchronization task cleanses exported CSV files, computes changes, and sends them to the server."
sidebar_position: 290
---

# Usercube-Prepare-Synchronization

`Usercube-Prepare-Synchronization` is used as the second step of the [Synchronization](../../../configuration/synchronization/index.md) process. It cleanses exported CSV files before sending them to the server for database loading. It is performed on the _Agent_ side.

## Behavior Details

The task reads files from the source directory, usually the temp folder > ExportOutput folder. See the [Application Settings](../../../configuration/network-configuration/server-configuration/general-purpose.md) topic for additional information.

### Cleanse data

The following actions are performed on the _CSV source files_:

1. Remove columns that aren't used in
[Entity Type Mapping](../../toolkit/xml-configuration/connectors/entitytypemapping.md) or [Entity Association Mapping](../../toolkit/xml-configuration/connectors/entityassociationmapping.md).
2. Remove entries that have a null primary key.
3. Remove duplicates.
4. Sort entries according to the primary key.

The result of the _Prepare-Synchronization_ is stored in the [Application Settings](../../../configuration/network-configuration/server-configuration/general-purpose.md) as three files:

- For every entity type of the relevant _Connector_ involved in an
[Entity Type Mapping](../../toolkit/xml-configuration/connectors/entitytypemapping.md) or an [Entity Association Mapping](../../toolkit/xml-configuration/connectors/entityassociationmapping.md), a `.sorted.csv` file is generated, containing the final, cleansed, and sorted result.
- Duplicates are kept in a separate `.duplicates.csv` file.
- Null primary key entries are kept in a separate `.nullpk.csv` file.

All files produced by the task are in the work folder > Collect directory. See the [Application Settings](../../../configuration/network-configuration/server-configuration/general-purpose.md) topic for additional information.

### Compute changes

In _incremental_ mode, changes might need to be computed by the _Agent_:

- If the Export step has provided computed changes, no further process is required. The changes will
be sent as-is to the server.
- If the Export step has provided a full extract of the managed systems, the
_Prepare-Synchronization_ step computes changes. This computation is based on the result of the last data cleansing, generated by the previous _Prepare-Synchronization_, and stored in the `previous` folder in the _export directory_. See the [Application Settings](../../../configuration/network-configuration/server-configuration/general-purpose.md) topic for additional information.

For _incremental_ mode, it is **recommended**, whenever possible, to use managed systems to compute changes. Dedicated workstations and knowledge of the inner data organization allow managed systems to compute changes with performance that Identity Manager can't match. Using managed systems for these operations avoids generating heavy files and alleviates Identity Manager's processing load.

The result is a set of clean lists of changes stored as a `.sorted.delta` file containing a _command_ column. The _command_ column can take the following values:

- _insert_
- _update_
- _delete_
- _merge_

These values are instructions for the _Synchronization_ step to apply the changes to the database.

The `.sorted` file (that is, the **original** clean export file, **not** the changes) is stored in the `previous` folder inside the _export directory_. It will be used as a reference for the next _incremental_ Prepare-Synchronization to compute the changes, if needed. See the [Application Settings](../../../configuration/network-configuration/server-configuration/general-purpose.md) topic for additional information.

Tampering with the `previous` folder content would result in false changes leading to false computation. It would result in data corruption in the Identity Manager database. To restore the Identity Manager database and reflect the managed system data updates, a _complete\_\_Sync Up_ would be required.

### Prepare the server

At the beginning of every _Prepare-Synchronization_ process, the _Server_ is notified via HTTP.

Upon receiving the notification, the server creates a directory on its host environment, identified by a unique GUID, to contain `.sorted` or `.sorted.delta` files that will be sent by the agent.

This is designed to prevent network errors that would cause an _incremental_ database update to happen more than once.

This means that several _Export_ and _Prepare-Synchronization_ tasks can be executed simultaneously. These tasks will be processed by the server one at a time, in the right order.

Any notification of a _complete_ Prepare-Synchronization would cancel the previous non-processed _incremental_ Prepare-Synchronizations. As a _complete_ Prepare-Synchronization reloads the whole database, it renders _incremental_ changes computation moot.

### Send clean exports

`.sorted` or `.sorted.delta` files are sent over HTTP to the _Server_ for the last step.

### Example

The figure models the complete _Prepare-Synchronization_ steps applied to an Active Directory export. The matching _Connector_ defines an Entity Type _AD Entry_ and two associations (_members_ and _manager_).

![Active Directory Prepare-Synchronization Example](/images/identitymanager/ad_preparesynchro_example.webp)

## Examples

`Usercube-Prepare-Synchronization` can be used as an executable file as follows:

```text
./Usercube-Prepare-Synchronization --api-url myserver.usercube.com --api-client-id myclientid --api-secret myclient secret --connector --agent myagent --synchronization-mode complete
```

## Arguments

 | Name | Details |
 | --- | --- |
 | --agent required | **Type** [Agent](../../toolkit/xml-configuration/connectors/agent.md) **Description** Identifier of the agent where the task runs. |
 | --connector required | **Type** [Connector](../../toolkit/xml-configuration/connectors/connector.md) **Description** Identifier of the linked connector. The task is linked to a connector whose entity types are synchronized. |
 | --synchronization-mode required | **Type** [Upward Data Synchronization](../../../configuration/synchronization/upward-data-sync.md)Mode **Description** Synchronization mode for this task can be one of the following: - Initial - Complete - Incremental This must be the same as the associated Export and Synchronize tasks. Use _initial_ if this is the first time the target managed system is synchronized. Use _complete_ to load the data from the managed system as a whole. Use _incremental_ to consider only incremental changes from the last synchronization. In _incremental_ mode, the Prepare-Synchronization task computes changes in the source managed system since the last _Prepare-Synchronization_. |
 | --sources-directory default value: ExportOutput | **Type** String **Description** Directory path, relative to temp folder, from which export files to cleanse are read. See the [Application Settings](../../../configuration/network-configuration/server-configuration/general-purpose.md) topic for additional information |
 | --working-directory default value: Collect | **Type** String **Description** The directory path, relative to work folder, to which intermediary and cleansed files are stored. See the [Application Settings](../../../configuration/network-configuration/server-configuration/general-purpose.md) topic for additional information |
 | --- | --- |
 | --- | --- |
 | --api-client-id required | **Type** String **Description** Login used to authenticate to the server. Every request from agent to server needs to be authenticated with an OpenID Connect ClientId/Secret pair, linked to a profile with the relevant permissions. See the [OpenIdClient](../../toolkit/xml-configuration/access-control/openidclient.md) topic for additional information. |
 | --api-secret required | **Type** String **Description** Password used to authenticate to the server. Every request from agent to server needs to be authenticated with an OpenID Connect ClientId/Secret pair, linked to a profile with the relevant permissions. See the [OpenIdClient](../../toolkit/xml-configuration/access-control/openidclient.md) topic for additional information. |
 | --api-url required | **Type** String **Description** URL of Identity Manager server. |
 | --- | --- |
 | --- | --- |
 | --log-level optional | **Type** LogLevel **Description** Level of log information among: `Verbose`; `Debug`; `Information`; `Warning`; `Error`; `Fatal`. |

