Browse Source

Update syno_hdd_db.sh

v3.5.99-RC
- Changed to support "--restore --ssd=restore" to restore write_mostly when restoring all other changes. Issue #340
pull/345/head v3.5.99-RC
Dave Russell 1 year ago
committed by GitHub
parent
commit
3fbd1bb84c
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 133
      syno_hdd_db.sh

133
syno_hdd_db.sh

@ -29,7 +29,7 @@
# /var/packages/StorageManager/target/ui/storage_panel.js # /var/packages/StorageManager/target/ui/storage_panel.js
scriptver="v3.5.98" scriptver="v3.5.99"
script=Synology_HDD_db script=Synology_HDD_db
repo="007revad/Synology_HDD_db" repo="007revad/Synology_HDD_db"
scriptname=syno_hdd_db scriptname=syno_hdd_db
@ -113,13 +113,6 @@ if options="$(getopt -o Sabcdefghijklmnopqrstuvwxyz0123456789 -l \
eval set -- "$options" eval set -- "$options"
while true; do while true; do
case "$1" in case "$1" in
--restore) # Restore changes from backups
restore=yes
break
;;
-s|--showedits) # Show edits done to host db file
showedits=yes
;;
-S) # Enable writemostly for md0 and md1 -S) # Enable writemostly for md0 and md1
ssd=yes ssd=yes
;; ;;
@ -134,6 +127,13 @@ if options="$(getopt -o Sabcdefghijklmnopqrstuvwxyz0123456789 -l \
fi fi
shift shift
;; ;;
--restore) # Restore changes from backups
restore=yes
break
;;
-s|--showedits) # Show edits done to host db file
showedits=yes
;;
-n|--nodbupdate|--noupdate) # Disable disk compatibility db updates -n|--nodbupdate|--noupdate) # Disable disk compatibility db updates
nodbupdate=yes nodbupdate=yes
;; ;;
@ -566,6 +566,44 @@ vidfile="/usr/syno/etc.defaults/pci_vendor_ids.conf"
vidfile2="/usr/syno/etc/pci_vendor_ids.conf" vidfile2="/usr/syno/etc/pci_vendor_ids.conf"
set_writemostly(){
# $1 is writemostly or -writemostly
# $2 is sata1 or sas1 or sda etc
local model
# Show drive model
model="$(cat /sys/block/"${2}"/device/model | xargs)"
echo -e "${Yellow}$model${Off}"
if [[ ${1::2} == "sd" ]]; then
# sda etc
# md0 DSM system partition
echo "$1" > /sys/block/md0/md/dev-"${2}"1/state
# Show setting
echo -n " $2 DSM partition: "
cat /sys/block/md0/md/dev-"${2}"1/state
# md1 DSM swap partition
echo "$1" > /sys/block/md1/md/dev-"${2}"2/state
# Show setting
echo -n " $2 Swap partition: "
cat /sys/block/md1/md/dev-"${2}"2/state
else
# sata1 or sas1 etc
# md0 DSM system partition
echo "$1" > /sys/block/md0/md/dev-"${2}"p1/state
# Show setting
echo -n " $2 DSM partition: "
cat /sys/block/md0/md/dev-"${2}"p1/state
# md1 DSM swap partition
echo "$1" > /sys/block/md1/md/dev-"${2}"p2/state
# Show setting
echo -n " $2 Swap partition: "
cat /sys/block/md1/md/dev-"${2}"p2/state
fi
}
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
# Restore changes from backups # Restore changes from backups
@ -696,6 +734,45 @@ if [[ $restore == "yes" ]]; then
if [[ -z $restoreerr ]]; then if [[ -z $restoreerr ]]; then
echo -e "\nRestore successful." echo -e "\nRestore successful."
fi fi
# Restore writemostly if set
if [[ $ssd_restore == "yes" ]]; then
# Get array of internal drives
readarray -t internal_drives < <(synodisk --enum -t internal | grep 'Disk path' | cut -d"/" -f3)
# Restore all internal drives to just in_sync
echo -e "\nRestoring internal drive's state"
for idrive in "${internal_drives[@]}"; do
#if ! grep -q "write_mostly" ; then
set_writemostly -writemostly "$idrive"
#fi
md0="/sys/block/md0/md/dev-"
md1="/sys/block/md1/md/dev-"
if [[ ${idrive::2} == "sd" ]]; then
# sda etc
# md0 DSM system partition
if ! grep -q "write_mostly" "${md0}$idrive"1/state; then
set_writemostly -writemostly "$idrive"
fi
# md1 DSM swap partition
if ! grep -q "write_mostly" "${md1}$idrive"2/state; then
set_writemostly -writemostly "$idrive"
fi
else
# sata1 or sas1 etc
# md0 DSM system partition
if ! grep -q "write_mostly" "${md0}$idrive"p1/state; then
set_writemostly -writemostly "$idrive"
fi
# md1 DSM swap partition
if ! grep -q "write_mostly" "${md1}$idrive"p2/state; then
set_writemostly -writemostly "$idrive"
fi
fi
done
fi
else else
echo "Nothing to restore." echo "Nothing to restore."
fi fi
@ -1727,43 +1804,6 @@ done
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
# Set or restore writemostly # Set or restore writemostly
set_writemostly(){
# $1 is writemostly or in_sync
# $2 is sata1 or sas1 or sda etc
local model
# Show drive model
model="$(cat /sys/block/"${2}"/device/model | xargs)"
echo -e "${Yellow}$model${Off}"
if [[ ${1::2} == "sd" ]]; then
# sda etc
# md0 DSM system partition
echo "$1" > /sys/block/md0/md/dev-"${2}"1/state
# Show setting
echo -n " $2 DSM partition: "
cat /sys/block/md0/md/dev-"${2}"1/state
# md1 DSM swap partition
echo "$1" > /sys/block/md1/md/dev-"${2}"2/state
# Show setting
echo -n " $2 Swap partition: "
cat /sys/block/md1/md/dev-"${2}"2/state
else
# sata1 or sas1 etc
# md0 DSM system partition
echo "$1" > /sys/block/md0/md/dev-"${2}"p1/state
# Show setting
echo -n " $2 DSM partition: "
cat /sys/block/md0/md/dev-"${2}"p1/state
# md1 DSM swap partition
echo "$1" > /sys/block/md1/md/dev-"${2}"p2/state
# Show setting
echo -n " $2 Swap partition: "
cat /sys/block/md1/md/dev-"${2}"p2/state
fi
}
if [[ $ssd == "yes" ]]; then if [[ $ssd == "yes" ]]; then
# Get array of internal drives # Get array of internal drives
readarray -t internal_drives < <(synodisk --enum -t internal | grep 'Disk path' | cut -d"/" -f3) readarray -t internal_drives < <(synodisk --enum -t internal | grep 'Disk path' | cut -d"/" -f3)
@ -2056,7 +2096,8 @@ fi
dtu=drive_db_test_url dtu=drive_db_test_url
url="$(/usr/syno/bin/synogetkeyvalue $synoinfo ${dtu})" url="$(/usr/syno/bin/synogetkeyvalue $synoinfo ${dtu})"
disabled="" disabled=""
if [[ $nodbupdate == "yes" ]]; then #if [[ $nodbupdate == "yes" ]]; then
if [[ $updatedb != "yes" ]]; then
if [[ ! $url ]]; then if [[ ! $url ]]; then
# Add drive_db_test_url="127.0.0.1" # Add drive_db_test_url="127.0.0.1"
#echo 'drive_db_test_url="127.0.0.1"' >> "$synoinfo" #echo 'drive_db_test_url="127.0.0.1"' >> "$synoinfo"

Loading…
Cancel
Save