From a65077df147dab20da3b6950956941bab11570bb Mon Sep 17 00:00:00 2001 From: Dave Russell <39733752+007revad@users.noreply.github.com> Date: Fri, 16 Aug 2024 08:59:45 +1000 Subject: [PATCH 1/8] Update CHANGES.txt --- CHANGES.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGES.txt b/CHANGES.txt index f938db2..fa06a23 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,3 +1,6 @@ +v3.5.99-RC +- Changed to support "--restore --ssd=restore" to restore write_mostly when restoring all other changes. Issue #340 + v3.5.98 - Changed to automatically download and install dtc if all of the following 4 conditions are met: 1. dtc is not already installed. From 3fbd1bb84c1fdfc3f2c321246ccca7a42d5def45 Mon Sep 17 00:00:00 2001 From: Dave Russell <39733752+007revad@users.noreply.github.com> Date: Fri, 16 Aug 2024 08:59:54 +1000 Subject: [PATCH 2/8] 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 --- syno_hdd_db.sh | 133 ++++++++++++++++++++++++++++++++----------------- 1 file changed, 87 insertions(+), 46 deletions(-) diff --git a/syno_hdd_db.sh b/syno_hdd_db.sh index 778f138..d6f5646 100644 --- a/syno_hdd_db.sh +++ b/syno_hdd_db.sh @@ -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 @@ -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 ;; @@ -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 ;; @@ -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 @@ -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 @@ -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) @@ -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" From 19f6d36ff2cc254aae4439c1fde2a0798ae53c4d Mon Sep 17 00:00:00 2001 From: Dave Russell <39733752+007revad@users.noreply.github.com> Date: Mon, 19 Aug 2024 14:02:24 +1000 Subject: [PATCH 3/8] Update CHANGES.txt --- CHANGES.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGES.txt b/CHANGES.txt index fa06a23..acad096 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,3 +1,7 @@ +v3.5.100-RC +- Changed to support "--restore --ssd=restore" to restore write_mostly when restoring all other changes. Issue #340 + - When using --restore you can also use --ssd=restore, -e or --email + v3.5.99-RC - Changed to support "--restore --ssd=restore" to restore write_mostly when restoring all other changes. Issue #340 From 25981e01f65c269b6795fce1157b89eb1cfce659 Mon Sep 17 00:00:00 2001 From: Dave Russell <39733752+007revad@users.noreply.github.com> Date: Mon, 19 Aug 2024 14:02:34 +1000 Subject: [PATCH 4/8] Update syno_hdd_db.sh v3.5.100-RC - Changed to support "--restore --ssd=restore" to restore write_mostly when restoring all other changes. Issue #340 - When using --restore you can also use --ssd=restore, -e or --email --- syno_hdd_db.sh | 56 ++++++++++++++++++++++---------------------------- 1 file changed, 25 insertions(+), 31 deletions(-) diff --git a/syno_hdd_db.sh b/syno_hdd_db.sh index d6f5646..a1cda47 100644 --- a/syno_hdd_db.sh +++ b/syno_hdd_db.sh @@ -29,7 +29,7 @@ # /var/packages/StorageManager/target/ui/storage_panel.js -scriptver="v3.5.99" +scriptver="v3.5.100" script=Synology_HDD_db repo="007revad/Synology_HDD_db" scriptname=syno_hdd_db @@ -81,6 +81,8 @@ Options: --ssd=sata1 or --ssd=sata1,sata2 or --ssd=sda etc --ssd=restore --restore Undo all changes made by the script (except -S --ssd) + To restore all changes including write_mostly use + --restore --ssd=restore --autoupdate=AGE Auto update script (useful when script is scheduled) AGE is how many days old a release must be before auto-updating. AGE must be a number: 0 or greater @@ -105,7 +107,6 @@ EOF # Save options used args=("$@") - # Check for flags with getopt if options="$(getopt -o Sabcdefghijklmnopqrstuvwxyz0123456789 -l \ ssd:,restore,showedits,noupdate,nodbupdate,m2,force,incompatible,ram,pcie,wdda,email,autoupdate:,help,version,debug \ @@ -113,6 +114,22 @@ if options="$(getopt -o Sabcdefghijklmnopqrstuvwxyz0123456789 -l \ eval set -- "$options" while true; do case "$1" in + -d|--debug) # Show and log debug info + debug=yes + ;; + -e|--email) # Disable colour text in task scheduler emails + color=no + ;; + --restore) # Restore changes from backups + restore=yes + if $(echo "${args[@]}" | grep -q -- '--ssd=restore'); then + ssd_restore=yes + fi + break + ;; + -s|--showedits) # Show edits done to host db file + showedits=yes + ;; -S) # Enable writemostly for md0 and md1 ssd=yes ;; @@ -127,13 +144,6 @@ 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 ;; @@ -155,9 +165,6 @@ if options="$(getopt -o Sabcdefghijklmnopqrstuvwxyz0123456789 -l \ -p|--pcie) # Enable creating volumes on M2 in unknown PCIe adaptor forcepci=yes ;; - -e|--email) # Disable colour text in task scheduler emails - color=no - ;; --autoupdate) # Auto update script autoupdate=yes if [[ $2 =~ ^[0-9]+$ ]]; then @@ -173,9 +180,6 @@ if options="$(getopt -o Sabcdefghijklmnopqrstuvwxyz0123456789 -l \ -v|--version) # Show script version scriptversion ;; - -d|--debug) # Show and log debug info - debug=yes - ;; --) shift break @@ -743,30 +747,20 @@ if [[ $restore == "yes" ]]; then # 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 + # Check DSM system and swap partitions + if grep -q "write_mostly" "${md0}$idrive"1/state ||\ + 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 + # Check DSM system and swap partitions + if grep -q "write_mostly" "${md0}$idrive"p1/state ||\ + grep -q "write_mostly" "${md1}$idrive"p2/state; then set_writemostly -writemostly "$idrive" fi fi From e40a0372488b1787bd1a7606807d4e95e0386741 Mon Sep 17 00:00:00 2001 From: Dave Russell <39733752+007revad@users.noreply.github.com> Date: Thu, 22 Aug 2024 15:27:27 +1000 Subject: [PATCH 5/8] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 35c8a66..98d7e56 100644 --- a/README.md +++ b/README.md @@ -170,6 +170,7 @@ ### Donators | | | | | |--------------------|--------------------|----------------------|----------------------| +| | | | Mark Rohde | | vaadmin | Sebastiaan Mulder | Nico Stark | Oleksandr Antonishak | | Marcel Siemienowski | Dave Smart | dweagle79 | lingyinsam | | Vojtech Filkorn | Craig Sadler | Po-Chia Chen | Jean-François Fruhauf | From acf8c0b9418ae6da380a8807ab2b52be746f5c83 Mon Sep 17 00:00:00 2001 From: Dave Russell <39733752+007revad@users.noreply.github.com> Date: Thu, 22 Aug 2024 16:35:54 +1000 Subject: [PATCH 6/8] Update syno_hdd_db.sh --- syno_hdd_db.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/syno_hdd_db.sh b/syno_hdd_db.sh index a1cda47..6b3b008 100644 --- a/syno_hdd_db.sh +++ b/syno_hdd_db.sh @@ -125,7 +125,7 @@ if options="$(getopt -o Sabcdefghijklmnopqrstuvwxyz0123456789 -l \ if $(echo "${args[@]}" | grep -q -- '--ssd=restore'); then ssd_restore=yes fi - break + #break ;; -s|--showedits) # Show edits done to host db file showedits=yes From 8eae46b74f9ac985ffdd51597d9729f4ad293f51 Mon Sep 17 00:00:00 2001 From: Dave Russell <39733752+007revad@users.noreply.github.com> Date: Thu, 22 Aug 2024 16:36:32 +1000 Subject: [PATCH 7/8] Update CHANGES.txt --- CHANGES.txt | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index acad096..55e06ca 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,10 +1,7 @@ -v3.5.100-RC +v3.5.100 - Changed to support "--restore --ssd=restore" to restore write_mostly when restoring all other changes. Issue #340 - When using --restore you can also use --ssd=restore, -e or --email -v3.5.99-RC -- Changed to support "--restore --ssd=restore" to restore write_mostly when restoring all other changes. Issue #340 - v3.5.98 - Changed to automatically download and install dtc if all of the following 4 conditions are met: 1. dtc is not already installed. From 8f4d03b2a381dea24fe8e53dce3fb1be935fcf16 Mon Sep 17 00:00:00 2001 From: Dave Russell <39733752+007revad@users.noreply.github.com> Date: Thu, 22 Aug 2024 16:48:46 +1000 Subject: [PATCH 8/8] Update syno_hdd_db.sh --- syno_hdd_db.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/syno_hdd_db.sh b/syno_hdd_db.sh index 6b3b008..e63bf3c 100644 --- a/syno_hdd_db.sh +++ b/syno_hdd_db.sh @@ -2090,8 +2090,7 @@ fi dtu=drive_db_test_url url="$(/usr/syno/bin/synogetkeyvalue $synoinfo ${dtu})" disabled="" -#if [[ $nodbupdate == "yes" ]]; then -if [[ $updatedb != "yes" ]]; then +if [[ $nodbupdate == "yes" ]]; then if [[ ! $url ]]; then # Add drive_db_test_url="127.0.0.1" #echo 'drive_db_test_url="127.0.0.1"' >> "$synoinfo"