A locally recoverable code is an error-correcting code such that any erasure in a single coordinate of a codeword can be recovered from a small subset of other coordinates. In this article we develop an algorithm that computes a recovery structure as concise posible for an arbitrary linear code $mathcal{C}$ and a recovery method that realizes it. This algorithm also provides the locality and the dual distance of $mathcal{C}$. Complexity issues are studied as well. Several examples are included.