mover: bettern handling cases of primary/secondary configured but not present

This commit is contained in:
Tom Mortensen
2024-06-18 11:15:40 -07:00
parent c2a4e68196
commit 20f34bc0b9
+31 -9
View File
@@ -26,6 +26,10 @@ PIDFILE="/var/run/mover.pid"
CFGFILE="/boot/config/share.cfg"
DEBUGGING=""
move() {
/usr/bin/find "$1" -depth 2>/dev/null | /usr/libexec/unraid/move $DEBUGGING
}
start() {
if [ -f $PIDFILE ]; then
if ps h $(cat $PIDFILE) | grep mover ; then
@@ -49,22 +53,38 @@ start() {
for SHARECFG in /boot/config/shares/*.cfg ; do
SHARE=$(basename "$SHARECFG" .cfg)
[[ "$SHARE" == *~* ]] && continue
source <(fromdos < "$SHARECFG")
# maybe move from primary to secondary
if [[ $shareUseCache = yes ]]; then
find "/mnt/$shareCachePool/$SHARE" -depth 2>/dev/null | /usr/libexec/unraid/move $DEBUGGING
if [[ $shareUseCache = yes && -n $shareCachePool && -d "/mnt/$shareCachePool/$SHARE" ]]; then
if [[ -n $shareCachePool2 ]]; then
# secondary is a pool
if [[ -d "/mnt/$shareCachePool2" ]]; then
move "/mnt/$shareCachePool/$SHARE"
fi
else
# secondary is the unRAID array, ensure at least one data disk is present
disks=(/mnt/disk[1-9]/ /mnt/disk[1-9][0-9]/)
if [[ ${#disks[@]} -gt 0 ]]; then
move "/mnt/$shareCachePool/$SHARE"
fi
fi
fi
# maybe move from secondary to primary
if [[ $shareUseCache = prefer ]]; then
if [[ -n $shareCachePool2 ]]; then
# secondary is a pool
find "/mnt/$shareCachePool2/$SHARE" -depth 2>/dev/null | /usr/libexec/unraid/move $DEBUGGING
# secondary is a pool (primary is also a pool)
if [[ -d "/mnt/$shareCachePool2/$SHARE" && -n $shareCachePool && -d "/mnt/$shareCachePool" ]]; then
move "/mnt/$shareCachePool2/$SHARE"
fi
else
# secondary is the unRAID array
for SHAREPATH in /mnt/disk[0-9]*/$SHARE; do
find "$SHAREPATH" -depth 2>/dev/null | /usr/libexec/unraid/move $DEBUGGING
done
if [[ -n $shareCachePool && -d "/mnt/$shareCachePool" ]]; then
for SHAREPATH in /mnt/disk[1-9]/$SHARE/ /mnt/disk[1-9][0-9]/$SHARE/ ; do
move "$SHAREPATH"
done
fi
fi
fi
done
@@ -87,7 +107,9 @@ empty() {
shopt -s nullglob
for SHAREPATH in /mnt/$DISK/* ; do
find "$SHAREPATH" -depth 2>/dev/null | /usr/libexec/unraid/move -e $DEBUGGING
if [[ -d "$SHAREPATH" ]]; then
find "$SHAREPATH" -depth 2>/dev/null | /usr/libexec/unraid/move -e $DEBUGGING
fi
done
# output list of files which could not be moved