An APC Uninterruptible Power Supply , used them from mundane things like faxes up to entire business networks, top quality & never failed me. A small, inexpensive one will allow you to shut down in a controlled manner (or even do it automatically) & a larger one will give you enough time to continue working, possibly until the supply is restored.