Can you copy/backup the plex database dir in ubuntu with plex running?

can you copy/backup the plex database dir in ubuntu with plex running?

just had another disaster where a drive was accidentally unmounted and did a scan : (

went back to a database backup rather than wait for hours for plex to re find/take the trash can icon away… alas days old its still gonna take a while to reimport stuff…

i’d back up the database every day if i didn’t have to stop plex to copy the database… is that really necessary? just wondering…

No. You cannot operate on anything in Plex with Plex running unless you’re doing it through the Plex GUI.

What happened that made you resort to this ? the drive unmounted? PMS watches for that.

Given you speak of hours to do things, I wonder if the tool I’ve written might help you .

First, let’s address what happened?

plexdrive… which i love (still get twice the speed via compared to rclone mounts) used to crash and unmount like once every 6 or 7 months… but lately its done in like once every couple weeks
: ) : (

i have a shortcut to check the drive is still mounted before i do a scan… but got lazy and was in a hurry and paid the price…

so plex red trashcans everything in the my two main libraries, that i scanned not realizing it was unmounted…

it used to be you could still play the red trash caned files after you reconnected the drive… but at some point that play button on red trash can items went away : (

scanning 100’s of thousands of things in the cloud that were trash canned takes hours/days… so i restored a backup… and just had to reimport the last 3 days worth of stuff…

i’d back up the database multiple times a day and avoid ever having this kind of disaster… if not for the fact that i’d have to shut down plex to do it : ) :frowning:

was just wondering if it was possible to make a copy of the database while plex was running… but your saying thats not a good idea right?

You can make a copy BUT , so you’re informed:

  1. Whatever PMS is doing, won’t be in the DB yet
  2. The DB has WAL & SHM files
  • WAL = Write Ahead Lookup (write cache it uses for transactions)
  • SHM = Shared memory mapping between PMS and SQLite (this is the voodoo)

In majority of cases, If you have to make a ‘snapshot’ and the SERVER IS QUIET –

– you can get away with it but you always risk SOME (maybe only a few) pending database updates

1 Like

yea i wouldnt care at all about missing a few pending things… : )

Then go ahead. Now you know what risks you take.

For me:

systemctl stop plexmediaserver

cd "/var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Plug-in Support/Databases"

tar cf /path/to/backup/PMS-Backup-$(date "+%Y-%m-%d %H.%M.%S").tar  com.*

systemctl start plexmediaserver

This takes 2 minutes for me.

1 Like

thanks for that… i’ll make that a macro in mobaxterm to use when the server is not being used : )

i manually cut and paste a command changing the date-time of the backup…

like this-

sudo cp -a /mnt/ramdisk/Databases /mnt/eight-one/Databases/march3-1pm

i’m linux/command line semi illiterate, but is there a (date “+%Y-%m-%d %H.%M.%S”) type bit i could add to the copy command to have it automatically copy the databases folders contents to a folder automatically named with the date and time? tried googling it but i’m an idiot and couldn’t quite figure it out…

slightly off topic… but i just noticed as i was running yer suggestion… that the database duplicate is back… a 2.7gb db file and a 2.7gb db-wal file… is this normal? the time stamps says they are both being written to right now… what exactly is going in there, why are there two databases occasionally? hadn;t seen it happen in a while… (i wouldnt really care, cept i run my database in ram… and have to increase the ramdisk when i want to run your dbrepair prog)

2.7 GB WAL file tells me the 2.7 GB “DB” file was “Optimized” in PMS but the server has not yet been restarted

the “WAL” are all the pending changes. They are ‘commit’ ed to the main DB as PMS closes.

WAL → DB … this is done by SQLite3

======================================

If you want to make a Backup directory somewhere – which is Date-Time Stamped

#Define the dir name
Dir="/mnt/eight-one/Databases/$(date "+%Y-%m-%d_%H-%M")"

# Create it
mkdir -p "$Dir"

# Copy the principle DB files.
cp  com.plexapp.plugins.library.db* com.plexapp.plugins.library.blobs.db*  "$Dir"

Date format I show here is:

[chuck@lizum ~.2004]$ date "+%Y-%m-%d_%H-%M"
2023-03-02_16-06
[chuck@lizum ~.2005]$ 
1 Like

don’t i need to enter the full path to the Databases dir in the copy command?

ie /mnt/ramdisk/Databases

A post was split to a new topic: Changes could not be saved

@jaquestati

Look what I wrote:

Dir="/mnt/eight-one/Databases/$(date "+%Y-%m-%d_%H-%M")"

# Create it
mkdir -p "$Dir"

# Copy the principle DB files.
cp  com.plexapp.plugins.library.db* com.plexapp.plugins.library.blobs.db*  "$Dir"
  1. variable “Dir” is a full path

  2. mkdir -p “$Dir” makes that full path

  3. cp com.plexapp.plugins.library.db* com.plexapp.plugins.library.blobs.db* “$Dir”
    – Copies everything found to the Full Path pointed to by “$Dir”

This way, you set “Dir” in one place. All the other commands reference it automatically.

Try this on the command line

A="123"
A+="456"
echo $A

:slight_smile: Programming is fun

ha… sorry i’m such an idiot… i tried the above and get a path not found error…

i’m confused as to where i put the actual directory my database is in… (its /mnt/ramdisk/Databases btw)

assume i’m a complete idiot (not much of a stretch obviously : )

if my plex databases folder is at /mnt/ramdisk/Databases

and the place i’d like to backup/copy/put the dated folder is at /mnt/eight-one/Databases

what are the exact commands i should run?

I tried to use the path you showed above.

OBVIOUSLY :rofl: I didn’t get it 100% right.

Let’s back up.

  1. Where do you want the data copied ?

  2. What date/time format do you want for the directory name ? (any structure?)

  3. Is plex installed in the default “/var/lib/plexmediaserver” location?

i’d like it copied to /mnt/eight-one/Databases

and my plex database dir is on a ramdisk at /mnt/ramdisk/Databases : )

and any date and time format is fine

  1. I will write this based on:
    – It runs as ‘root’ user --OR-- the username running it has full permissions.
    – I presume it’s a Shell script which you’ll run yourself or via automation.
#!/bin/bash

# Where are the PMS databases
SrcDir="/mnt/ramdisk/Databases"

# Creates: /mnt/eight-one/Databases/YYYY-mm-dd_HH-MM/<databases>
DestDir="/mnt/eight-one/Databases/$(date "+%Y-%m-%d_%H-%M")"

# Create destination directory
mkdir -p "$DestDir"
Result=$?

if [ $Result -ne 0 ]; then
  echo ERROR:  Could not create directory '$DestDir'.  Stopping.
  exit 1
fi

# Now get into the directory
cd "$SrcDir"

# Copy the main and blobs databases
cp -p com.plexapp.plugins.library.db* com.plexapp.plugins.library.blobs.db* "$DestDir"
Result=$?

# Make sure it copied OK
if [ $Result -ne 0 ]; then 
  echo ERROR:  Not able to copy all files.  System error  $Result
  exit 2
fi
exit

To use this.

  1. Save the script contents to a file
  2. do a ‘chmod +x filename
  3. Run it

It will stop if it can’t create the directory
It will report if it wasn’t able to copy everything without error

1 Like

thanks so much… : )

i will try this tomorrow as my eyes are starting to give out : ) : (

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.