Mars as a backup planet is a nice thought, but IMO we are not nearly ready to pursue it at present. Meanwhile, robotics and AI are improving fast.
"Mars as a backup is not even logical. Let's say there is a disaster scenario on Earth like this: Global warming. is left unchecked and it gets to the point where agriculture is impossible in many places of the world. War breaks out as starving people fight over the remaining water and livable land, this leads to a global six-way nuclear war. Industry and cities are gone and much of the world is radioactive. People are using self-made stone tools and eating bugs and roots. Few people live to be 30 years old. 95% of the human population was killed in the war or the after effects. Pandemics like a resurgence of the Black Death run unchecked. Dead bodies are common with no means to dispose of them. Then as luck would have it an asteroid of the size that killed dinosaurs impacts the Earth and makes things even worse.
The above scenario is not good. But even if it all came to be, the Earth would still be like paradise compared to Mars. On Earth at least there is air pressure and liquid water and a magnetic field and to survive all you need is stone-age technology. On Mars without advanced 22nd-century technology, you'd be dead in seconds.
Or to say it differently, if you could build an underground city and underground farms on Mars all powered by Fusion energy and maintain artificial closed ecosystems on Mars. Then with far less effort, you could do all of those things on Earth. In fact you would have to. Who would build such things on Mars without first testing the technology on Earth?
I think Mars and the Moon will be like Antarctica, places where some scientists go to and live for some time then come home and a place where rich tourists can go. We don't build cities in Antarctica because no one really wants to live there forever and it's too expensive.
Again, it is hard to think of a way that Earth could ever be a worse place to live than Mars and if it does happen then whatever technology you would use to live on Mars could be used on Earth.