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…
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 : )
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?
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]$
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.
Save the script contents to a file
do a ‘chmod +x filename’
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