Shell Script help: Making a plex backup

It’s been there for a while, not sure when it was added. It’s under settings → scheduled tasks. The arrs have something similar. I just have the default directories hostpath mounted to another location that gets pushed to google drive.

Can’t remember if I copied plex’s preferences.xml to the folder or not.

It dumps 2 files:

com.plexapp.plugins.library.blobs.db-$DATE
com.plexapp.plugins.library.db-$DATE

Both seem to be compressed.

When I wrote the script, I was basing it on what I learned from Move an Install to Another System | Plex Support . I suppose I could optimize the script and reduce the downtime by skipping the DBs that are in use when I perform the backup, stops the docker container, backup the DBs, then start the docker container, but as it is, I can afford the downtime at 6-7 AM on a Sunday morning while everyone else is sleeping in… including a buddy of mine who also is allowed to use the server.

Weekly backups with a current week/previous week should be “good enough” for my needs. I’m just happy that the process is working again.

Here is the revised script after I migrated the app from my HDD pool to a SSD mirror drive set. Of particular note… I “speeded up” the script by changing -zcf to just -cf , then gzipping the tar file afterward. This reduces the downtime on the Plex instance to about 1-2 minutes.

#!/bin/sh

# Single we run this on a weekly basis, we want to keep two weeks of backups
now="plexbackup-$(date +%F)"
old="plexbackup-$(date +%F --date='2 weeks ago')"

# Plex configuration
cd /mnt/nvme/apps/plex/Library/Application\ Support

# Shut down Plex instance
echo "Stopping Plex Instance"
docker stop ix-plex-plex-1

# Archive the files, use --verbose when testing
echo "TARing files"
tar --exclude=Plex\ Media\ Server/Cache --exclude=Plex\ Media\ Server/Logs --exclude=Plex\ Media\ Server/Plug-in\ Support/Caches -cf /mnt/nvme/backup/Plex/Weekly/$now.tar .

# Restart Plex instance
echo "Starting Plex Instance"
docker start ix-plex-plex-1

# Changing the directory
cd /mnt/nvme/backup/Plex/Weekly

# Compressing the backup
echo "Compressing the backup"
gzip $now.tar

# Remove oldest backup
echo "Removing Oldest Backup"
rm $old.tar.gz