Remove the shelves if possible.
Sand small areas of the shelf to expose the wood grain underneath the paint or stain. Pay attention to the areas that would have been worn through years of use from books being moved on and off of the shelves, such as small areas along the edges.
Wipe away excess sawdust with a tack cloth.
Apply a polyurethane sealer to the shelves with a foam paintbrush. This will help protect the exposed grain. Reinstall the shelves, if applicable, after the polyurethane has dried.