Skip to content

Commit

Permalink
Merge pull request #17 from 007revad/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
007revad authored Jun 9, 2023
2 parents 2cae924 + 1004f24 commit 4f0a686
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 14 deletions.
7 changes: 7 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
v1.0.9
- Fixed bug in DSM 7.2-64570 due to dmidecode now returning memory size in GB. Issue #16
- Added sound when there's an error.

v1.0.8
- Prevent running with "sh scriptname.sh".

v1.0.7
- Changed to show usage if invalid long option used instead of continuing.
- Show the options used.
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@

Enable data deduplication with non-Synology SSDs and unsupported NAS models

It will work for DSM 7.2 beta and DSM 7.1.1 (and possibly DSM 7.1 and maybe even DSM 7.0). As for which models it will work with, I don't know yet. I do know it does work on models not listed by Synology as supported for data deduplication.
Works for DSM from 7.01 and later. As for which models it will work with, I don't know yet. It does work on models not listed by Synology as supported for data deduplication, as long as they have 16GB of memory or more.

**Confirmed working on:**

| Model | DSM version |
| ------------ |--------------------------|
| DS3622xs+ | DSM 7.2-64561 |
| DS3622xs+ | DSM 7.2-64216 Beta |
| RS4021xs+ | DSM 7.1.1-42962 Update 2 |
| DS1821+ | DSM 7.2-64561 |
| DS1821+ | DSM 7.2-64216 Beta |
| DS1821+ | <a href=known_issues.md>DSM 7.2-64213 Beta *</a> |
| DS1821+ | DSM 7.1.1-42962 Update 4 |
Expand Down
29 changes: 29 additions & 0 deletions my-other-scripts.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
## All my Synology Scripts

- **<a href="https://github.com/007revad/Synology_HDD_db">Synology_HDD_db</a>**
- Add your HDD, SSD and NVMe drives to your Synology's compatible drive database.

- **<a href="https://github.com/007revad/Synology_enable_M2_volume">Synology_enable_M2_volume</a>**
- Enable creating volumes with non-Synology M.2 drives.
- Enable Health Info for non-Synology NVMe drives.

- **<a href="https://github.com/007revad/Synology_M2_volume">Synology_M2_volume</a>**
- Easily create an M.2 volume on Synology NAS.

- **<a href="https://github.com/007revad/Synology_enable_Deduplication">Synology_enable_Deduplication</a>**
- Enable deduplication with non-Synology SSDs and unsupported NAS models.

- **<a href="https://github.com/007revad/Synology_RAID-F1_SHR_switch">Synology_RAID-F1_SHR_switch</a>**
- Easily switch between SHR and RAID F1.

- **<a href="https://github.com/007revad/Synology_Config_Backup">Synology_Config_Backup</a>**
- Backup and export your Synology DSM configuration.

- **<a href="https://github.com/007revad/Synology_Plex_Backup">Synology_Plex_Backup</a>**
- A script to backup Plex to a tgz file. For DSM 7 and DSM 6.

- **<a href="https://github.com/007revad/Plex_Server_Sync">Plex_Server_Sync</a>**
- Sync main Plex server database & metadata to backup Plex server

- **<a href="https://github.com/007revad/ScriptNotify">ScriptNotify</a>**
- DSM 7 package to allow your scripts to send DSM notifications
64 changes: 51 additions & 13 deletions syno_enable_dedupe.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,23 @@
# sudo /volume1/scripts/syno_dedupe.sh
#------------------------------------------------------------------------------

scriptver="v1.0.7"
scriptver="v1.0.9"
script=Synology_enable_Deduplication
repo="007revad/Synology_enable_Deduplication"

# Check BASH variable is is non-empty and posix mode is off, else abort with error.
[ "$BASH" ] && ! shopt -qo posix || {
printf \\a
printf >&2 "This is a bash script, don't run it with sh\n"
exit 1
}

#echo -e "bash version: $(bash --version | head -1 | cut -d' ' -f4)\n" # debug

# Shell Colors
#Black='\e[0;30m' # ${Black}
Red='\e[0;31m' # ${Red}
Green='\e[0;32m' # ${Green}
#Green='\e[0;32m' # ${Green}
Yellow='\e[0;33m' # ${Yellow}
#Blue='\e[0;34m' # ${Blue}
#Purple='\e[0;35m' # ${Purple}
Expand All @@ -28,6 +35,9 @@ Cyan='\e[0;36m' # ${Cyan}
Error='\e[41m' # ${Error}
Off='\e[0m' # ${Off}

ding(){
printf \\a
}

