ChuckPa / PlexDBRepair

Database repair utility for Plex Media Server databases
Other
867 stars 43 forks source link

Change directory for Backup and Maintenance #85

Closed minermartijn closed 1 year ago

minermartijn commented 1 year ago

Gooodday Chuck,

First of all, awesome tool you made there. It made everything alot easier for alot of people. and im very gratefull for it thanks :).

I would very much like it if i could change the directory that all operations happen in. My Plex has its Databases directory on a ramdisk, and i dont want it to have to be as large as it is now. My sqlite files are about 3.9gb together, and with all the operations the ramdisk needs to be over 10gb.

Also, if there could be a way to have it create backups and have us choose where that would be great. Im using this in a Hotio container.

ChuckPa commented 1 year ago

The current implementation determines the Host (or container) type and configures to defaults.

If you want to customize the script itself for your use, I don't mind.
I never anticipated anyone running their PMS DB in RAM. I create the DBTMP on the file system to expressly avoid using RAM.

Here are the lines to modify: (you'll want Line 1482 and point it to a known HDD/SSD based storage point)

1481:  # Set tmp dir so we don't use RAM when in DBDIR
1482:  DBTMP="./dbtmp"
1483:  mkdir -p "$DBDIR/$DBTMP"
1484:  export TMPDIR="$DBTMP"
1485:  export TMP="$DBTMP"

The tool is designed for repair/optimization. It's not a backup tool. A simple file-based copy would serve you far better but I do see the "One Stop Shopping" thinking you have. I would have to figure out how to handle full pathnames as command arguments and work in every environment.

DBRepair.sh stop auto back "/path/to/someplace" start exit

PMS does make its own backups every 3 days (Scheduled Tasks). You can always avail yourself of copying those backup files.

minermartijn commented 1 year ago

If I run the following commands on both the blobs and db, will it be about the same as your script? Or should i keep away from these commands?, Or maybe add .vacuum with the second command? (Code field doenst work with my code, hopefully its readable enough)

` /usr/lib/plexmediaserver/Plex\ SQLite com.plexapp.plugins.library.blobs.db <<EOF .output /dev/shm/db-recover.sqlite .recover .quit EOF

mv com.plexapp.plugins.library.blobs.db "/home/administrator/com.plexapp.plugins.library.blobs.db.$(date +'%Y.%m.%d')"
/usr/lib/plexmediaserver/Plex\ SQLite com.plexapp.plugins.library.blobs.db <<EOF

.read /dev/shm/db-recover.sqlite .quit EOF

sudo rm /dev/shm/db-recover.sqlite`
ChuckPa commented 1 year ago

That will be about the same.

I am thinking about a -d /path/to/databases -s /path/to/PlexSQLite option set.

I'm not sure how to resolve that but am thinking.

minermartijn commented 1 year ago

Well like i said before, you are awesome haha. I changed the script like you said and it works wonders.

DBTMP="/dev/shm/dbtmp" mkdir -p "$DBTMP" export TMPDIR="$DBTMP" export TMP="$DBTMP"

Now my only problem remains, that because im running on ram. it sometimes malformes.. And the code i wrote before this, works to fix that.

But atleast for now i got your script working on my install! Thank you!

ChuckPa commented 1 year ago

Now my only problem remains, that because im running on ram. it sometimes malformes.. And the code i wrote before this, works to fix that.

That will happen on some machines. 'tmpfs' isn't as robustly file locked as full block devices. (I've never figured out why not)

OK to close here?

minermartijn commented 1 year ago

Yes it is, thanks for all the help!. hopefully some day this can run on RAM without any issues haha. Its so fast