I would like to back up a SQL express database but with the date of when the backup was created added to the end (Owls06222017.bak). Is this possible if so how?
I tried the following but did not work.
db, backup_path + db + time.strftime("%m%d%y")+ r'.bak'
import pyodbc, datetime, fnmatch
conn = pyodbc.connect('DRIVER={SQL Server};SERVER=GIS7\SQLEXPRESS;Trusted_Connection=yes', autocommit=True)
backup_path = 'C:\\temp\\'
db = "Owls"
def backup_db(conn, db, backup_path):
cur = conn.cursor()
try:
cur.execute('BACKUP DATABASE ? TO DISK=?', [db, backup_path + db + time.strftime("%m%d%y")+ r'.bak'])
while cur.nextset():
pass
cur.close()
except:
print 'Unable to backup: ' + db
backup_db(conn, db, backup_path)
conn.close()
Solved! Go to Solution.
For debugging purposes, how about you remove the try:except block so you can see the actual error message. Or, have your except clause print the error message and stack trace as well.
How did it not work, exactly? What were the errors or results you didn't expect?
it returned
cant backup: Owls
Done
For debugging purposes, how about you remove the try:except block so you can see the actual error message. Or, have your except clause print the error message and stack trace as well.
After adding the trace back it came back as not having arcpy module. Once i added the module it ran fine.
Would a better alternative be arcpy.ExportXMLWorkspaceDocument_management or be the same?
I don't administer geodatabases enough to have an informed opinion on your follow-up question. That said, I think the caution note in Export XML Workspace Document—Help | ArcGIS Desktop strongly implies the answer isn't to use that tool for managing data itself:
The output XML workspace document can be very large when you copy both the data and the schema. Generally, this alternative is not recommended for copying geodatabase data. Alternatives for making a geodatabase copy include the use of the Copy tool or the Clip tool to extract subsets of the data. In addition, tools in the Package toolset provides tools to consolidate, package, and share layers, map documents, address locators, and geoprocessing results.
Since this question has already been answered, maybe ask another question in the https://community.esri.com/groups/geodatabase?sr=search&searchId=af6bec87-2501-47bf-91d5-63c244bc724... or https://community.esri.com/community/gis/managing-data?sr=search&searchId=c73670d4-2ccf-4af2-9825-d2... places.