
perhaps a Library Closed plugin could copy the metadata.db file of the library just closed to a metadata.db.backup fiie within the library folder, doing a replace of it already exists.
I say 'perhaps' because I don't know if LC plugins can have an event that kicks in when the metadata.db file is actually closed. The existing LC plugins operate on the content of the database (Virtual Library and Custom Column definitions) before its closed.
Recovery would be manual: Close calibre and copy metadata.db.backup to metadata.db, then run the calibredb check_library command and fix errors, OR start calibre, run Library Maintenance->Check library and fix errors.
BR