I am having problems with lock files while deleting and copying geodatabases for backup purposes.
print "Now backing up your Geodatabase"
distutils.dir_util.remove_tree (r"\\Msukserver\gis\geodatabase BACKUP\EVERYONE\Mining Features (MATTHEW).gdb", 0, 0) # deletes 'everyone' backup copy
distutils.dir_util.copy_tree(r"\\Msukserver\gis\geodatabase BACKUP\MATT\Mining Features (MATTHEW).gdb", r"\\Msukserver\gis\geodatabase BACKUP\EVERYONE\Mining Features (MATTHEW).gdb") # backup the last backup to 'everyone'
print "old backup copied"
distutils.dir_util.remove_tree(r"\\Msukserver\gis\geodatabase BACKUP\MATT\Mining Features (MATTHEW).gdb", 0, 0) # deletes last backup
print "old backup deleted"
distutils.dir_util.copy_tree(r"C:\GIS Home\Mining Features (MATTHEW).gdb", r"\\Msukserver\gis\geodatabase BACKUP\MATT\Mining Features (MATTHEW).gdb") # copy mining features to create new backup
print "::::::::::::::::::::::Backup Complete::::::::::::::::::::::"
raw_input("Push Return key to close...")
I am getting a 'permission denied' error on the '.lock' files. Is there a way of copying/deleting all the file except those with a .lock extension? or a way to continue/force with errors? I am aware that I am currently copying/deleting the entire directory and may need to change my code to copy/delete files only.
arcpy.Copy_management
andarcpy.Delete_management
to do this?.lock
files generally indicate that something is in use. You don't want to delete something in use by an application. You want to stop using it first. (I consider it a weakness of the GDB format that you could go delete other files that belong to it while this one is locked.) Also, don't usedistutils
for file management; that's for creating distribution packages for Python code.