Backing up databases

3659
13
Jump to solution
12-16-2013 08:34 AM
TonyAlmeida
Occasional Contributor II
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)
Tags (2)
0 Kudos
13 Replies
TonyAlmeida
Occasional Contributor II

A little old thread but i am trying to figure out how to save over my network.

I currently have tried the using the UNC path but no luck.

like the following but no luck.

server_backup_path ='\\\\ccdept\\dsd\\GIS\\'

0 Kudos
ChrisMathers
Occasional Contributor III

Some functions trip on UNC paths on occasion so it may be easier to save it locally to the database and move it with shutil.copy to the network location. Also, instead of trying to escape the slashes just flip your slashes forward, or wrap the whole thing in triple quotes and only give it what slashes you really want: """\\ccdept\dsd\GIS"""

TonyAlmeida
Occasional Contributor II

Shutil.copy worked out best.

Thanks!

0 Kudos
JohnFell
Occasional Contributor III

Tony,

You may also look into a maintenance plan that is available with SQL Server. You can add a backup database task to the plan and just schedule it. See this microsoft developer network document.

0 Kudos