Created
April 3, 2019 13:58
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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
Still works like a charm! Thank you!