Skip to content

Commit

Permalink
Update syno_hdd_db.sh
Browse files Browse the repository at this point in the history
v3.5.99-RC
- Changed to support "--restore --ssd=restore" to restore write_mostly when restoring all other changes. Issue #340
  • Loading branch information
007revad authored Aug 15, 2024
1 parent a65077d commit 3fbd1bb
Showing 1 changed file with 87 additions and 46 deletions.
133 changes: 87 additions & 46 deletions syno_hdd_db.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
# /var/packages/StorageManager/target/ui/storage_panel.js


scriptver="v3.5.98"
scriptver="v3.5.99"
script=Synology_HDD_db
repo="007revad/Synology_HDD_db"
scriptname=syno_hdd_db
Expand Down Expand Up @@ -113,13 +113,6 @@ if options="$(getopt -o Sabcdefghijklmnopqrstuvwxyz0123456789 -l \
eval set -- "$options"
while true; do
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
ssd=yes
;;
Expand All @@ -134,6 +127,13 @@ if options="$(getopt -o Sabcdefghijklmnopqrstuvwxyz0123456789 -l \
fi
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
nodbupdate=yes
;;
Expand Down Expand Up @@ -566,6 +566,44 @@ vidfile="/usr/syno/etc.defaults/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

Expand Down Expand Up @@ -696,6 +734,45 @@ if [[ $restore == "yes" ]]; then
if [[ -z $restoreerr ]]; then
echo -e "\nRestore successful."
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
echo "Nothing to restore."
fi
Expand Down Expand Up @@ -1727,43 +1804,6 @@ done
#------------------------------------------------------------------------------
# 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
# Get array of internal drives
readarray -t internal_drives < <(synodisk --enum -t internal | grep 'Disk path' | cut -d"/" -f3)
Expand Down Expand Up @@ -2056,7 +2096,8 @@ fi
dtu=drive_db_test_url
url="$(/usr/syno/bin/synogetkeyvalue $synoinfo ${dtu})"
disabled=""
if [[ $nodbupdate == "yes" ]]; then
#if [[ $nodbupdate == "yes" ]]; then
if [[ $updatedb != "yes" ]]; then
if [[ ! $url ]]; then
# Add drive_db_test_url="127.0.0.1"
#echo 'drive_db_test_url="127.0.0.1"' >> "$synoinfo"
Expand Down

0 comments on commit 3fbd1bb

Please sign in to comment.