The Phrase Finder explains that the expression means there is hope even in the worst of circumstances. There are many examples in print from the late 1700s. An English theologian and historian named Thomas Fuller used a version of the term in writings dating 1650. It isn’t known whether Fuller originated the expression or whether “…he may have been recording a piece of folk wisdom.”