This exact problem is systematised in software and other infrastructure regions. Even hospitals for example have backup generators.
The problem is that power companies making resilient grids eats into their profits and so they won’t do it unless they’re compelled to
Do a search on aliexpress, you’ll get 10 for the $14 linked above