Add daemon for indexing, which do need action to database
and multimedia indexing in full automat indexing.
Q: Why is script need ?
A: This Auto update realy update indexes on any actions with files: (on current inotify synoinex can`t do indexis in example variants)
For example if you copy to multimedia dir`s from WinSCP, Telnet, SSH, from mc or from sh scripts like cp * mv* and etc.
HOW:
Step #1:
Add this sh to full verife db index`s on start syno
Create file with text in path: /usr/local/etc/rc.d/S92_mediaindex.sh with chrown do "exec" right`s
- Code: Select all
#!/bin/sh
#
# update all indexes in db on syno
# NO MORE FULL reindex and etc
# by manslife 2010-11-13
case "$1" in
start|"")
#
# input dirs
mkdir -p /tmp/mediaindex
music="/volume1/music"
video="/volume1/video"
photo="/volume1/photo"
# Setup find correctly.
export IFS=$'\n'
#sleep 10
echo `date` "Autoindex start indexing: " >> /var/log/messages
# Loop through our array.
for x in $music $video $photo
do
if [ "$x" == "/volume1/music" ]; then
nn="music"
fi
if [ "$x" == "/volume1/video" ]; then
nn="video"
fi
if [ "$x" == "/volume1/photo" ]; then
nn="photo"
fi
# Find all directories & subdirectories
/opt/bin/find $x -type d -wholename '*' ! -wholename */@eaDir* > /tmp/mediaindex/$nn.dir
/opt/bin/sort /tmp/mediaindex/$nn.dir -o /tmp/mediaindex/$nn.dir
/usr/syno/pgsql/bin/psql mediaserver admin -tA -c "select path from directory where path like '$x%'" > /tmp/mediaindex/$nn-pgsql.dir
/opt/bin/sort /tmp/mediaindex/$nn-pgsql.dir -o /tmp/mediaindex/$nn-pgsql.dir
# Find all Files and exclude win files
/opt/bin/find $x -type f -wholename '*' ! -wholename */@eaDir* ! -name '*.ini' ! -name '*.db' ! -name '*.sys' ! -name '*.zip' ! -name '*.ra?' > /tmp/mediaindex/$nn.file
/opt/bin/sort /tmp/mediaindex/$nn.file -o /tmp/mediaindex/$nn.file
/usr/syno/pgsql/bin/psql mediaserver admin -tA -c "select path from $nn where path like '$x%'" > /tmp/mediaindex/$nn-pgsql.file
/opt/bin/sort /tmp/mediaindex/$nn-pgsql.file -o /tmp/mediaindex/$nn-pgsql.file
# Looking + -
/opt/bin/diff /tmp/mediaindex/$nn.dir /tmp/mediaindex/$nn-pgsql.dir |grep "<"|cut -c3-9000 > /tmp/mediaindex/$nn-dif-ON.dir
/opt/bin/diff /tmp/mediaindex/$nn.file /tmp/mediaindex/$nn-pgsql.file |grep "<"|cut -c3-9000 > /tmp/mediaindex/$nn-dif-ON.file
/opt/bin/diff /tmp/mediaindex/$nn.dir /tmp/mediaindex/$nn-pgsql.dir |grep ">"|cut -c3-9000 > /tmp/mediaindex/$nn-dif-OFF.dir
/opt/bin/diff /tmp/mediaindex/$nn.file /tmp/mediaindex/$nn-pgsql.file |grep ">"|cut -c3-9000 > /tmp/mediaindex/$nn-dif-OFF.file
#######################################
# REMOVE all needed directories & subdirectories
for i in $( /opt/bin/cat /tmp/mediaindex/$nn-dif-OFF.dir )
do
/usr/syno/bin/synoindex -D "$i" > /dev/null
echo `date` "Autoindex REMOVE DIRs: " $i >> /var/log/messages
done
# REMOVE all needed files
for i in $( /opt/bin/cat /tmp/mediaindex/$nn-dif-OFF.file)
do
/usr/syno/bin/synoindex -d "$i" > /dev/null
echo `date` "Autoindex REMOVE FILES: " $i >> /var/log/messages
done
# ADD all needed directories & subdirectories
for i in $( /opt/bin/cat /tmp/mediaindex/$nn-dif-ON.dir )
do
/usr/syno/bin/synoindex -A "$i" > /dev/null
echo `date` "Autoindex ADD DIRs: " $i >> /var/log/messages
done
# ADD all needed files
for i in $( /opt/bin/cat /tmp/mediaindex/$nn-dif-ON.file)
do
/usr/syno/bin/synoindex -a "$i" > /dev/null
echo `date` "Autoindex ADD FILES: " $i >> /var/log/messages
done
done
rm -fr /tmp/mediaindex
echo `date` "Autoindex END indexing: " >> /var/log/messages
;;
restart|reload|force-reload)
echo "Error: argument '$1' not supported" >&2
exit 3
;;
stop)
#
;;
*)
echo "Usage: inotifywait.sh [start|stop]" >&2
exit 3
;;
esac
:
Step #2 : For full automatic daemon need to install "inotify-tools"
Download http://github.com/downloads/rvoicilas/inotify-tools/inotify-tools-3.14.tar.gz
unpak file, copy dir to syno and exeс in console:
path to unpacked dir/configure --prefix=/usr && make && su -c 'make install'
Site for FAQ https://github.com/rvoicilas/inotify-tools/wiki#getting
whait on same actions ...... and all done.
Now Create file with text in path: /usr/local/etc/rc.d/S93_mediaindexdm.sh
- Code: Select all
#!/bin/sh
# Looking FULL changes
case "$1" in
start|"")
#NEW Variant: dirs ends white slashes
/usr/bin/inotifywait -mrcq -e close_write -e moved_to -e moved_from -e move -e create -e delete -e unmount /volume1/music /volume1/photo /volume1/video | while read -r; do
eval "$(echo "$REPLY" | sed -r 's#'\''#'\'\\\\\'\''#; s#^("([^"]*)"|([^"][^,]*)),("([^"]*)"|([^"][^,]*)),("([^"]*)"|([^"][^,]*))$#file_name='\''\2\3\8\9'\''; action='\''\5\6'\''#')"
#if [ "$action" = "CREATE" ] ; then
#echo '0 NOTHING to file CREATE! ONLY on WRITE_CLOSE'
#fi
if [ "$action" = "CREATE,ISDIR" ] ; then
/usr/syno/bin/synoindex -A "$file_name" > /dev/null
echo "At `date`, Autoindex ADD DIRs: " "$file_name" >> /var/log/messages
fi
if [ "$action" = "CLOSE_WRITE,CLOSE" ] ; then
/usr/syno/bin/synoindex -a "$file_name" > /dev/null
echo "At `date`, Autoindex ADD FILES: " "$file_name" >> /var/log/messages
fi
if [ "$action" = "DELETE" ] ; then
/usr/syno/bin/synoindex -d "$file_name" > /dev/null
echo "At `date`, Autoindex REMOVE FILES: " "$file_name" >> /var/log/messages
fi
if [ "$action" = "DELETE,ISDIR" ] ; then
/usr/syno/bin/synoindex -D "$file_name" > /dev/null
echo "At `date`, Autoindex REMOVE DIRs: " "$file_name" >> /var/log/messages
fi
if [ "$action" = "MOVED_FROM,ISDIR" ] ; then
/usr/syno/bin/synoindex -D "$file_name" > /dev/null
echo "At `date`, Autoindex REMOVE DIRs: " "$file_name" >> /var/log/messages
fi
if [ "$action" = "MOVED_FROM" ] ; then
/usr/syno/bin/synoindex -d "$file_name" > /dev/null
echo "At `date`, Autoindex REMOVE FILES: " "$file_name" >> /var/log/messages
fi
if [ "$action" = "MOVED_TO,ISDIR" ] ; then
/usr/syno/bin/synoindex -A "$file_name" > /dev/null
echo "At `date`, Autoindex ADD DIRs: " "$file_name" >> /var/log/messages
fi
if [ "$action" = "MOVED_TO" ] ; then
/usr/syno/bin/synoindex -a "$file_name" > /dev/null
echo "At `date`, Autoindex ADD FILES: " "$file_name" >> /var/log/messages
fi
done &
;;
restart|reload|force-reload)
echo "Error: argument '$1' not supported" >&2
exit 3
;;
stop)
killall inotifywait
;;
*)
echo "Usage: inotifywait.sh [start|stop]" >&2
exit 3
;;
esac
:
All done.
With this daemons HDD DISK`s on Syno go to hibernate without problem.
DS210j FW Version: DSM 3.0-1354



