How can I check whether a replica exists, with python, before using arcpy.CreateReplica_management() ?

2204
2
Jump to solution
02-21-2017 02:22 PM
RebeccaStrauch__GISP
MVP Emeritus

I'm working on a script/tool for a python addin that will let me create a replicas, one at a time per tool run, but to different locations.  Another script will allow me to sync the replicas.  These will be one-way replicas, from a SQL SDE to file GDBs.  Currently I am using ArcGIS Desktop 10.3.1 advanced, SDE SQL2008.

In theory, this will be done once for each location and I will probably include an attribute so I can control the replica name. 

If by chance I mess up and use the same name for a replica, I will get an (expected) error:

PYTHON ERRORS:
  File "c:\program files (x86)\arcgis\desktop10.3\arcpy\arcpy\management.py", line 808, in CreateReplica
    raise e

<class 'arcgisscripting.ExecuteError'>: ERROR 000775: Replica with the same name already exists.
Failed to execute (CreateReplica).

GP ERRORS:
ERROR 000775: Replica with the same name already exists.
Failed to execute (CreateReplica).

Q1: How can I test whether the replica already exists (so I can exit cleanly with message)?  Also, I would want to use a similar test before I try to sync.

Q2:  Is there a way in python/arcpy to list all the replicas that currently exist?  (additional info would be nice, but not mandatory)

Thanks

tagging Geodatabase

1 Solution

Accepted Solutions
ManviLather1
Occasional Contributor

Q1: How can I test whether the replica already exists (so I can exit cleanly with message)?  Also, I would want to use a similar test before I try to sync.

--In Arc Catalog -> right click on the geodatabase connection -> distributed geodatabase -> Manage replica
 or
 
you can use "Replica Manager". With this utility, you can rename, refresh, and review the properties of each replica as well as remove datasets from a replica.
 
 A quick tour of replica management
http://desktop.arcgis.com/en/arcmap/10.3/manage-data/geodatabases/a-quick-tour-of-replica-management...

Q2:  Is there a way in python/arcpy to list all the replicas that currently exist?  (additional info would be nice, but not mandatory)

Please refer to the following link:
ListReplicas
http://pro.arcgis.com/en/pro-app/arcpy/data-access/listreplicas.htm

Thanks

View solution in original post

2 Replies
ManviLather1
Occasional Contributor

Q1: How can I test whether the replica already exists (so I can exit cleanly with message)?  Also, I would want to use a similar test before I try to sync.

--In Arc Catalog -> right click on the geodatabase connection -> distributed geodatabase -> Manage replica
 or
 
you can use "Replica Manager". With this utility, you can rename, refresh, and review the properties of each replica as well as remove datasets from a replica.
 
 A quick tour of replica management
http://desktop.arcgis.com/en/arcmap/10.3/manage-data/geodatabases/a-quick-tour-of-replica-management...

Q2:  Is there a way in python/arcpy to list all the replicas that currently exist?  (additional info would be nice, but not mandatory)

Please refer to the following link:
ListReplicas
http://pro.arcgis.com/en/pro-app/arcpy/data-access/listreplicas.htm

Thanks

RebeccaStrauch__GISP
MVP Emeritus

Thanks Manvi.  The ListReplicas—Help | ArcGIS Desktop  will work great for Q2.  I included the Desktop link vs the Pro one you had...but same concept.

For Q1, right after I sent push the submit button, I thought about the stand "try: except" option. That does enough so I can use that.

Basically the things I add (need to clean up a bit):

try:
  arcpy.AddMessage("in the try")
  #myMsgs("in the try")
  arcpy.CreateReplica_management(in_data, replicaType, replicaOutGDB, replicaName, replicaAccessType, replicaSender, replicaRecords)
  #myMsgs("ok if it made it here")
except:
  arcpy.AddMessage("{0} exists".format(replicaName))
  #myMsgs("{0} exists".format(replicaName))
  
for replica in arcpy.da.ListReplicas(masterGDB):
    print(replica.name)  

I had looked at the help for the Replica Manager, but I didn't see a way to use this in a script.  But since above will work, I'm good to go.

Thanks for the quick response!