AnsweredAssumed Answered

Backing up databases

Question asked by Tonyalmeida on Dec 16, 2013
Latest reply on Jul 25, 2014 by fellj
I have been working on the following code, i am trying to back up a gdb. I am first trying it with a file geodatabase then i will eventually like it to work with a SQL Server Express database server.

My following code gives me an error but it does copy all the feature classes. I don't understand why this giving me an error but still creates the feature classes.

Any help would be great.
Thanks.

import arcpy, os, string  arcpy.env.overwriteOutput = True DS3 = "C:\GIS\DS.gdb"  if arcpy.Exists(DS3):     arcpy.Delete_management(DS3)  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 = "C:\GIS\PARCEL\Parcel.gdb" #Origin Database     end_db = "C:\GIS\DS.gdb"  #To database     num = 8                                   #number of characters in schema (for example: sde.sde. is 8)     arcpy.Copy_management(start_db,end_db,num)     arcpy.Copy_management(start_db,end_db,num)     arcpy.CopyRows_management(start_db,end_db,num) 


I forgot to post the error.
ExecuteError: Failed to execute. Parameters are not valid. ERROR 000732: Input Rows: Dataset C:\GIS\PARCEL\Parcel.gdb does not exist or is not supported Failed to execute (CopyRows)

Outcomes