Getting to the moon and Mars won't save the human race, Earth is where life can be sustained. Humans cannot reproduce in space, on the moon or on Mars because gravity has a strong and vital role in gestation in mammals. Beyond that, these other locations are quite inhospitable (radiation, temperature, pressure, etc), more inhospitable than pretty much anywhere on Earth.
If we can't make it work here and end up destroying the ecology of Earth, upon which we depend, there's no reason to think we'll survive on the moon or Mars.