When calibre first sends the books, all the metadata should be properly embedded in the book -- however, if you are using plugboards and such to apply metadata rules to the exported books, the embedded metadata might not match the library metadata. For example, I have a plugboard that automatically changes all titles to read "title (series, Book #)" -- which does not match the "title".

So calibre also tracks the books on the device using a cache -- this will be a file on the device called "metadata.calibre"
Match books will tell calibre which device books map to which library books, and allow the metadata cache file to track them. This means calibre can better track which books are on the device already, and for certain devices, to manage metadata/collections automatically.
Getting those books back into calibre should be as simple as copying the books back into calibre, but depending on the ebook format, not all metadata may have been embedded in the book.

I don't know how much metadata LRF for example supports, though EPUB should be fine.
Is the metadata for the books now in calibre consistent? That is to say, the messed up metadata -- is there a pattern to the madness? If so, we can probably fix that

but I don't know any way to fix it if the books themselves don't have good metadata.
For the future, I would definitely advise backing up your library. One easy way would be to put it in Dropbox. (See the relevant information in my signature.)