You need a UPS (uninterruptable power supply). These kick in when your mains supply fails and will supply
enough power for you to save all your work and shut down safely until mains power is restored.
Cost is from under £100 to £000's depending on how many computers you want to support and for how long.
Try Maplins, Dabs, Misco et al or just Google UPS