DBRepair development

@wyldemusick

You can run the existing now. The core code works. Only the UI is changing.

I will be adding the new features but if you can manually stop & start plex, you’re good to go :wink:

1 Like

I’ve gotten very used to manually stopping and restarting Plex.

I’ve figured out how to incorporate it into the platforms which allow it.

When the platform supports start/stop, it will be presented as a valid command option.

When available:

[chuck@lizum tmp.2002]$ ./menus 
 
 
      Plex Media Server Database Repair Utility ()
 
Select
 
  Automatic database check, repair / optimize. Auto exit if successful
  Check database
  Index database
  Optimimize database
  Repair database
  Replace current database with newest usable backup copy
  Start PMS
  Stop PMS
  Undo last successful command
  Vacuum database
  Viewstate (Watch history) import from another PMS database
  Show logfile
  Quit / Exit
 
Enter command (4 letters required - not case sensitive):

When not available:

[chuck@lizum tmp.2004]$ ./menus 
 
 
      Plex Media Server Database Repair Utility ()
 
Select
 
  Automatic database check, repair / optimize. Auto exit if successful
  Check database
  Index database
  Optimimize database
  Repair database
  Replace current database with newest usable backup copy
  Undo last successful command
  Vacuum database
  Viewstate (Watch history) import from another PMS database
  Show logfile
  Quit / Exit
 
Enter command (4 letters required - not case sensitive):
1 Like

A gentle reminder regarding version numbers within the script :slight_smile:

@anon5074910

Do you want the version numbers INSIDE the script file as well?

(That makes the most sense to me)

Sounds like good to me.

Goal (at least for me) is to know what version of a script I have locally as part of my own automation.

Thanks.

That makes sense… Greatly appreciate that feedback.

2 Likes

I don’t want to delete anything though, basically I have my main server at home, and I have a remote server for family and when I’m out.

I copy the database from home to remote every 3 hours, this works great but it loses the watch history on the remote server, I just need to commands to run to copy the watched history from the old remote db to the new remote copy of my home db.

Hope that makes sense.

To COPY the watch history

  1. DUMP the table
  2. IMPORT that table into the other database.
  3. Job done

All that code exists in the script now. You only need to add a table name to the .dump command.

See Sync Watch State and Ratings

Plex allows you to optionally sync your watched/played state and personal ratings of movies and episodes with your Plex account online.

The file is on github: https://github.com/ChuckPa/PlexDBRepair/blob/master/DBRepair.sh

The section regarding copying watched state starts on line 1138.

# 7. - Get Viewstate/Watch history from another DB and import

thank you

thanks :slight_smile:

Folks,

I’ve been at it again :see_no_evil:

I am ready to show you what I’m working on.

It’s the folding of many requests into an updated form.

Superficial changes

  1. Commonly used Options appear first (resequenced)

  2. Options now have names “Commands”

  3. You may abbreviate any command after the first 4 characters (uniqueness)

  4. When the package starts

  5. I will be completing the cosmetic changes (like time stamps in important places) before releasing

  6. I will also complete fine tuning of the command order. A few still seem awkward. Your input welcomed

Key changes

  1. There is now an “Automatic” mode.
    – Automatic will perform Check, Repair, and Reindex for you in one step provided there are no errors.

  2. For those environments (packages and containers) where Stopping & Restarting PMS are safe, the tool can now do so. If it can’t, Start/Stop will show as “unavailable” (for now)

  3. It monitors space used and available. If there isn’t enough free space to perform a step (3x safety factor), it won’t do it. It will report so.

Here is how the updated UI looks.

[chuck@lizum PlexDBRepair.2030]$ sudo ./DBRepair-v1-dev.sh
 
 
 
      Plex Media Server Database Repair Utility (Ubuntu 20.04.5 LTS)
 
Select
 
  1 - 'stop' PMS
  2 - 'automatic' database check, repair/optimize, and reindex in one step.
  3 - 'check' database
  4 - 'vacuum' database
  5 - 'repair' / 'optimize' database
  6 - 'reindex' database
  7 - 'start' PMS
  8 - 'import' viewstate (Watch history) from another PMS database
  9 - 'replace current database with newest usable backup copy (interactive)
 10 - 'show' logfile
 11 - 'status' of PMS (Stop/Run and databases)
 12 - 'undo' - Undo last successful command
 99 -  exit
 
