Summary
The ListReplicas function lists the replicas in the workspace.
Discussion
You can specify the path to a connection file as an argument to the function or you can set the workspace environment to the connection file and call the ListReplicas function without any arguments.
Syntax
ListReplicas (workspace, {all_replicas})
Parameter | Explanation | Data Type |
workspace | The geodatabase workspace. | String |
all_replicas | Specifies whether all replica types in the geodatabase will be returned.
(The default value is False) | Boolean |
Data Type | Explanation |
Replica | A list returned from the function containing Replica objects. If the all_replicas argument is set to True, SyncReplica objects may also be returned. |
Code sample
For every replica in a workspace that is a sender, call the ExportDataChangeMessage function.
import arcpy
import os
sdeConnection = "C:/Data/toolboxDEFAULTVersion.sde"
outLocation = "C:/data"
for replica in arcpy.da.ListReplicas(sdeConnection):
# If the replica is a sender, call ExportDataChangeMessage
if replica.isSender:
changesFile = os.path.join(outputLocation,
f"changes_{replica.name}.gdb")
arcpy.management.ExportDataChangeMessage(sdeConnection,
changes,
replica.name)
Print all replicas that are in conflict.
import arcpy
sdeConnection = "C:/Data/toolboxDEFAULTVersion.sde"
# Print the name of the replicas that are in conflict
for replica in arcpy.da.ListReplicas(sdeConnection):
if replica.hasConflicts:
print(replica.name)
Print the properties of a SyncReplica object
import arcpy
# Use the ListReplicas function to return all replicas in the geodatabase
replicas = arcpy.da.ListReplicas("C:\\Projects\\MyProject\\myGDB.sde", True)
for r in replicas:
# Check if the class is a SyncReplica
if isinstance(r, arcpy.da.SyncReplica):
# Print the properties of a SyncReplica object
print(f"Properties of replica named: {r.name}")
print(f"Datasets: {r.datasets}")
print(f"Owner: {r.owner}")
print(f"Replica ID: {r.replicaID}")
print(f"Service name: {r.serviceName}")
print(f"Version: {r.version}")
print(f"Direction: {r.direction}")
print(f"Sync model: {r.syncModel}")
print(f"Last sync date: {r.lastSyncDate}")
print(f"LayerServerGens: {r.layerServerGens}")
print(f"LayerServerSibGens: {r.layerServerSibGens}")
print(f"ReplicaServerGen: {r.replicaServerGen}")
print(f"ReplicaServerSibGen: {r.replicaServerSibGen")
print(f"Target type: {r.targetType}")
Print the creationDate, replicaDate, and geometry properties of each Replica or SyncReplica object. A Replica or SyncReplica object can have a creationDate property value, a replicaDate property value, or both. The creationDate and replicaDate properties describe when the replica was created; however, the creationDate property is in UTC, and the replicaDate property is in the time zone of the server machine. The geometry property is the replica’s spatial filter geometry.
import arcpy
# Use the ListReplicas function to return all Replicas and SyncReplicas in the geodatabase
replicas = arcpy.da.ListReplicas("C:\\gdb\\mygeodatabase.sde", True)
for r in replicas:
# Print Replica or SyncReplica object properties
if hasattr(r, 'creationDate'):
print(str(r.creationDate))
if hasattr(r, 'replicaDate'):
print(str(r.replicaDate))
if hasattr(r, 'geometry') and (r.geometry is not None):
print(str(r.geometry.JSON))