usage(){
cat <<EOF
Expand Down Expand Up @@ -55,7 +65,7 @@ EOF


# Save options used
args="$@"
#args="$@"


# Check for flags with getopt
Expand Down Expand Up @@ -96,19 +106,22 @@ if options="$(getopt -o abcdefghijklmnopqrstuvwxyz0123456789 -a \
shift
done
else
echo
usage
fi


# Check script is running as root
if [[ $( whoami ) != "root" ]]; then
ding
echo -e "${Error}ERROR${Off} This script must be run as root or sudo!"
exit 1
fi

# Get DSM major version
dsm=$(get_key_value /etc.defaults/VERSION majorversion)
if [[ $dsm -lt "7" ]]; then
ding
echo "This script only works for DSM 7."
exit 1
fi
Expand Down Expand Up @@ -148,7 +161,7 @@ if [[ $smallfixnumber -gt "0" ]]; then smallfix="-$smallfixnumber"; fi
echo -e "$model DSM $productversion-$buildnumber$smallfix $buildphase\n"

# Show options used
echo "Using options: $args"
#echo "Using options: $args"


#------------------------------------------------------------------------------
Expand Down Expand Up @@ -240,14 +253,14 @@ if ! printf "%s\n%s\n" "$tag" "$scriptver" |

# Delete downloaded .tar.gz file
if ! rm "/tmp/$script-$shorttag.tar.gz"; then
delerr=1
#delerr=1
echo -e "${Error}ERROR ${Off} Failed to delete"\
"downloaded /tmp/$script-$shorttag.tar.gz!"
fi

# Delete extracted tmp files
if ! rm -r "/tmp/$script-$shorttag"; then
delerr=1
#delerr=1
echo -e "${Error}ERROR ${Off} Failed to delete"\
"downloaded /tmp/$script-$shorttag!"
fi
Expand Down Expand Up @@ -295,21 +308,35 @@ IFS=$'\n' read -r -d '' -a array < <(dmidecode -t memory | grep -i 'size')
if [[ ${#array[@]} -gt "0" ]]; then
num="0"
while [[ $num -lt "${#array[@]}" ]]; do
ram=$(printf %s "${array[num]}" | cut -d" " -f2)
#ram=$(printf %s "${array[num]}" | cut -d" " -f2)
ram=$(printf %s "${array[num]}" | awk '{print $2}')
bytes=$(printf %s "${array[num]}" | awk '{print $3}')
if [[ $ramtotal ]]; then
ramtotal=$((ramtotal +ram))
else
ramtotal="$ram"
fi
num=$((num +1))
done
if [[ $ramtotal -lt 16384 ]]; then
echo -e "${Error}ERROR ${Off} Not enough memory installed for deduplication: $ramtotal MB!"
if [[ $bytes == GB ]]; then
if [[ $ramtotal -lt 16 ]]; then
ding
echo -e "${Error}ERROR ${Off} Not enough memory installed for deduplication: $ramtotal GB!"
exit 1
fi
elif [[ $bytes == MB ]]; then
if [[ $ramtotal -lt 16384 ]]; then
ding
echo -e "${Error}ERROR ${Off} Not enough memory installed for deduplication: $ramtotal MB!"
exit 1
fi
else
ding
echo -e "${Error}ERROR ${Off} Unable to determine the $bytes of installed memory!"
exit 1
#else
# echo "NAS has enough memory installed for deduplication: $ramtotal MB"
fi
else
ding
echo -e "${Error}ERROR ${Off} Unable to determine the amount of installed memory!"
exit 1
fi
Expand All @@ -321,6 +348,7 @@ fi
file="/usr/lib/libhwcontrol.so.1"

if [[ ! -f ${file} ]]; then
ding
echo -e "${Error}ERROR ${Off} File not found!"
exit 1
fi
Expand Down Expand Up @@ -350,10 +378,12 @@ if [[ $restore == "yes" ]]; then
rebootmsg
exit
else
ding
echo -e "${Error}ERROR ${Off} Backup failed!"
exit 1
fi
else
ding
echo -e "${Error}ERROR ${Off} Backup file not found!"
exit 1
fi
Expand All @@ -367,6 +397,7 @@ if [[ ! -f ${file}.bak ]]; then
if cp "$file" "$file".bak ; then
echo "Backup successful."
else
ding
echo -e "${Error}ERROR ${Off} Backup failed!"
exit 1
fi
Expand All @@ -382,6 +413,7 @@ else
if cp "$file" "$file".bak ; then
echo "Backup successful."
else
ding
echo -e "${Error}ERROR ${Off} Backup failed!"
exit 1
fi
Expand Down Expand Up @@ -500,6 +532,7 @@ else
if [[ $bytes =~ "752"[0-9] ]]; then
echo -e "\nEditing file."
else
ding
echo -e "\n${Red}hex string not found!${Off}"
exit 1
fi
Expand All @@ -509,6 +542,7 @@ fi
# Replace bytes in file
posrep=$(printf "%x\n" $((0x${poshex}+8)))
if ! printf %s "${posrep}: 9090" | xxd -r - "$file"; then
ding
echo -e "${Error}ERROR ${Off} Failed to edit file!"
exit 1
fi
Expand All @@ -525,6 +559,7 @@ if [[ $bytes == "9090" ]]; then
echo -e "\n${Cyan}You can now enabled data deduplication"\
"pool in Storage Manager.${Off}"
else
ding
echo -e "${Error}ERROR ${Off} Failed to edit file!"
exit 1
fi
Expand All @@ -539,6 +574,7 @@ if [[ ! -f ${synoinfo}.bak ]]; then
if cp "$synoinfo" "$synoinfo.bak"; then
echo -e "\nBacked up $(basename -- "$synoinfo")" >&2
else
ding
echo -e "\n${Error}ERROR 5${Off} Failed to backup $(basename -- "$synoinfo")!"
exit 1
fi
Expand All @@ -552,11 +588,13 @@ setting="$(get_key_value "$synoinfo" ${sbd})"
enabled=""
if [[ ! $setting ]]; then
# Add support_btrfs_dedupe="yes"
echo 'support_btrfs_dedupe="yes"' >> "$synoinfo"
#echo 'support_btrfs_dedupe="yes"' >> "$synoinfo"
synosetkeyvalue "$synoinfo" "$sbd" yes
enabled="yes"
elif [[ $setting == "no" ]]; then
# Change support_btrfs_dedupe="no" to "yes"
sed -i "s/${sbd}=\"no\"/${sbd}=\"yes\"/" "$synoinfo"
#sed -i "s/${sbd}=\"no\"/${sbd}=\"yes\"/" "$synoinfo"
synosetkeyvalue "$synoinfo" "$sbd" yes
enabled="yes"
elif [[ $setting == "yes" ]]; then
echo -e "\nData Deduplication already enabled."
Expand Down

0 comments on commit 4f0a686

Please sign in to comment.