1

Using a script that I found on Stack Exchange, I am able to replicate everything in my enterprise geodatabase to file geodatabase except the Facilities dataset. Can anyone help with why only the Facilities Dataset fails to copy?

When I isolate the Facilities Dataset in the code it does copy properly but always fails in the scheduled script and in the the full script. My enterprise geodatabase is based on the LGIM. We are in ArcGIS 10.5 on SQL Server The script is called from Windows Task Scheduler. I get this error

[INFO] [04/10/2017 05:32:29 PM] [75] - Atempting to Copy Facilities to C:\AC\BackUps\20170410AC_Pro.gdb\Facilities
[INFO] [04/10/2017 05:33:12 PM] [79] - Unable to copy Facilities to C:\AC\BackUps\20170410AC_Pro.gdb\Facilities
[INFO] [04/10/2017 05:33:12 PM] [80] - ERROR 000260: Failed to copy C:\Users\bmay\AppData\Roaming\ESRI\Desktop10.5\ArcCatalog\AC_Pro.sde\AC_Pro.DBO.Facilities into C:\AC\BackUps\20170410AC_Pro.gdb\Facilities
ERROR 000260: The table already exists.--The item was not found.--The item was not found.
Failed to execute (Copy).

From research, I gather there are similar problems with data maintained in ARCFM.
Here's the code:

import time, os, datetime, sys, logging, logging.handlers, shutil
import arcpy

########################## user defined functions ##############################

def getDatabaseItemCount(workspace):
    log = logging.getLogger("script_log")
    """returns the item count in provided database"""
    arcpy.env.workspace = workspace
    feature_classes = []
    log.info("Compiling a list of items in {0} and getting count.".format(workspace))
    for dirpath, dirnames, filenames in arcpy.da.Walk(workspace,datatype="Any",type="Any"):
        for filename in filenames:
            feature_classes.append(os.path.join(dirpath, filename))
    log.info("There are a total of {0} items in the database".format(len(feature_classes)))
    return feature_classes, len(feature_classes)

def replicateDatabase(dbConnection, targetGDB):
    log = logging.getLogger("script_log")
    startTime = time.time()

    if arcpy.Exists(dbConnection):
        featSDE,cntSDE = getDatabaseItemCount(dbConnection)
        log.info("Geodatabase being copied: %s -- Feature Count: %s" %(dbConnection, cntSDE))
        if arcpy.Exists(targetGDB):
            featGDB,cntGDB = getDatabaseItemCount(targetGDB)
            log.info("Old Target Geodatabase: %s -- Feature Count: %s" %(targetGDB, cntGDB))
            try:
                shutil.rmtree(targetGDB)
                log.info("Deleted Old %s" %(os.path.split(targetGDB)[-1]))
            except Exception as e:
                log.info(e)

        GDB_Path, GDB_Name = os.path.split(targetGDB)
        log.info("Now Creating New %s" %(GDB_Name))
        arcpy.CreateFileGDB_management(GDB_Path, GDB_Name)

        arcpy.env.workspace = dbConnection

        try:
            datasetList = [arcpy.Describe(a).name for a in arcpy.ListDatasets()]
        except Exception, e:
            datasetList = []
            log.info(e)
        try:
            featureClasses = [arcpy.Describe(a).name for a in arcpy.ListFeatureClasses()]
        except Exception, e:
            featureClasses = []
            log.info(e)
        try:
            tables = [arcpy.Describe(a).name for a in arcpy.ListTables()]
        except Exception, e:
            tables = []
            log.info(e)

        #Compiles a list of the previous three lists to iterate over
        allDbData = datasetList + featureClasses + tables

        for sourcePath in allDbData:
            targetName = sourcePath.split('.')[-1]
            targetPath = os.path.join(targetGDB, targetName)
            if not arcpy.Exists(targetPath):
                try:
                    log.info("Atempting to Copy %s to %s" %(targetName, targetPath))
                    arcpy.Copy_management(sourcePath, targetPath)
                    log.info("Finished copying %s to %s" %(targetName, targetPath))
                except Exception as e:
                    log.info("Unable to copy %s to %s" %(targetName, targetPath))
                    log.info(e)
            else:
                log.info("%s already exists....skipping....." %(targetName))

        featGDB,cntGDB = getDatabaseItemCount(targetGDB)
        log.info("Completed replication of %s -- Feature Count: %s" %(dbConnection, cntGDB))

    else:
        log.info("{0} does not exist or is not supported! \
        Please check the database path and try again.".format(dbConnection))

#####################################################################################

def formatTime(x):
    minutes, seconds_rem = divmod(x, 60)
    if minutes >= 60:
        hours, minutes_rem = divmod(minutes, 60)
        return "%02d:%02d:%02d" % (hours, minutes_rem, seconds_rem)
    else:
        minutes, seconds_rem = divmod(x, 60)
        return "00:%02d:%02d" % (minutes, seconds_rem)

if __name__ == "__main__":
    startTime = time.time()
    now = datetime.datetime.now()

    ############################### user variables #################################
    '''change these variables to the location of the database being copied, the target
    database location and where you want the log to be stored'''

    logPath = ""
    databaseConnection = "path_to_sde_or_gdb_database"
    targetGDB = "apth_to_replicated_gdb\\Replicated.gdb"

    ############################### logging items ###################################
    # Make a global logging object.
    logName = os.path.join(logPath,(now.strftime("%Y-%m-%d_%H-%M.log")))

    log = logging.getLogger("script_log")
    log.setLevel(logging.INFO)

    h1 = logging.FileHandler(logName)
    h2 = logging.StreamHandler()

    f = logging.Formatter("[%(levelname)s] [%(asctime)s] [%(lineno)d] - %(message)s",'%m/%d/%Y %I:%M:%S %p')

    h1.setFormatter(f)
    h2.setFormatter(f)

    h1.setLevel(logging.INFO)
    h2.setLevel(logging.INFO)

    log.addHandler(h1)
    log.addHandler(h2)

    log.info('Script: {0}'.format(os.path.basename(sys.argv[0])))

    try:
        ########################## function calls ######################################

        replicateDatabase(databaseConnection, targetGDB)

        ################################################################################
    except Exception, e:
        log.exception(e)

    totalTime = formatTime((time.time() - startTime))
    log.info('--------------------------------------------------')
    log.info("Script Completed After: {0}".format(totalTime))
    log.info('--------------------------------------------------')
0

1 Answer 1

1

Check that there are not duplicated table names in your geodatabase. I have seen this happen before when a table name was accidentally used on two tables/feature classes.

This is possible in an enterprise Geodatabase where there are multiple user schemas used. e.g. AC_Pro.DBO.Facilities and AC_Pro.GISUser.Facilities etc. When copying to the file geodatabase the schema/owner is removed and so if Facilities already exists from one table, the second won't be able to copy.

To work around this I checked that all tables were in the default schema. Any it tried to copy with a different user schema had that schema name appended to the start of the table name e.g. AC_Pro.DBO.Facilities would copy as Facilities as it's in the default schema DBO, but AC_Pro.GISUser.Facilities would copy as GISUser_Facilities as it's using a different user schema.

1
  • I think I may be seeing something similar today in an ArcFM managed ArcSDE geodatabase at 10.2. Copy_management gives an ERROR 000260 and the feature class that I am trying to copy participates a relationship class. Your answer here may or may not apply to my situation but it is certainly useful to know about.
    – PolyGeo
    Oct 30, 2017 at 4:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.