ListReplicas

Summary

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})
ParameterExplanationData Type
workspace

A geodatabase workspace.

String
all_replicas

Specifies whether to return all replica types in the geodatabase.

  • True—Return all types of replicas. This may include Replica or SyncReplica objects.
  • False—Return only Replica objects. These include replicas created from geodatabase replication workflows as well as replicas created from feature services running on traditional versioned data. This is the default.

(The default value is False)

Boolean
Return Value
Data TypeExplanation
Replica

A list returned from the function containing Replica objects.

If the all_replicas argument has been set to True, SyncReplica objects may also be returned.

Code sample

ListReplicas example 1

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,
                                   "changes_{0}.gdb".format(replica.name))
        arcpy.ExportDataChangeMessage_management(sdeConnection,
                                                 changes,
                                                 replica.name)
ListReplicas example 2

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)
ListReplicas example 3

Print the properties of a SyncReplica object

# Import required modules
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("Properties of replica named: {}".format(r.name))
        print("Datasets: {}".format(r.datasets))    
        print("Owner: {}".format(r.owner))
        print("Replica ID: {}".format(r.replicaID))
        print("Service name: {}".format(r.serviceName))
        print("Version: {}".format(r.version))
        print("Direction: {}".format(r.direction))
        print("Sync model: {}".format(r.syncModel))
        print("Last sync date: {}".format(r.lastSyncDate))
        print("LayerServerGens: {}".format(r.layerServerGens))
        print("LayerServerSibGens: {}".format(r.layerServerSibGens))
        print("ReplicaServerGen: {}".format(r.replicaServerGen))
        print("ReplicaServerSibGen: {}".format(r.replicaServerSibGen))
        print("Target type: {}".format(r.targetType))

Related topics


In this topic