Select to view content in your preferred language

Reconcile & Post Question

2076
4
Jump to solution
03-13-2018 05:50 AM
JordanMiller4
Frequent Contributor

I created a version called GIS.GIS Data so that operators out in the field could GPS data and I could review it and post the edits to my own version before reaching the Default. My only concern is that our current reconcile and post scripts is grabbing data from each of the child versions under the Default each night. Is there a command in python that would exclude any child versions created underneath another child version from being reconciled and posted to the default? I am very new to the workflow and I would really appreciate some guidance. Thanks

import arcpy, time, smtplib, os

deleteVersions = False
arcpy.env.overwriteOutput = True
reconcileLog = r'C:\temp\Daily_Reconcile_Log\Reconcile_Log.txt'

# set the workspace
arcpy.env.workspace = 'C:\Users\jnmiller\AppData\Roaming\ESRI\Desktop10.6\ArcCatalog\SDE.sde'

# Set a variable for the workspace
adminConn = arcpy.env.workspace

# Block new connections to the database.
#print("The database is no longer accepting connections")
#arcpy.AcceptConnections(adminConn, False)

# Wait 15 minutes
#time.sleep(900)

# Disconnect all users from the database.
print("Disconnecting all users")
arcpy.DisconnectUser(adminConn, "ALL")

# Get a list of versions to pass into the ReconcileVersions tool.
print("Getting list of all versions")
versionList = arcpy.ListVersions(adminConn)

for version in versionList:
    if 'default' in version.lower():
        if 'dbo' in version.lower():
            defaultVersion = 'dbo.DEFAULT'
        elif 'sde' in version.lower():
            defaultVersion = 'sde.DEFAULT'


# Execute the ReconcileVersions tool.
print("Reconciling/posting/deleting all versions")
if deleteVersions:
    try:
        arcpy.ReconcileVersions_management(adminConn, "ALL_VERSIONS", defaultVersion, versionList, "LOCK_ACQUIRED", "NO_ABORT", "BY_OBJECT", "FAVOR_EDIT_VERSION", "POST", "DELETE_VERSION", reconcileLog)
    except:
        reconcileMessage = "Reconcile failed:  " + arcpy.GetMessages() + ".  Check reconcilelog.txt file in the " + str(reconcileLog)
        arcpy.AddWarning(reconcileMessage)
        pass
else:
    try:
        arcpy.ReconcileVersions_management(adminConn, "ALL_VERSIONS", defaultVersion, versionList, "LOCK_ACQUIRED", "NO_ABORT", "BY_OBJECT", "FAVOR_EDIT_VERSION", "POST", "KEEP_VERSION", reconcileLog)
    except:
        reconcileMessage = "Reconcile failed:  " + arcpy.GetMessages() + ".  Check reconcilelog.txt file in the " + str(reconcileLog)
        arcpy.AddWarning(reconcileMessage)
        pass
print("Completed Reconcile & Post")

# Run the compress tool. 
print("Running compress")

arcpy.Compress_management(adminConn)
print("Compress Completed")

# Allow the database to begin accepting connections again
#print("Allow users to connect to the database again")
#arcpy.AcceptConnections(adminConn, True)

print("Starting Rebuild Indexes")
# Get a list of all the datasets the user has access to.
# First, get all the stand alone tables, feature classes and rasters.
dataList = arcpy.ListTables() + arcpy.ListFeatureClasses() + arcpy.ListRasters()

# Next, for feature datasets get all of the datasets and featureclasses
# from the list and add them to the master list.
for dataset in arcpy.ListDatasets("", "Feature"):
    arcpy.env.workspace = os.path.join(adminConn,dataset)
    dataList += arcpy.ListFeatureClasses() + arcpy.ListDatasets()

# Get the user name for the workspace
userName = arcpy.Describe(adminConn).connectionProperties.user.lower()

# remove any datasets that are not owned by the connected user.
userDataList = [ds for ds in dataList if ds.lower().find(".%s." % userName) > -1]

# Execute rebuild indexes
# Note: to use the "SYSTEM" option the workspace user must be an administrator.
arcpy.RebuildIndexes_management(adminConn, "SYSTEM", userDataList, "ALL")
print('Rebuild Complete')

# Update statistics on the system tables
# print("Updating statistics on the system tables")
# Execute analyze datasets
# Note: to use the "SYSTEM" option the workspace user must be an administrator.
arcpy.AnalyzeDatasets_management(adminConn, "SYSTEM", userDataList, "ANALYZE_BASE","ANALYZE_DELTA","ANALYZE_ARCHIVE")
print("Analyze Complete")

print("Finished.")
1 Solution

Accepted Solutions
JakeSkinner
Esri Esteemed Contributor

Hi Jordan,

You can create another list to include which versions you want to reconcile.  For example, in the below a new list (reconcileVersionList) is created and all versions except GIS.GIS Data are added to it.  The ReconcileVersions_management function then reconciles all versions in this list.

# Get a list of versions to pass into the ReconcileVersions tool.
print("Getting list of all versions")
versionList = arcpy.ListVersions(adminConn)

for version in versionList:
    if 'default' in version.lower():
        if 'dbo' in version.lower():
            defaultVersion = 'dbo.DEFAULT'
        elif 'sde' in version.lower():
            defaultVersion = 'sde.DEFAULT'

reconcileVersionList = []
for version in versionList:
    if version != 'GIS.GIS Data':
        reconcileVersionList.append(version)


# Execute the ReconcileVersions tool.
print("Reconciling/posting/deleting all versions")
if deleteVersions:
    try:
        arcpy.ReconcileVersions_management(adminConn, "ALL_VERSIONS", defaultVersion, reconcileVersionList, "LOCK_ACQUIRED", "NO_ABORT", "BY_OBJECT", "FAVOR_EDIT_VERSION", "POST", "DELETE_VERSION", reconcileLog)
    except:
        reconcileMessage = "Reconcile failed:  " + arcpy.GetMessages() + ".  Check reconcilelog.txt file in the " + str(reconcileLog)
        arcpy.AddWarning(reconcileMessage)
        pass
else:
    try:
        arcpy.ReconcileVersions_management(adminConn, "ALL_VERSIONS", defaultVersion, reconcileVersionList, "LOCK_ACQUIRED", "NO_ABORT", "BY_OBJECT", "FAVOR_EDIT_VERSION", "POST", "KEEP_VERSION", reconcileLog)
    except:
        reconcileMessage = "Reconcile failed:  " + arcpy.GetMessages() + ".  Check reconcilelog.txt file in the " + str(reconcileLog)
        arcpy.AddWarning(reconcileMessage)
        pass
print("Completed Reconcile & Post")

View solution in original post

4 Replies
JakeSkinner
Esri Esteemed Contributor

Hi Jordan,

You can create another list to include which versions you want to reconcile.  For example, in the below a new list (reconcileVersionList) is created and all versions except GIS.GIS Data are added to it.  The ReconcileVersions_management function then reconciles all versions in this list.

# Get a list of versions to pass into the ReconcileVersions tool.
print("Getting list of all versions")
versionList = arcpy.ListVersions(adminConn)

for version in versionList:
    if 'default' in version.lower():
        if 'dbo' in version.lower():
            defaultVersion = 'dbo.DEFAULT'
        elif 'sde' in version.lower():
            defaultVersion = 'sde.DEFAULT'

reconcileVersionList = []
for version in versionList:
    if version != 'GIS.GIS Data':
        reconcileVersionList.append(version)


# Execute the ReconcileVersions tool.
print("Reconciling/posting/deleting all versions")
if deleteVersions:
    try:
        arcpy.ReconcileVersions_management(adminConn, "ALL_VERSIONS", defaultVersion, reconcileVersionList, "LOCK_ACQUIRED", "NO_ABORT", "BY_OBJECT", "FAVOR_EDIT_VERSION", "POST", "DELETE_VERSION", reconcileLog)
    except:
        reconcileMessage = "Reconcile failed:  " + arcpy.GetMessages() + ".  Check reconcilelog.txt file in the " + str(reconcileLog)
        arcpy.AddWarning(reconcileMessage)
        pass
else:
    try:
        arcpy.ReconcileVersions_management(adminConn, "ALL_VERSIONS", defaultVersion, reconcileVersionList, "LOCK_ACQUIRED", "NO_ABORT", "BY_OBJECT", "FAVOR_EDIT_VERSION", "POST", "KEEP_VERSION", reconcileLog)
    except:
        reconcileMessage = "Reconcile failed:  " + arcpy.GetMessages() + ".  Check reconcilelog.txt file in the " + str(reconcileLog)
        arcpy.AddWarning(reconcileMessage)
        pass
print("Completed Reconcile & Post")
AndresCastillo
MVP Regular Contributor
0 Kudos
AnudeepGorantla
Emerging Contributor

I have Multiple feature classes under my version. Is there a way That i can tell to reconcile just one feature class instead of all the features classes under my version in sde.

0 Kudos
JakeSkinner
Esri Esteemed Contributor

Anudeep Gorantla‌ unfortunately, this will not be possible.  When reconciling, it is performed at the version level for all feature classes. 

0 Kudos