I could be wrong, but isn't the best way to "export" the library to an XML file (File > Library > Export Library) and save this, along with a copy of the iTunes Media Folder to a safe location, do your format and reinstall, then replace the iTunes Media Folder into the same location it used to be, then open iTunes; File > Library > Import Library and everything will be as it was before; metadata, playlists, play counts, ratings, sync data, back up of your iPhone (if you have one) etc
Unless I've got the wrong idea