The article talks about how to config a regular ups with qnap nas. Just write a simple script to detect power failure and let nas to safely shutdown.
This article is suitable for synology or any other NAS as well
TABLE OF CONTENT
- Why we need UPS for our NAS?
- What is UPS?
- How to config UPS with NAS following official guide?
- The mechanism behind the door
- Power failure detection
- My recommended UPS from amazon
Why we need UPS for our NAS?
NAS generally has mechanical hard disks to form the main storage. When we write NAS data, the magnetic head will be in a high-speed operation when the hard disk is in working state.
If the power supply is suddenly interrupted, it will result in data loss or even severe cases, damage to hard drives. Therefore, we need to use a UPS to ensure that the NAS has sufficient time to shut down safely after a power failure, thereby ensuring the safety of our data and hard disks.
What is UPS?
UPS stands for Uninterruptible Power Supply which provides emergency power to a load when the input power source or mains power fails.
How to config UPS with NAS following official guide
The officially recommended UPS can be configured easily following the link here. UPS can be configured using three modes: USB connection, SNMP connection or Network UPS Slave. The first mode requires USB port on UPS, and the latter two modes require Network connection on UPS. These are all advanced features of UPS, and we can find them in this link. They are all too expensive, more than 200$.
Is there any way to config a cheaper UPS with QNAP? The answer is YES!
The mechanism behind the door
QNAP nas need to know whether the power is failure or not, this is where USB/SNMP/Network Slave comes in. After properly configuration, UPS will signal QNAP after power failure and let QNAP to safely shutdown its self.
Previously, UPS was used to notify the NAS of whether the power was failure. In fact, we can consider letting the NAS detect whether the power is cut off by itself. NAS is generally connected to the router. If the power is off, the router is also powered off. At this time, if we ping the router, it will fail. As long as we regularly check whether the network of the router is normal, we can achieve the purpose of detecting whether there is a power failure.
Power failure detection
- Touch a new file on your NAS home folder: /share/CACHEDEV1_DATA/homes/user/auto_power.sh, remember to change the router_ip with your real router ip address.
#!/bin/sh
router_ip=192.168.3.1
ping -c 1 $router_ip > /dev/null
ret=$?
if [ $ret -eq 0 ]
then
write_log ' AC Power OK!' 4
else
write_log ' AC Power maybe off, turn off NAS!' 4
/sbin/poweroff
fi
- give execute permission to the file
$ chmod +x auto_power.sh
- make it running by schedule
$ echo '*/5 * * * * /share/CACHEDEV1_DATA/homes/user/auto_power.sh' >> /etc/config/crontab
# Add schedule line which means execute auto_power.sh every other 5 minutes
$ crontab /etc/config/crontab && /etc/init.d/crond.sh restart
# Restart crontab
The following picture show the power off log information I write in the shell script, we can find it in QuLog Center:
My recommended UPS from amazon
Here’s the UPS I recommend to you from Amazon starting at only $48.


0 Comments