There's almost no risk of this happening on Earth. As others have said, we don't have the technology to be able to destroy the Earth - not to the extent of making it less habitable than, say, Mars. No matter what we do to Earth, it will remain the most habitable planet in our solar system for the foreseeable future.
In the event of any disaster, the best thing to do, by way of preserving the species, is to stay on Earth, or return to it, and restore it to habitability. The most ambitious projects for terraforming Mars would take over a thousand years - and the result would be nowhere near as habitable as Earth, even if they succeed, which is not at all guaranteed. For instance not a breathable atmosphere . Also with its lower gravity and lack of a magnetic field, to protect it from solar flares, Mars would lose its atmosphere over geological timescales, it has already done that with a previous thick atmosphere, it's believed.
This situation is likely to continue for at least 500 million years, that Earth will be the most habitable planet anywhere close.
There may be habitable planets in the galaxy however. Possibly billions of them. So you don't need to look beyond the milky way. But the problem is that we have no easy way to get to them because of the speed of light restrictions.
Also - if habitable - they may have life already. If so that life might well be dangerous to humans, if it is XNA not related to our DNA and surely unlikely to be edible. So - do you destroy all the native life of a planet and replace it with Earth life?
I hope that we don't choose that way ahead myself. Especially if some of them have native intelligent life-forms like ourselves. We would then become the monsters of our own alien invasion movies.
As technology improves, especially with self replicating machines or some such, then it may get far easier to build habitats in space. If so Stanford Torus like habitats may be feasible. Large kilometer scale habitats in free space spinning to create artificial gravity. You can build much more habitat area that way than any other method, with enough materials in just the asteroid belt to create habitats with surface area of a thousand times the land area of the Earth.
We might then not be tied to planetary surfaces at all. And what's more it is a far faster process than terraforming. You could construct such a habitat in decades even with present day technology.
But that I think also brings a huge responsibility - that if we are no longer tied to planetary surfaces, and can build habitats almost anywhere - what is to prevent us from colonizing the entire galaxy. Which you might think "great" but would it really be such a great thing for the galaxy, to fill it with humans who then - some of us at least - might then tear it apart and destroy native life and so on for our own ends? At least if we continue as we are now. Also I think there is a risk that with the huge power that we would have with self replicating machines, and mega-engineering, even reshaping stars and eventually galaxies - it could be great if our descendants can be trusted to use it responsibly. But how can you ensure that all descendants of humans, for hundreds of generations, do use that power responsibly? And if they don't - a problem could evolve in part of the galaxy, say a hundred light years from now, and the first we know about it is a hundred years or more after it starts, by which time you might have billions, trillions of self replicators or whatever the issue is, and it would be surely unstoppable.
So - I think that we don't need to rush towards that future. We are safe here on Earth. It remains a great place for humans. We are indeed doing things that are not so great for the planet - but no matter how much we mess things up here, it is going to remain our fragile and hospitable home in our solar system and the only place we have that is anywhere as suitable for humans as this.
So - I think myself that focus should be on Earth as the future for humanity, throughout, and space as a place for exploration and discovery and maybe settlement like Antarctica for those purposes. And mining and returning materials from space to help the Earth. And probably some large settlements even of thousands of people in space. But I'd be surprised if we get the equivalent of new countries in space, in the near future. Just because Earth is so much more habitable and the obvious place to live in our solar system.