If your books are on your device, then the following works:
- Delete everything in your library (after backing up).
- Connect your device.
- Start Calibre.
- From the device icon choose: "Show books on device".
- Select all books.
- Right-click and choose: "Add to library".