Last active
April 24, 2023 11:21
-
-
Save KyonLi/d1e8b6243ad0c903fe0990bb63f37697 to your computer and use it in GitHub Desktop.
Revisions
-
KyonLi revised this gist
Apr 24, 2023 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -6,7 +6,7 @@ /share/Public/scripts/disk_standby.sh start ``` 2. 在共享文件夹`Public`中创建`scripts`目录,向其中放入[disk_standby.sh](#file-disk_standby-sh),添加执行权限`chmod +x disk_standby.sh` 3. 添加定时任务 ```shell echo "0 4 * * * /share/Public/scripts/disk_standby.sh readd" >> /etc/config/crontab -
KyonLi revised this gist
Apr 24, 2023 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -6,7 +6,7 @@ /share/Public/scripts/disk_standby.sh start ``` 2. 在共享文件夹`Public`中创建`scripts`目录,向其中放入[disk_standby.sh](#disk_standby.sh),添加执行权限`chmod +x disk_standby.sh` 3. 添加定时任务 ```shell echo "0 4 * * * /share/Public/scripts/disk_standby.sh readd" >> /etc/config/crontab -
KyonLi created this gist
Apr 24, 2023 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,15 @@ # QNAP硬盘休眠 适用于系统盘为SSD数据盘有HDD的情况,实现开机自动解除HDD系统占用,每天4:00~4:30自动同步数据避免系统出错 1. 启用开机自启,参考[wiki](https://wiki.qnap.com/wiki/Running_Your_Own_Application_at_Startup),编辑autorun.sh加入以下内容 ```shell #!/bin/sh /share/Public/scripts/disk_standby.sh start ``` 2. 在共享文件夹`Public`中创建`scripts`目录,向其中放入[disk_standby.sh](disk_standby.sh),添加执行权限`chmod +x disk_standby.sh` 3. 添加定时任务 ```shell echo "0 4 * * * /share/Public/scripts/disk_standby.sh readd" >> /etc/config/crontab echo "30 4 * * * /share/Public/scripts/disk_standby.sh remove" >> /etc/config/crontab crontab /etc/config/crontab && /etc/init.d/crond.sh restart ``` This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,60 @@ #!/bin/bash MD_DEVICES="md9 md13" SYS_DEV=$(df $(getcfg SHARE_DEF defVolMP -f /etc/config/def_share.info) | awk '/^\/dev/ {print $1}') turn_off_swap(){ echo "Turning off swap on HDD..." for partition in $(cat /proc/swaps | grep partition | awk '{print $1}'); do swapoff $partition done } remove_from_raid(){ for md in $MD_DEVICES; do echo "Disconnecting HDD from /dev/${md}..." save= for partition in $(mdadm -D /dev/${md} | grep 'active sync' | awk 'NF{ print $NF }'); do disk=${partition//[[:digit:]]/} disk=${disk#"/dev/"} if [ $(cat /sys/block/${disk}/queue/rotational) = 1 ]; then mdadm /dev/${md} --fail ${partition} save=${save}${partition}$'\n' fi done [ -n "$save" ] && echo -n "$save" > /tmp/disk_standby_${md} done } readd_to_raid(){ for md in $MD_DEVICES; do [ ! -f "/tmp/disk_standby_${md}" ] && break echo "Reconnecting HDD to /dev/${md}..." for partition in $(cat /tmp/disk_standby_${md}); do mdadm /dev/${md} --re-add ${partition} done rm "/tmp/disk_standby_${md}" done } case "$1" in start) turn_off_swap remove_from_raid ;; remove) remove_from_raid ;; readd) readd_to_raid ;; *) echo "Usage:" echo " $0 [command]" echo " command:" echo " start - turn off swap and remove hdd from raid1." echo " remove - remove hdd from raid1." echo " readd - readd hdd to raid1." exit 0 ;; esac