Enter command # -or- command name (4 char min) :

Here is how you can use it from the command line in your scripts (cron jobs)

root@lizum:/home/chuck/git/chuck/PlexDBRepair# ./DBRepair-v1-dev.sh stop auto start exit
 
 
 
      Plex Media Server Database Repair Utility (Ubuntu 20.04.5 LTS)
 
Select
 
  1 - 'stop' PMS
  2 - 'automatic' database check, repair/optimize, and reindex in one step.
  3 - 'check' database
  4 - 'vacuum' database
  5 - 'repair' / 'optimize' database
  6 - 'reindex' database
  7 - 'start' PMS
  8 - 'import' viewstate (Watch history) from another PMS database
  9 - 'replace current database with newest usable backup copy (interactive)
 10 - 'show' logfile
 11 - 'status' of PMS (Stop/Run and databases)
 12 - 'undo' - Undo last successful command
 99 -  exit
 
Enter command # -or- command name (4 char min) : stop
 
 
      Plex Media Server Database Repair Utility (Ubuntu 20.04.5 LTS)
 
Select
 
  1 - 'stop' PMS
  2 - 'automatic' database check, repair/optimize, and reindex in one step.
  3 - 'check' database
  4 - 'vacuum' database
  5 - 'repair' / 'optimize' database
  6 - 'reindex' database
  7 - 'start' PMS
  8 - 'import' viewstate (Watch history) from another PMS database
  9 - 'replace current database with newest usable backup copy (interactive)
 10 - 'show' logfile
 11 - 'status' of PMS (Stop/Run and databases)
 12 - 'undo' - Undo last successful command
 99 -  exit
 
Enter command # -or- command name (4 char min) : auto
Checking the PMS databases
Check complete.  PMS main database is OK.
Check complete.  PMS blobs database is OK.
Exporting current databases using timestamp: 2023-02-16_21.07.35
Export: (main)..(blobs)..done.
Successfully exported the main and blobs databases.  Proceeding to import into new databases.
Import: (main)..(blobs)..done.
Successfully imported data from exported SQL files.
Verifying databases integrity after importing.
Verification complete.  PMS main database is OK.
Verification complete.  PMS blobs database is OK.
Saving current databases with '-ORIG-2023-02-16_21.07.35'
Making imported databases active
Import complete. Please check your library settings and contents for completeness.
Recommend:  Scan Files and Refresh all metadata for each library section.
Backing up of databases
Backup current databases with '-ORIG-2023-02-16_21.07.35' timestamp.
Reindexing main database
Reindexing main database successful.
Reindexing blobs database
Reindexing blobs database successful.
Reindex complete.
Automatic Check,Repair/optimize,Index successful.
 
 
      Plex Media Server Database Repair Utility (Ubuntu 20.04.5 LTS)
 
Select
 
  1 - 'stop' PMS
  2 - 'automatic' database check, repair/optimize, and reindex in one step.
  3 - 'check' database
  4 - 'vacuum' database
  5 - 'repair' / 'optimize' database
  6 - 'reindex' database
  7 - 'start' PMS
  8 - 'import' viewstate (Watch history) from another PMS database
  9 - 'replace current database with newest usable backup copy (interactive)
 10 - 'show' logfile
 11 - 'status' of PMS (Stop/Run and databases)
 12 - 'undo' - Undo last successful command
 99 -  exit
 
Enter command # -or- command name (4 char min) : start
Started PMS
 
 
      Plex Media Server Database Repair Utility (Ubuntu 20.04.5 LTS)
 
Select
 
  1 - 'stop' PMS
  2 - 'automatic' database check, repair/optimize, and reindex in one step.
  3 - 'check' database
  4 - 'vacuum' database
  5 - 'repair' / 'optimize' database
  6 - 'reindex' database
  7 - 'start' PMS
  8 - 'import' viewstate (Watch history) from another PMS database
  9 - 'replace current database with newest usable backup copy (interactive)
 10 - 'show' logfile
 11 - 'status' of PMS (Stop/Run and databases)
 12 - 'undo' - Undo last successful command
 99 -  exit
 
Enter command # -or- command name (4 char min) : exit
root@lizum:/home/chuck/git/chuck/PlexDBRepair# 

I have tested this on Ubuntu, Debian, QNAP, Synology, and PMS Docker.
So far , everything is working OK.

