在 Informix 中编写地理数据库升级脚本

可以修改和使用在本主题中提供的其中一个 Python 脚本来连接和升级企业级地理数据库。

第一组脚本使用现有数据库连接文件来连接和升级地理数据库。

第二个脚本显示如何能够在用于升级地理数据库的同一脚本中提供连接信息。此脚本在无法访问 ArcGIS for Desktop 时特别有用;您可在已安装 ArcGIS Engine(含 Geodatabase Update 扩展模块)或 ArcGIS for Server(Standard 或 Advanced)的计算机上运行 Python 脚本,并提供连接信息和升级地理数据库。

无论是使用现有数据库连接文件还是通过脚本中的参数,您所建立的与地理数据库之间的连接都是直连。运行脚本的计算机上必须有以下内容:

请确保升级之前已经阅读和执行过升级 Informix 中的地理数据库的准备工作中的步骤。

步骤:
  1. 首先,检查地理数据库是否可升级。
    1. 打开 Python。

      cd /arcgis/server/tools
      ./python
      

    2. 使用 Describe 函数检查地理数据库版本与 ArcGIS 客户端版本是否匹配。

      import arcpy
      
      isCurrent = arcpy.Describe('/tmp/egdb_connection.sde').currentRelease
      
      print isCurrent
      

    如果返回 false,则可升级地理数据库。继续执行下一步。如果返回 true,则无需升级地理数据库。

  2. 要想升级地理数据库,请将这些示例脚本中的一个脚本复制到文本编辑器中。根据需要更改任意变量值,以与您的站点信息相匹配。
    • 如果现有数据库连接文件使用直连并以地理数据库管理员的身份进行连接,则根据不同的操作系统来复制和修改以下脚本之一:
      # Name: upgradesdegdb_example.py
      # Description: Connect from a Windows computer 
      # with an existing database connection file 
      # and upgrade an enterprise geodatabase in Informix
      # Author: Esri
      
      # Import arcpy module
      import arcpy
       
      # Local variables:
      Output_Workspace = "C:\\ArcGIS\connection_files\<Connection file>"
      Default_gdb = "C:\\ArcGIS\connection_files\<Connection file>"
      
      # Process: Upgrade Geodatabase
      arcpy.UpgradeGDB_management(Default_gdb, "PREREQUISITE", "UPGRADE")
      
      # Name: upgradesdegdb_example.py
      # Description: Connect from a Linux or UNIX computer 
      # with an existing database connection file 
      # and upgrade an enterprise geodatabase in Informix
      # Author: Esri
      
      # Import arcpy module
      import arcpy
       
      # Local variables:
      Output_Workspace = "<user>/connections/<Connection_file>"
      Default_gdb = "<user>/connections/<Connection_file>"
      
      # Process: Upgrade Geodatabase
      arcpy.UpgradeGDB_management(Default_gdb, "PREREQUISITE_CHECK", "UPGRADE")
      
    • 如果计算机上没有用于编写升级脚本的数据库连接文件,则可复制和修改以下脚本:
      """
      Name: upgrade_gdb_ids.py
      Description: Create a connection file and upgrade an enterprise geodatabase.
      Author: Esri
      """
      
      # Import system modules
      import arcpy, os, optparse, sys
      
      
      # Define usage and version
      parser = optparse.OptionParser(usage = "usage: %prog [Options]", version="%prog 1.0 for " + arcpy.GetInstallInfo()['Version'] )
      
      #Define help and options
      parser.add_option ("-s", dest="Server", type="string", default="", help="RDBMS server name")
      parser.add_option ("-i", dest="Service", type="string", default="", help="Use direct connection syntax")
      parser.add_option ("-u", dest="User", type="string", default="", help="Geodatabase administrator user name")
      parser.add_option ("-p", dest="Password", type="string", default="", help="Geodatabase  administrator password")
      parser.add_option ("--upgrade", dest="Upgrade", type="choice", choices=['TRUE', 'FALSE'], default="FALSE", help="Upgrade Options (case-sensitive):  TRUE=Perform Pre-requisite check and upgrade geodatabase, FALSE=Perform Pre-requisite check only.  Default=FALSE")                   
      parser.add_option ("-D", dest="Database", type="string", default="none", help="Database name:  Not required for Oracle")
      parser.add_option ("--auth", dest="account_authentication", type ="choice", choices=['DATABASE_AUTH', 'OPERATING_SYSTEM_AUTH'], default='DATABASE_AUTH', help="Authentication type options (case-sensitive):  DATABASE_AUTH, OPERATING_SYSTEM_AUTH.  Default=DATABASE_AUTH")
      
      # Check if value entered for option
      try:
      	(options, args) = parser.parse_args()
      
      	
      #Check if no system arguments (options) entered
      	if len(sys.argv) == 1:
      		print "%s: error: %s\n" % (sys.argv[0], "No command options given")
      		parser.print_help()
      		sys.exit(3)
      	
      
      	#Usage parameters for spatial database connection
      	server = options.Server
      	service = options.Service	
      	account_authentication = options.account_authentication.upper()
      	username = options.User.lower() 
      	password = options.Password	
      	database = options.Database.lower()
      	do_upgrade = options.Upgrade
      	
      	# Get the current product license
      	product_license=arcpy.ProductInfo()
      	
      	if (license == ""):
      		print " \n%s: error:%s\n" % (sys.argv[0], "Authorization file (-l) must be specified.")
      		parser.print_help()
      		sys.exit(3)
      	
      	# Checks required license level
      	if product_license.upper() == "ARCVIEW" or product_license.upper() == 'ENGINE':
      		print "\n" + product_license + " license found!" + "  Upgrading enterprise geodatabase requires an ArcGIS Desktop Standard or Advanced license, or an ArcGIS Server license."
      		sys.exit("Re-authorize ArcGIS before enabling enterprise geodatabase.")
      	else:
      		print "\n" + product_license + " license available!  Continuing to enable..."
      		arcpy.AddMessage("+++++++++")
      	
      	
      	# Check if direct connection
      	if service.find(":") <> -1:  #This is direct connect
      		ServiceConnFileName = service.replace(":", "")
      		ServiceConnFileName = ServiceConnFileName.replace(";", "")
      		ServiceConnFileName = ServiceConnFileName.replace("=", "")
      		ServiceConnFileName = ServiceConnFileName.replace("/", "")
      		ServiceConnFileName = ServiceConnFileName.replace("\\", "")
      	else:
      		arcpy.AddMessage("\n+++++++++")
      		arcpy.AddMessage("Exiting!!")
      		arcpy.AddMessage("+++++++++")
      		sys.exit("\nSyntax for a direct connection in the Service parameter is required for enabling enterprise geodatabase.")
      	
      	
      	# Local variables
      	Conn_File_NameT = server + "_" + ServiceConnFileName + "_" + database + "_" + username    
      	
      	if os.environ.get("TEMP") == None:
      		temp = "c:\\temp"	
      	else:
      		temp = os.environ.get("TEMP")
      	
      	if os.environ.get("TMP") == None:
      		temp = "/usr/tmp"		
      	else:
      		temp = os.environ.get("TMP")  
      	
      	Connection_File_Name = temp + os.sep + Conn_File_NameT + ".sde"
      	
      	
      	# Check for the .sde file and delete it if present
      	arcpy.env.overwriteOutput=True
      	
      	
      	# Variables defined within the script; other variable options commented out at the end of the line
      	saveUserInfo = "SAVE_USERNAME"
      	saveVersionInfo = "SAVE_VERSION" 
      	# The Version shouldn't matter for non-geodatabase connection
      	version = "" 
      	
      	print "\nCreating ArcSDE Connection File...\n"
      	# Process: Create ArcSDE Connection File...
      	# Usage: out_folder_path, out_name, server, service, database, account_authentication, username, password, save_username_password, version,   save_version_info
      	arcpy.CreateArcSDEConnectionFile_management(temp, Conn_File_NameT, server, service, database, account_authentication, username, password, saveUserInfo, version, saveVersionInfo)
      	for i in range(arcpy.GetMessageCount()):
      		if "000565" in arcpy.GetMessage(i):   #Check if database connection was successful
      			arcpy.AddReturnMessage(i)
      			arcpy.AddMessage("\n+++++++++")
      			arcpy.AddMessage("Exiting!!")
      			arcpy.AddMessage("+++++++++\n")
      			sys.exit(3)            
      		else:
      			arcpy.AddReturnMessage(i)
      			arcpy.AddMessage("+++++++++\n")
      	
      	# Process: Upgrade geodatabase...
      	try:
      		if do_upgrade.lower() == "true":
      			print "Upgrading Geodatabase...\n"
      			arcpy.UpgradeGDB_management(Connection_File_Name, "PREREQUISITE_CHECK", "UPGRADE")
      			for i in range(arcpy.GetMessageCount()):
      				arcpy.AddReturnMessage(i)
      			arcpy.AddMessage("+++++++++\n")
      	
      		else:
      			print "Running Pre-Requisite Check...\n"
      			arcpy.UpgradeGDB_management(Connection_File_Name, "PREREQUISITE_CHECK", "NO_UPGRADE")
      			for i in range(arcpy.GetMessageCount()):
      				arcpy.AddReturnMessage(i)
      			arcpy.AddMessage("+++++++++\n")
      	
      	except:
      		for i in range(arcpy.GetMessageCount()):
      			arcpy.AddReturnMessage(i)
      			
      #Check if no value entered for option	
      except SystemExit as e:
      	if e.code == 2:
      		parser.usage = ""
      		print "\n"
      		parser.print_help()   
      		parser.exit(2)
      
  3. 运行已复制和更改的脚本来执行先决条件检查和升级地理数据库。

相关主题

5/10/2014