AnsweredAssumed Answered

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

Question asked by suryakant on May 26, 2015
Latest reply on Jun 5, 2018 by ScottEvans_CCG

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
        replica_list = arcpy.da.ListReplicas(geodatabase_2)
        replica_user = (".")[0] for user in replica_list if".")[-1] == in_replica.split(".")[-1]).next()
        connected_users = [con_user for con_user in arcpy.ListUsers(admin_sde) if con_user.ClientName != socket.gethostname()]'Pausing user connection to geo-database: "{}"\n'.format(geodatabase_2))
        arcpy.AcceptConnections(admin_sde, False)'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)'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:
        return error
    finally:'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.