My only concern with stopping Plex in a container is getting done and restarted before health checks force a restart and break something.

For you consideration and feedback.
DBRepair-v1-dev.tar (50 KB)

3 Likes

Questions:

  1. Where does ‘start’ best go?
  • After “import” & “replace”

  • or right where it is given import & replace aren’t too commonly used ?

  1. Should “Import” and “Replace” be moved up higher into the main group ?
  • I’m inclined to put “Start” after ALL ‘database changing’ items.
    – “Last thing I do is start Plex” thinking.
  1. I’m also inclined to put import & replace right after vacuum (when we know the databases are good or skip to repair)

I like the order as is. The first seven steps, stop through start, are the primary reason the tool exists and the commands that will be most used.

Steps eight through twelve are “extras” if you will. Nice to have, very useful, but not the main purpose of the tool.

Playing with one more idea… time stamping.

  1 - 'stop' PMS
  2 - 'automatic' database check, repair/optimize, and reindex in one step.
  3 - 'check' database
  4 - 'vacuum' database
  5 - 'repair' / 'optimize' database
  6 - 'reindex' database
  7 - 'start' PMS
  8 - 'import' viewstate (Watch history) from another PMS database
  9 - 'replace current database with newest usable backup copy (interactive)
 10 - 'show' logfile
 11 - 'status' of PMS (Stop/Run and databases)
 12 - 'undo' - Undo last successful command
 99 -  exit
 
Enter command # -or- command name (4 char min) : 2
 
[23:21] Checking the PMS databases
[23:22] Check complete.  PMS main database is OK.
[23:22] Check complete.  PMS blobs database is OK.
[23:22] Exporting current databases using timestamp: 2023-02-16_23.21.52
Export: (main)..(blobs)..done.
[23:23] Successfully exported the main and blobs databases.  Proceeding to import into new databases.
Import: (main)..(blobs)..done.
[23:24] Successfully imported data from exported SQL files.
[23:24] Verifying databases integrity after importing.
[23:25] Verification complete.  PMS main database is OK.
[23:25] Verification complete.  PMS blobs database is OK.
[23:25] Saving current databases with '-ORIG-2023-02-16_23.21.52'
[23:25] Making imported databases active
[23:25] Import complete. Please check your library settings and contents for completeness.
[23:25] Recommend:  Scan Files and Refresh all metadata for each library section.
[23:25] Backing up of databases
[23:25] Backup current databases with '-ORIG-2023-02-16_23.21.52' timestamp.
[23:25] Reindexing main database
[23:26] Reindexing main database successful.
[23:26] Reindexing blobs database
[23:26] Reindexing blobs database successful.
[23:26] Reindex complete.
[23:26] Automatic Check,Repair/optimize,Index successful.
 
 
      Plex Media Server Database Repair Utility (Ubuntu 20.04.5 LTS)
 

Keep or drop?

Most certainly keep - always good to have timestamps.

Reading on the forum I like the look of the new menu along with the inclusion of automatic and will give the updated tool a test drive later. Thanks for keeping this automation updated and improved.

EDIT: Looks good to me. Main use case for me will be sudo sh DBRepair-v1-dev.sh automatic exit which runs perfectly on my ubuntu 22.04 server. Other options are handy to have and appreached in the tool.

Some (very minor) formatting issues with some of the messages outputted to the terminal when the tool is running if I was to be picky :slight_smile: QA part of my brain is kicking in …

@anon5074910

This isn’t anywhere nearly finished.

This is me, showing you what I’m working on.

If this is a good direction then I’ll finish it and make it look nice and “OCD Pretty” :rofl: before I release it as the new version on Github.

I have a lot of changes for the README.md too

I suspect the main use sequence will be:

DBRepair.sh  stop auto start exit

and be run in CRON by everyone

2 Likes

Development update -

  1. Menu is now stabilized

  2. Console output now includes [HH.MM.SS] timestamp
    – Allows setting the Docker container health check timeout to prevent restart of the container while performing maintenance.

  3. Free Space Available testing performed before any DB operation.
    (Space required is: ( sizeof (Main) + size of (Blobs)) * 3
    This allows copy of current, in process temp, and room to export DB to ASCII)

EDIT:

20-Feb-2023

  • fixed :see_no_evil: copy/paste error
  • made timestamp update better
2 Likes