Please help optimize my scripts [wall of text]

I’ve been lurking and helping where I can, but I’d like to know if anyone has any further suggestions given my setup, as I’m still only at about 60-70% successful in starting media in Plex.

I’ve got a GB fiber connection. You won’t believe me, but I actually pay $40 less for this and satellite tv than I did for comcast cable and slower internet. I have an additional 64GB ssd that I’m not currently using. I have 3 old i3 laptops hooked up to my TVs, but they will not run at 4k. I haven’t tried with OpenPlexHomeTheater yet. I have 1 i5 that MAY be able. My server is old. It’s an i7 920 with a slight overclock. It won’t do a 4k transcode, so I WAS pre-optimizing the media, but now without the unionfs running, that fails (more on that later). I also have a workstation with an i7-2600K @ 3.40GHz that MAY be able to do a 4k transcode, but I do work on for my employment on that. I have a 4k LG, a 4k Visio, and a 1080p Samsung TV. Each TV has Plex. The LG and Samsung don’t have the processing power to decode anything h.264 above 12MBbps, so I have to have my server transcode down for them.

As for buying new hardware: I’m currently eating Cup-O-Noodles. We were doing fine before (hence our great last-year’s setup) our mortgage company screwed up our projected taxes and increased our monthly bill by over $600. Not to mention that the health insurance costs doubled last year. So, needless to say, no new hardware for at least a year until I get either a raise or the homestead exemption or both. This is also why I went to ACD. $60 / year for unlimited vs. $250/8TB. It was a no-brain-er.

What I’m currently doing is downloading into a hdd with 1.5TB of space. That then is filebot’d to a staging directory on a 180gb ssd, where my media files sit until they are uploaded to ACD encrypted drive via rclone copy after 1 minute, and then to gdrive encrypted via rclone move after 60 minutes. I know those time scales are very vigorous, but I have limited local free space. filebot is often not able to properly rename my media, and so, it sits in the download hdd for a time until I get around to manually doing something with it.

I HAD Plex pulling data through a unionfs mount setup between my staging directory and my ACD encrypted drive, however a few days after I set this up, my daughter asked me to play her favorite movie. It wouldn’t work. I ended up finding that the unionfs mount directory showed 0b filesize of the file (a known bug), and interestingly enough, Plex was somehow still able to play ~3s of this. Just enough to get my daughters hopes up, then drop them. So, I now point Plex directly at the ACD encrypted mount, and after 2-3 failures indicating file missing / permissions errors, it works, and plays the entire piece of media.

My wife can’t take the failures though, as she doesn’t understand. So, I’m here looking for a little assistance.

Below are all my scripts. Most of them are derived from this very forum. Maybe someone can make some sense out of them and assist.

I appreciate all the help from all of you, and hopefully these will help some of the others here as well.

Mount Points:

# Local mountpoint
mntpoint="/mnt/disks/GDriveSecure" 		# It's recommended to mount your remote share in /mnt/disks/subfolder - 
                                # This is the only way to make it accesible to dockers

# Remote share
remoteshare="GDriveSecure:/" 	# If you want to share the root of your remote share you have to 
                                # define it as "remote:" eg. "acd:" or "gdrive:" 

# Local mountpoint
mntpoint2="/mnt/disks/ACDSecure" 		# It's recommended to mount your remote share in /mnt/disks/subfolder - 
                                # This is the only way to make it accesible to dockers

# Remote share
remoteshare2="ACDSecure:/" 	# If you want to share the root of your remote share you have to 
                                # define it as "remote:" eg. "acd:" or "gdrive:" 


#---------------------------------------------------------------------------------------------------------------------

mkdir -p $mntpoint
rclone mount \
	--allow-non-empty \
	--allow-other \
	--max-read-ahead 4G \
	--buffer-size 1G \
	--contimeout 15s \
	--low-level-retries 1 \
	--no-check-certificate \
	--quiet \
	--stats 0 \
	--retries 3 \
	--timeout 30s \
	$remoteshare $mntpoint &

mkdir -p $mntpoint2
rclone mount \
	--allow-non-empty \
	--allow-other \
	--acd-templink-threshold 10G \
	--max-read-ahead 4G \
	--buffer-size 1G \
	--contimeout 15s \
	--low-level-retries 1 \
	--no-check-certificate \
	--quiet \
	--stats 0 \
	--retries 3 \
	--timeout 30s \
	$remoteshare2 $mntpoint2 &
	
mkdir -p /mnt/disks/UnionFS/Media/
sleep 10
unionfs \
        -o cow,allow_other,direct_io,auto_cache,sync_read,nonempty,hide_meta_files \
        /mnt/user/Media/Staging=RW:/mnt/disks/ACDSecure/Media=RO \
        /mnt/disks/UnionFS/Media/

Move From Staging To Cloud:

ps_out=`ps -ef | grep "rclone copy" | grep -v 'grep' | grep -v $0`
result=$(echo $ps_out | grep "$1")
if [[ "$result" != "" ]];then
    echo "Rclone copy is already Running."
else
    echo "Rclone copy is Not Running.  Starting it now..."
	rclone copy /mnt/user/Media/Staging/ ACDSecure:/Media/ --transfers=12 --min-age 1m --no-traverse --no-check-certificate --exclude Moana*.mkv -v
fi

ps_out=`ps -ef | grep "rclone move" | grep -v 'grep' | grep -v $0`
result=$(echo $ps_out | grep "$1")
if [[ "$result" != "" ]];then
    echo "Rclone move is already Running."
else
    echo "Rclone move is Not Running.  Starting it now..."
	rclone move /mnt/user/Media/Staging/ GDriveSecure:/Media/ --transfers=12 --min-age 60m --no-traverse --no-check-certificate -v
fi
exit

Check the mount and if it is not there, remount both the cloud drive and the union:

if [[ -f "/mnt/disks/GDriveSecure/ACDSecureTest.txt" ]]; then
   echo "$(date "+%d.%m.%Y %T") INFO: Check successful, GDriveSecure mounted" | tee -a "/var/log/acd-check.log"
else
   echo "$(date "+%d.%m.%Y %T") ERROR: GDriveSecure not mounted remount in progress" | tee -a "/var/log/acd-check.log"
#Change your mount point here
   mntpoint3="/mnt/disks/GDriveSecure"
   mntpoint="/mnt/disks/UnionFS/Media"
   fusermount -u $mntpoint
   fusermount -z $mntpoint
   umount -f $mntpoint
   umount -l $mntpoint
   fusermount -u $mntpoint3
   fusermount -z $mntpoint3
   umount -f $mntpoint3
   umount -l $mntpoint3
   sleep 5
rclone mount \
	--allow-non-empty \
	--allow-other \
	--max-read-ahead 4G \
	--buffer-size 1G \
	--contimeout 15s \
	--low-level-retries 1 \
	--no-check-certificate \
	--quiet \
	--stats 0 \
	--retries 3 \
	--timeout 30s \
	GDriveSecure:/ $mntpoint3 &
	mkdir -p /mnt/disks/UnionFS/Media/
    sleep 5
    unionfs \
        -o cow,allow_other,direct_io,auto_cache,sync_read,nonempty,hide_meta_files \
        /mnt/user/Media/Staging=RW:/mnt/disks/ACDSecure/Media=RO \
        /mnt/disks/UnionFS/Media/
sleep 5
   if [[ -f "/mnt/disks/GDriveSecure/ACDSecureTest.txt" ]]; then
      echo "$(date "+%d.%m.%Y %T") INFO: GDriveSecure Remount successful" | tee -a "/var/log/acd-check.log"
   else
      echo "$(date "+%d.%m.%Y %T") CRITICAL: GDriveSecure Remount failed." | tee -a "/var/log/acd-check.log"
   fi
fi
if [[ -f "/mnt/disks/ACDSecure/ACDSecureTest.txt" ]]; then
   echo "$(date "+%d.%m.%Y %T") INFO: Check successful, ACDSecure drive mounted" | tee -a "/var/log/acd-check.log"
else
   echo "$(date "+%d.%m.%Y %T") ERROR: ACDSecure Drive not mounted remount in progress" | tee -a "/var/log/acd-check.log"
#Change your mount point here
   mntpoint2="/mnt/disks/ACDSecure"
   mntpoint="/mnt/disks/UnionFS/Media"
   fusermount -u $mntpoint
   fusermount -z $mntpoint
   umount -f $mntpoint
   umount -l $mntpoint
   fusermount -u $mntpoint2
   fusermount -z $mntpoint2
   umount -f $mntpoint2
   umount -l $mntpoint2
   sleep 5
rclone mount \
	--allow-non-empty \
	--allow-other \
	--acd-templink-threshold 10G \
	--max-read-ahead 4G \
	--buffer-size 1G \
	--contimeout 15s \
	--low-level-retries 1 \
	--no-check-certificate \
	--quiet \
	--stats 0 \
	--retries 3 \
	--timeout 30s \
	ACDSecure:/ $mntpoint2 &
	mkdir -p /mnt/disks/UnionFS/Media/
    sleep 5
    unionfs \
        -o cow,allow_other,direct_io,auto_cache,sync_read,nonempty,hide_meta_files \
        /mnt/user/Media/Staging=RW:/mnt/disks/ACDSecure/Media=RO \
        /mnt/disks/UnionFS/Media/

sleep 5
   if [[ -f "/mnt/disks/ACDSecure/ACDSecureTest.txt" ]]; then
      echo "$(date "+%d.%m.%Y %T") INFO: ACDSecure Remount successful" | tee -a "/var/log/acd-check.log"
   else
      echo "$(date "+%d.%m.%Y %T") CRITICAL: ACDSecure Remount failed." | tee -a "/var/log/acd-check.log"
   fi
fi
exit

Sync the ACD Encrypted Drive to the GDrive Encrypted:

ps_out=`ps -ef | grep "rclone sync" | grep -v 'grep' | grep -v $0`
result=$(echo $ps_out | grep "$1")
if [[ "$result" != "" ]];then
    echo "Rclone sync is already Running."
else
    echo "Rclone sync is Not Running.  Starting it now..."
	rclone sync ACDSecure:/ GDriveSecure:/ --transfers=15 --no-check-certificate --bwlimit 60M -v
fi
exit