I know this isn't a Plex forum, but have you ever tried navigating theirs? Sheesh.
Anyway, I run Plex Media Server on my Ubuntu MATE 22.04.5 LTS. For reasons not known to me, the Plex sqlite3 databases sometimes go wonky, requiring me to revert to earlier versions. Plex makes backups every three days, but losing three days of updates requires time and patience to bring things back to the present, so I wrote a script that I run via cron every night to make a backup. It requires superuser privileges, so I run it in root's crontab.
#!/bin/bash
#
# Plex only backs up its databases every three days. This is a manual method to do it
# more often. Please NOTE: The plexmediaserver is taken offline in order to do this
# cleanly.
#
# Must be run as root. This is not secure, but...
#
# NOTE: "******" replaces the actual root password in this script.
# (i.e. "******" = rootpass)
# It might be possible to store the root password in a variable
#
# Step 1: Stop Plex
#
echo "******" | sudo -S systemctl stop plexmediaserver
#
cd "/var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Plug-in Support/Databases/"
#
# Step 2: Copy the database files
#
echo "******" | sudo -S cp com.plexapp.plugins.library.db com.plexapp.plugins.library.db-$(date +%m-%d-%Y).bak
echo "******" | sudo -S cp com.plexapp.plugins.library.blobs.db com.plexapp.plugins.library.blobs.db-$(date +%m-%d-%Y).bak
#
# Step 3: Apply proper ownership to file
#
echo "******" | sudo -S chown plex *db
echo "******" | sudo -S chown plex *bak
#
# Step 4: Restart Plex & make sure it's running
#
echo "******" | sudo -S systemctl start plexmediaserver
#
If I need to restore from a backup, I simply reverse the process (no script yet, this is a manual process):
Everything is run under root.
- Stop Plex
- Rename the two "active" files (those with the simple .db extension). I give them the extension of .active
- Copy the two needed files, stripping off the date suffixes
- Change the ownership to the plex account (running as root changes the owner)
- Start Plex
This has saved me a lot of time and frustration. If I knew why Plex's databases were so unreliable, this wouldn't be necessary. Also, I periodically manually "prune" these backups as they have no expiration. They aren't large, but after time they can consume disk space.