Skip to content

Instantly share code, notes, and snippets.

@roskakori
Created April 3, 2019 13:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save roskakori/e2d8f1a04a90a880a303b295141c8f87 to your computer and use it in GitHub Desktop.
Save roskakori/e2d8f1a04a90a880a303b295141c8f87 to your computer and use it in GitHub Desktop.
After moving or removing media files on a Synology NAS the previews etc do not update correctly and will remain visible despite the files being gone. This script collected from the Synology forums removes the orphan data from the media database. Credits go to various users of the Synology forums.
#!/bin/sh
# Usage: ./remove_orphans.sh [-f]
#
# Run this after moving / removing media files on a Synology NAS.
[ "$1" = "-f" ] && REMOVE=1
IFS='
'
DBADMIN=postgres
for db in directory; do
for testfile in `/usr/bin/psql mediaserver $DBADMIN -tA -c "select path from $db;"`; do
if [ ! -d "$testfile" ]; then
echo "MISSING FOLDER: $testfile"
[ -n "$REMOVE" ] && synoindex -D "$testfile"
fi
done
done
for db in music video photo; do
for testfile in `/usr/bin/psql mediaserver $DBADMIN -tA -c "select path from $db;"`; do
if [ ! -f "$testfile" ]; then
echo "MISSING FILE: $testfile"
[ -n "$REMOVE" ] && synoindex -d "$testfile"
fi
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment