With the migration from Dragonfish to ElectricEel-24.10.0.2 and the Docker containers, I thought I would try again in setting up a backup script to backup my Plex data to a directory on my TrueNAS server. (I already have it configured to have my My configuration is as follows:
When I’m logged in as root and enter these commands manually, I am able to stop my Plex instance, create a tar file (it just takes 30 minutes) , then restart my plex instance. But, when I put those same commands into a shell script and attempt to run it:
root@vaultron[/mnt/pool/plex]# ./backup.sh
: not found: 3:
./backup.sh: 4: cd: can't cd to /mnt/pool/app-config/plex
Error response from daemon: No such container: ix-plex-plex-1
: not found: 6:
tar: .\r: Cannot stat: No such file or directory
tar: Exiting with failure status due to previous errors
: not found: 8:
ix-plex-plex-1
root@vaultron[/mnt/pool/plex]#
Yes, I have tried the #! /bin/bash and #! /bin/sh as the first line, but those are thowing errors as well. I may need to change some directory permissions, but still… what is this shell script novice doing wrong?
root@vaultron[/mnt/pool/plex]# cd /mnt/pool/plex && ./backup.sh
: not found: 3:
./backup.sh: 4: cd: can't cd to /mnt/pool/app-config/plex
Error response from daemon: No such container: ix-plex-plex-1
: not found: 6:
tar: .\r: Cannot stat: No such file or directory
tar: Exiting with failure status due to previous errors
: not found: 8:
ix-plex-plex-1
root@vaultron[/mnt/pool/plex]#
You have a carriage return character after sh instead of a line feed character that Linux requires.
Those characters are typically not visible in text editors, remove it by placing the blinking cursor right after the “h” in #!/bin/sh and press DEL/DELETE to delete the (invisible) carriage return character to the right. Then press ENTER to create the correct line break to replace it.
Yes, I did. These were the same commands that I used months ago when I migrated from TrueNAS CORE to TrueNAS SCALE. One of the bonuses of this upgrade was being able to use Sonic Analysis in Plex which wasn’t available in CORE because it was running FreeBSD.
Yes, I agree that config and data should be in separate directories. One of my mistakes when I migrated from TrueNAS CORE to TrueNAS SCALE was that I had set the Plex Configuration Storage and Plex Data Storage in the app to the same directory of /mnt/pool/plex . I blame it on the rush on getting my Plex instance back online and the newbieness of using Apps in SCALE. After installing multiple Apps since then, I gained experience, and finally sat down and migrated the Plex Configuration Storage over to /mnt/pool/app-config/plex. That’s when I figured I should tackle the backups once again.
The backup completed successfully although it took 58 minutes, and all of the files are there minus the Logs, Cache, and Plug-in Support/Caches as expected. When I extract the tar file using the options -vxf, I’m seeing the following with all of the files:
tar: ./Library/Application Support/Plex Media Server/Plug-in Support/Databases/tv.plex.providers.epg.cloud-d451573b-b195-4387-8a22-2877417cb388.db-shm: Cannot change mode to rwxrw-r--: Operation not permitted
The permissions I’m seeing are 777, go figure. The test on another Plex instance will have to wait until another weekend.
Here is the latest iteration of my backup script. Other than taking 52 minutes to run, it is working out great. I’ve implemented the date function so that I have two backups locally, and the cron job runs at 6 AM locally on Sunday mornings.
I did the test extraction to /mnt/pool/app-config/plex-test and temporarily pointed my Plex to that directory. After about a minute, Plex came right up, although some images had to be rebuilt. This was expected… the Cache was intentionally backed up. Playback worked. I then pointed Plex back to /mnt/pool/app-config/plex which is my production. Everything works in terms of backup, plus I have the script rotate my backups so that I have this week and last week.