利用bat调用py备份SDE数据到GDB中
@echo off set SDEServer=192.168.0.16 set GeoSDEService=5151 set GeoUserName=USER_Mingkof set GeoUserPassWord=UPWD_Mingkof rem 名称用,分割 set GeoFeatureClassNames=GIS_T1,GIS_T2 echo ————————————————————————————— echo 正在导出空间数据 echo ————————————————————————————— echo ' echo ' echo ' python SDE2GBD.py %SDEServer% %GeoSDEService% %GeoUserName% %GeoUserPassWord% %GeoFeatureClassNames% echo ' echo ' echo ' echo ————————————————————————————— echo 空间数据导出完成! echo ————————————————————————————— echo. & pause
__author__ = 'Mingkof' # coding=cp936 # Import arcpy module import os import arcpy from arcpy import env import time env.overwriteOutput = True #SDE主机地址 SDEServer = arcpy.GetParameterAsText(0) #SDE服务端口号 SDEService = arcpy.GetParameterAsText(1) #SDE用户名 SDEUsername = arcpy.GetParameterAsText(2) #SDE用户密码 SDEPassword = arcpy.GetParameterAsText(3) #需要复制的图层名称 FeatureClass_list = arcpy.GetParameterAsText(4) FeatureClass_list = str.split(FeatureClass_list, ",") try: yyMMdd = time.strftime('%Y%m%d', time.localtime(time.time())) hhmmss = time.strftime('%H%M%S', time.localtime(time.time())) #年月日文件夹 out_GDB_Folder_Path = os.path.abspath('.') + "\\" + yyMMdd SDEFilePath = out_GDB_Folder_Path SDEFileName = hhmmss #时分秒文件 out_GDB_Name = hhmmss #GDB文件路径 out_GDB_Path = out_GDB_Folder_Path + '\\' + out_GDB_Name + '.gdb' #创建目录 if not os.path.exists(out_GDB_Folder_Path): os.mkdir(out_GDB_Folder_Path) print '创建输出目录结束' #创建GDB文件 arcpy.CreateFileGDB_management(out_GDB_Folder_Path, out_GDB_Name, "CURRENT") print '创建GDB文件结束' #.sde文件路径 SDEFilePath_SDE = SDEFilePath + "\\" + SDEFileName + ".sde" if os.path.isfile(SDEFilePath_SDE): os.remove(SDEFilePath_SDE) print '删除已有sde文件结束' #创建SDE文件 arcpy.CreateArcSDEConnectionFile_management(SDEFilePath, SDEFileName, SDEServer, SDEService, "", "DATABASE_AUTH", SDEUsername, SDEPassword, "SAVE_USERNAME", "SDE.DEFAULT", "SAVE_VERSION") print '创建SDE文件结束' print "SDE导出GDB开始" #循环输出 FeatureClass_listCount = len(FeatureClass_list) indexI = 1 for tempFeature in FeatureClass_list: print '正在处理' + str(indexI) + "/" + str(FeatureClass_listCount) + "_" + tempFeature indexI += 1 tempSDE = SDEFilePath_SDE + "\\" + tempFeature tempGBD = out_GDB_Path + "\\" + tempFeature arcpy.CopyFeatures_management(tempSDE, tempGBD, "", "0", "0", "0") #删除sde文件 if os.path.isfile(SDEFilePath_SDE): os.remove(SDEFilePath_SDE) print '删除sde文件结束' print "SDE导出GDB结束" except ValueError: print ValueError