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)
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)
Solved! Go to Solution.
# imports import pyodbc #define database db = "STATE" # define the backup paths server_backup_path = 'c:\\temp\\' # Connection object (notice that i dont include the database name) conn = pyodbc.connect('DRIVER={SQL Server};SERVER=<server name>;Trusted_Connection=yes', autocommit=True) def backup_db(conn_obj, db_name, server_backup_path): try: os.remove(client_backup_path + db_name + r'_sql.bak') except: pass cur = conn_obj.cursor() try: cur.execute('BACKUP DATABASE ? TO DISK=?', [db_name, server_backup_path + db_name + r'_sql.bak']) while cur.nextset(): pass cur.close() except: print 'cant backup: ' + db_name backup_db(conn, db, server_backup_path) # close the connection conn.close()
DS3 = "C:\GIS\DS.gdb"
DS3 = r'C:\GIS\DS.gdb'
# imports import pyodbc #define database db = "STATE" # define the backup paths server_backup_path = 'c:\\temp\\' # Connection object (notice that i dont include the database name) conn = pyodbc.connect('DRIVER={SQL Server};SERVER=<server name>;Trusted_Connection=yes', autocommit=True) def backup_db(conn_obj, db_name, server_backup_path): try: os.remove(client_backup_path + db_name + r'_sql.bak') except: pass cur = conn_obj.cursor() try: cur.execute('BACKUP DATABASE ? TO DISK=?', [db_name, server_backup_path + db_name + r'_sql.bak']) while cur.nextset(): pass cur.close() except: print 'cant backup: ' + db_name backup_db(conn, db, server_backup_path) # close the connection conn.close()
def restore_db(conn_obj, db_name, server_backup_path): cur = conn_obj.cursor() cur.execute('RESTORE DATABASE ? FROM DISK=?', [db_name, server_backup_path + db_name + r'_sql.bak']) while cur.nextset(): pass cur.close() restore_db(conn, db, server_backup_path)
restore_db(conn, db, server_backup_path)
backup_db(conn, db, server_backup_path)
def restore_db(conn_obj, db_name, server_backup_path): cur = conn_obj.cursor() cur.execute('RESTORE DATABASE ? FROM DISK=?', [db_name, server_backup_path + db_name + r'_sql.bak']) while cur.nextset(): pass cur.close() restore_db(conn, db, server_backup_path)