Hello Alex, for starters there's no defence against most cosmic things that can get us. The only warning we get from a gamma ray burst is when we detect the same gamma rays that would wreck our atmosphere. However at the moment there's no stars close to us that could give off that much energy, this sort of event is probably something in the region of 1 on average every billion years.
Large asteroids or comet impacts aren't much to worry about either, again very rare, maybe a big one every hundred million years on average. If we did find an asteroid with a couple of years notice we could do something about it. Comets are a bit more tricky because we'd only have maybe a few months notice if one came but we could probably deal with it.
The Earth has been here for 4.5 billion years, its not about to dissapear next week.