Unless you train them to fire a weapon, they will get shot.
See Argentina...
Or poisoned. See Mexico...
If I’m awakened by gunfire,all hell is gonna break out on the farm.
First, dogs are but one layer of a protective/defensive onion. Singularly they may be taken out by a determined invader, but not before they provide notice and buy time. I would not expect my dog to survive a home invasion by a determined crew, but I would however expect him to provide me enough advanced warning and buy enough time that I would at least have some chance to prepare myself for what was coming.
The same thing would apply in a larger agricultural setting, although one dog would not be sufficient. Mastiffs have been historically used to patrol large estates for poachers, and in combination with adequate fencing, cleared fields of observation, etc. would be pretty effective deterring, detecting and delaying any but the most determined interlopers on a rural agricultural property.