We had a storm last night that knocked out power for about 4 hours. Thankfully—because I have an Uninterruptible Power Supply (UPS)—my internet connection stayed up, as did my Network Attached Storage (NAS) and backup desktop. It gave me enough time to cleanly shut down these devices before the battery ran out.
Some CyberPower UPSs (and other brands too) have USB ports that can tell your computer or NAS that it is on battery and will trigger an automatic shutdown.
Be sure to calculate how much power your equipment will draw so that you get the appropriate size. For my setup of a modem, wifi router, NAS, and desktop computer + display, I got 650VA.