Problem with schema synchronization using Import Replica Schema (Data Management)

3486
4
05-26-2015 04:19 AM
Highlighted
New Contributor III

I want to synchronize the schema of replica in disconnected environment. The steps I am following is documented in ArcGIS Resources:

  1. Export the geodatabase_1 replica schema using Export Replica Schema (Data Management) tool.
  2. Compare the schema of geodatabase_1 and geodatabase_2 replica using Compare Replica Schema (Data Management) tool.
  3. Import the compared schema (.xml) to geodatabase_2 replica using Import Replica Schema (Data Management) tool.

Code sample to import is:

def import_schema(admin_sde, geodatabase_2, in_replica, schema):

    """

     import compared replica schema to geodatabase

    :param admin_sde: admin connection to disconnect users

    :param geodatabase_2: import schema to geodatabase

    :param in_replica: import schema for replica

    :param schema: schema xml

    """

    try:

        replica_list = arcpy.da.ListReplicas(geodatabase_2)

        replica_user = (user.name.split(".")[0] for user in replica_list if user.name.split(".")[-1] == in_replica.split(".")[-1]).next()

        connected_users = [con_user for con_user in arcpy.ListUsers(admin_sde) if con_user.ClientName != socket.gethostname()]

        log.info('Pausing user connection to geo-database: "{}"\n'.format(geodatabase_2))

        arcpy.AcceptConnections(admin_sde, False)

        log.info('Disconnecting users except for: "{}" and "SDE" from the geo-database: "{}"\n'.format(replica_user, geodatabase_2))

        for user in connected_users:

            arcpy.DisconnectUser(admin_sde, user.ID)

        log.info('Importing schema file to geo-database: "{}" on replica: "{}"\n'.format(geodatabase_2, in_replica))

        result = arcpy.ImportReplicaSchema_management(geodatabase_2, schema)

        return result

    except Exception as error:

        log.error(error)

        return error

    finally:

        log.info('Resuming geo-database: "{}"\n'.format(geodatabase_2))

        arcpy.AcceptConnections(admin_sde, True)

When I import the compared schema through python script, it adds the new fields to geodatabase_2 but do not delete the fields which are already been deleted in geodatabase_1. This leads to too many unwanted fields in the geodatabase_2 replica. While working on ArcMap (Distributed Geodatabase -> Import Schema Changes), it opens a Import Schema Changes Wizard where we can select the dropped fields and apply the schema changes to geodatabase_2. How to achieve this via python script?

I want the same schema should reflect at geodatabase_1 and geodatabase_2 replica after importing compared schema xml.

0 Kudos
4 Replies
Highlighted
Occasional Contributor III

Are you able to do schema synchronization manually by right clicking geodatabse connection in Arccatalog and using the tools from distributed geodatabase.

0 Kudos
Highlighted
New Contributor III

Yes, from ArcMap->Distributed Geodatabase this works fine. The tool from system toolboxes is also works but the tools lacks the more control over the sync as the "Distribute Geodatabase" have.

0 Kudos
Highlighted
New Contributor

Did you ever find a solution to this? I'm running into the same issue now.

0 Kudos
Highlighted
Occasional Contributor

Also running into this issue.  After some trial and error, going back and forth between the GUI and python environment, it appears as though the 'checkbox' step is somehow being neglected in the script.  When running the tool via the toolbar you have to manually check the Apply box (see below).

As clarification, when I say I've tried it in the GUI environment, I mean both the Geoprocessing tool via ArcToolbox (Data Management Tools > Distributed Geodatabase > Import Replica Schema), by right clicking on the replica GDB and selecting Distributed Geodatabase > Import Schema Changes, and using the toolbar.  It is interesting to note that the checkbox option is not available via the Geoprocessing tool, however, changes seem to go through just fine.

Very problematic because I'd like to run replication programmatically ... either a weekly, if not a daily basis ... 

0 Kudos