Created
February 26, 2015 21:12
-
-
Save eliotjordan/512dd8bcc67240c5e129 to your computer and use it in GitHub Desktop.
Copy ArcSDE
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## From http://support.esri.com/en/knowledgebase/techarticles/detail/40831 | |
import arcpy, os, string | |
def CopyDatasets(start_db,end_db,num): | |
#Set workspaces | |
arcpy.env.workspace = start_db | |
wk2 = end_db | |
datasetList = arcpy.ListDatasets() | |
#for feature classes within datasets | |
for dataset in datasetList: | |
print "Reading: {0}".format(dataset) | |
name = arcpy.Describe(dataset) | |
new_data=name.name[num:] | |
if arcpy.Exists(wk2 + os.sep + new_data)==False: | |
arcpy.Copy_management(dataset, wk2 + os.sep + new_data) | |
print "Completed copy on {0}".format(new_data) | |
else: | |
print "Dataset {0} already exists in the end_db so skipping".format(new_data) | |
#Clear memory | |
del dataset | |
def CopyFeatureClasses(start_db,end_db,num): | |
#Set workspaces | |
arcpy.env.workspace = start_db | |
wk2 = end_db | |
datasetList = arcpy.ListDatasets() | |
#for feature classes within datasets | |
for fc in arcpy.ListFeatureClasses(): | |
print "Reading: {0}".format(fc) | |
name = arcpy.Describe(fc) | |
new_data=name.name[num:] | |
if arcpy.Exists(wk2 + os.sep + new_data)==False: | |
arcpy.Copy_management(fc, wk2 + os.sep + new_data) | |
print "Completed copy on {0}".format(new_data) | |
else: | |
print "Feature class {0} already exists in the end_db so skipping".format(new_data) | |
#Clear memory | |
del fc | |
def CopyTables(start_db,end_db,num): | |
#Set workspaces | |
arcpy.env.workspace = start_db | |
wk2 = end_db | |
datasetList = arcpy.ListDatasets() | |
#for feature classes within datasets | |
for table in arcpy.ListTables(): | |
print "Reading: {0}".format(table) | |
name = arcpy.Describe(table) | |
new_data=name.name[num:] | |
if arcpy.Exists(wk2 + os.sep + new_data)==False: | |
arcpy.Copy_management(table, wk2 + os.sep + new_data) | |
print "Completed copy on {0}".format(new_data) | |
else: | |
print "Table {0} already exists in the end_db so skipping".format(new_data) | |
#Clear memory | |
del table | |
if __name__== "__main__": | |
start_db = r"Database Connections\Jie.sde" #Origin Database | |
end_db = r"Database Connections\MXD2.sde" #To database | |
num = 8 #number of characters in schema (for example: sde.sde. is 8) | |
CopyDatasets(start_db,end_db,num) | |
CopyFeatureClasses(start_db,end_db,num) | |
CopyTables(start_db,end_db,num) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment