Database Reference
In-Depth Information
There is one step missing, the backup. In order to back up this geodatabase on a daily
basis, we could rename the existing Web_Bestaurants geodatabase to
Web_Bestaurants_TodayDate , and then run the script normally. Since the
Web_Bestaurants geodatabase is no longer available (it has been renamed), the script
will create a fresh geodatabase. We will need to add additional Python libraries, os and
datetime . A Python library, such as arcpy , is a collection of useful methods that can
be imported and used throughout the script. For instance, the os.rename method is used
to rename a folder name, and datetime.date.today gives you the year, month, and
day of the current date. Add the following lines to your code to do so:
1. Import the os and datetime libraries right after the arcpy library as follows:
import arcpy
import os
import datetime
sgdb_path = "c:/gdb/web"
sgdb_name = "Web_Bestaurants.gdb"
arcpy.CreateFileGDB_management(sgdb_path, sgdb_name)
sfc_source = "c:/gdb/Bestaurants_new.gdb/
Food_and_Drinks"
sfc_dest = sgdb_path + "/" + sgdb_name +
"/Restaurants"
#Copy features
arcpy.CopyFeatures_management (sfc_source, sfc_dest)
sfield_rating = "RATING"
sfield_desc = "DESCRIPTION"
arcpy.DeleteField_management(sfc_dest, sfield_rating)
arcpy.DeleteField_management(sfc_dest, sfield_desc)
input ("Web Bestaurants geodatabase created
successfully, press any key to continue.")
2. Write the following code snippet in your script after the sgdb_name line and be-
fore creating the file geodatabase:
import arcpy
import os
import datetime
sgdb_path = "c:/gdb/web"
sgdb_name = "Web_Bestaurants.gdb"
Search WWH ::




Custom Search