Merge pull request #201 from danrahn/master

Update Windows scripts to reflect name change
This commit is contained in:
Chuck 2025-05-24 10:39:30 -04:00 committed by GitHub
commit d6f4dbf263
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 47 additions and 44 deletions

View File

@ -10,7 +10,7 @@ To contribute to the project, please follow the following instructions:
### When submitting your work for review and merge: ### When submitting your work for review and merge:
1. Create an issue in the PlexDBRepair repo against the current release 1. Create an issue in the DBRepair repo against the current release
- Describe the deficiency to be addressed in sufficient detail - Describe the deficiency to be addressed in sufficient detail
2. Complete your work in your branch 2. Complete your work in your branch
@ -26,7 +26,7 @@ To contribute to the project, please follow the following instructions:
5. In the pull request, provide a description of what change(s) where made 5. In the pull request, provide a description of what change(s) where made
- As last text added, on a blank line, - As last text added, on a blank line,
- Add the text: `Fixes:` followed by the URL of the open Issue - Add the text: `Fixes:` followed by the URL of the open Issue
eg: Fixes: https://ChuckPa/PlexDBRepair/issues/12 (if we were fixing issue 12) eg: Fixes: https://github.com/ChuckPa/DBRepair/issues/12 (if we were fixing issue 12)
- Adding the above text & URL has the following impact: - Adding the above text & URL has the following impact:
-- The Issue which prompted the change is forever linked to the PR making documentation easy. -- The Issue which prompted the change is forever linked to the PR making documentation easy.

View File

@ -1,5 +1,5 @@
@echo off @echo off
REM PlexDBRepair.bat - Database maintenance / rebuild tool for Windows. REM DBRepair.bat - Database maintenance / rebuild tool for Windows.
REM REM
REM This tool currently works as a "full shot" service. REM This tool currently works as a "full shot" service.
REM - everything is done without need to interact. REM - everything is done without need to interact.
@ -78,13 +78,13 @@ set "TmpFile=%DBtmp%\results.tmp"
REM Time now. REM Time now.
echo %time% -- ====== Session begins. (%date%) ====== echo %time% -- ====== Session begins. (%date%) ======
echo %time% -- ====== Session begins. (%date%) ====== >> "%PlexData%\PlexDBRepair.log" echo %time% -- ====== Session begins. (%date%) ====== >> "%PlexData%\DBRepair.log"
REM Make certain Plex is NOT running. REM Make certain Plex is NOT running.
tasklist | find /I "Plex Media Server.exe" >NUL tasklist | find /I "Plex Media Server.exe" >NUL
if %ERRORLEVEL%==0 ( if %ERRORLEVEL%==0 (
echo %time% -- Plex is running. Please stop Plex Media Server and try again. echo %time% -- Plex is running. Please stop Plex Media Server and try again.
echo %time% -- Plex is running. Please stop Plex Media Server and try again. >> "%PlexData%\PlexDBRepair.log" echo %time% -- Plex is running. Please stop Plex Media Server and try again. >> "%PlexData%\DBRepair.log"
exit /B 1 exit /B 1
) )
@ -95,7 +95,7 @@ md "%PlexData%\dbtmp" 2>NUL
del "%TmpFile%" 2>NUL del "%TmpFile%" 2>NUL
echo %time% -- Exporting Main DB echo %time% -- Exporting Main DB
echo %time% -- Exporting Main DB >> "%PlexData%\PlexDBRepair.log" echo %time% -- Exporting Main DB >> "%PlexData%\DBRepair.log"
echo .dump | "%PlexSQL%" "%PlexData%\com.plexapp.plugins.library.db" > "%DBtmp%\library.sql_%TimeStamp%" echo .dump | "%PlexSQL%" "%PlexData%\com.plexapp.plugins.library.db" > "%DBtmp%\library.sql_%TimeStamp%"
if not %ERRORLEVEL%==0 ( if not %ERRORLEVEL%==0 (
echo %time% -- ERROR: Cannot export Main DB. Aborting. echo %time% -- ERROR: Cannot export Main DB. Aborting.
@ -103,7 +103,7 @@ if not %ERRORLEVEL%==0 (
) )
echo %time% -- Exporting Blobs DB echo %time% -- Exporting Blobs DB
echo %time% -- Exporting Blobs DB >> "%PlexData%\PlexDBRepair.log" echo %time% -- Exporting Blobs DB >> "%PlexData%\DBRepair.log"
echo .dump | "%PlexSQL%" "%PlexData%\com.plexapp.plugins.library.blobs.db" > "%DBtmp%\blobs.sql_%TimeStamp%" echo .dump | "%PlexSQL%" "%PlexData%\com.plexapp.plugins.library.blobs.db" > "%DBtmp%\blobs.sql_%TimeStamp%"
if not %ERRORLEVEL%==0 ( if not %ERRORLEVEL%==0 (
echo %time% -- ERROR: Cannot export Blobs DB. Aborting. echo %time% -- ERROR: Cannot export Blobs DB. Aborting.
@ -111,75 +111,75 @@ if not %ERRORLEVEL%==0 (
REM Now create new databases from SQL statements REM Now create new databases from SQL statements
echo %time% -- Exporting Complete. echo %time% -- Exporting Complete.
echo %time% -- Exporting Complete. >> "%PlexData%\PlexDBRepair.log" echo %time% -- Exporting Complete. >> "%PlexData%\DBRepair.log"
echo %time% -- Creating Main DB echo %time% -- Creating Main DB
echo %time% -- Creating Main DB >> "%PlexData%\PlexDBRepair.log" echo %time% -- Creating Main DB >> "%PlexData%\DBRepair.log"
"%PlexSQL%" "%PlexData%\com.plexapp.plugins.library.db_%TimeStamp%" < "%DBtmp%\library.sql_%TimeStamp%" "%PlexSQL%" "%PlexData%\com.plexapp.plugins.library.db_%TimeStamp%" < "%DBtmp%\library.sql_%TimeStamp%"
if not %ERRORLEVEL%==0 ( if not %ERRORLEVEL%==0 (
echo %time% -- ERROR: Cannot create Main DB. Aborting. echo %time% -- ERROR: Cannot create Main DB. Aborting.
echo %time% -- ERROR: Cannot create Main DB. Aborting. >> "%PlexData%\PlexDBRepair.log" echo %time% -- ERROR: Cannot create Main DB. Aborting. >> "%PlexData%\DBRepair.log"
exit /b 3 exit /b 3
) )
echo %time% -- Verifying Main DB echo %time% -- Verifying Main DB
echo %time% -- Verifying Main DB >> "%PlexData%\PlexDBRepair.log" echo %time% -- Verifying Main DB >> "%PlexData%\DBRepair.log"
"%PlexSQL%" "%PlexData%\com.plexapp.plugins.library.db_%TimeStamp%" "PRAGMA integrity_check(1)" >"%TmpFile%" "%PlexSQL%" "%PlexData%\com.plexapp.plugins.library.db_%TimeStamp%" "PRAGMA integrity_check(1)" >"%TmpFile%"
set /p Result= < "%TmpFile%" set /p Result= < "%TmpFile%"
del "%TmpFile%" del "%TmpFile%"
echo %time% -- Main DB verification check is: %Result% echo %time% -- Main DB verification check is: %Result%
echo %time% -- Main DB verification check is: %Result% >> "%PlexData%\PlexDBRepair.log" echo %time% -- Main DB verification check is: %Result% >> "%PlexData%\DBRepair.log"
if not "%Result%" == "ok" ( if not "%Result%" == "ok" (
echo %time% -- ERROR: Main DB verificaion failed. Exiting. echo %time% -- ERROR: Main DB verificaion failed. Exiting.
echo %time% -- ERROR: Main DB verificaion failed. Exiting. >> "%PlexData%\PlexDBRepair.log" echo %time% -- ERROR: Main DB verificaion failed. Exiting. >> "%PlexData%\DBRepair.log"
exit /B 4 exit /B 4
) )
echo %time% -- Main DB verification successful. echo %time% -- Main DB verification successful.
echo %time% -- Main DB verification successful. >> "%PlexData%\PlexDBRepair.log" echo %time% -- Main DB verification successful. >> "%PlexData%\DBRepair.log"
echo %time% -- Creating Blobs DB echo %time% -- Creating Blobs DB
echo %time% -- Creating Blobs DB >> "%PlexData%\PlexDBRepair.log" echo %time% -- Creating Blobs DB >> "%PlexData%\DBRepair.log"
"%PlexSQL%" "%PlexData%\com.plexapp.plugins.library.blobs.db_%TimeStamp%" < "%DBtmp%\blobs.sql_%TimeStamp%" "%PlexSQL%" "%PlexData%\com.plexapp.plugins.library.blobs.db_%TimeStamp%" < "%DBtmp%\blobs.sql_%TimeStamp%"
if not %ERRORLEVEL%==0 ( if not %ERRORLEVEL%==0 (
echo %time% -- ERROR: Cannot create Blobs DB. Aborting. echo %time% -- ERROR: Cannot create Blobs DB. Aborting.
echo %time% -- ERROR: Cannot create Blobs DB. Aborting. >> "%PlexData%\PlexDBRepair.log" echo %time% -- ERROR: Cannot create Blobs DB. Aborting. >> "%PlexData%\DBRepair.log"
exit /b 5 exit /b 5
) )
echo %time% -- Verifying Blobs DB echo %time% -- Verifying Blobs DB
echo %time% -- Verifying Blobs DB >> "%PlexData%\PlexDBRepair.log" echo %time% -- Verifying Blobs DB >> "%PlexData%\DBRepair.log"
"%PlexSQL%" "%PlexData%\com.plexapp.plugins.library.blobs.db_%TimeStamp%" "PRAGMA integrity_check(1)" > "%TmpFile%" "%PlexSQL%" "%PlexData%\com.plexapp.plugins.library.blobs.db_%TimeStamp%" "PRAGMA integrity_check(1)" > "%TmpFile%"
set /p Result= < "%TmpFile%" set /p Result= < "%TmpFile%"
del "%TmpFile%" del "%TmpFile%"
echo %time% -- Blobs DB verification check is: %Result% echo %time% -- Blobs DB verification check is: %Result%
echo %time% -- Blobs DB verification check is: %Result% >> "%PlexData%\PlexDBRepair.log" echo %time% -- Blobs DB verification check is: %Result% >> "%PlexData%\DBRepair.log"
if not "%Result%" == "ok" ( if not "%Result%" == "ok" (
echo %time% -- ERROR: Blobs DB verificaion failed. Exiting. echo %time% -- ERROR: Blobs DB verificaion failed. Exiting.
echo %time% -- ERROR: Blobs DB verificaion failed. Exiting. >> "%PlexData%\PlexDBRepair.log" echo %time% -- ERROR: Blobs DB verificaion failed. Exiting. >> "%PlexData%\DBRepair.log"
exit /B 6 exit /B 6
) )
echo %time% -- Blobs DB verification successful. echo %time% -- Blobs DB verification successful.
echo %time% -- Blobs DB verification successful. >> "%PlexData%\PlexDBRepair.log" echo %time% -- Blobs DB verification successful. >> "%PlexData%\DBRepair.log"
echo %time% -- Import and verification complete. echo %time% -- Import and verification complete.
echo %time% -- Import and verification complete. >> "%PlexData%\PlexDBRepair.log" echo %time% -- Import and verification complete. >> "%PlexData%\DBRepair.log"
REM Import complete, now reindex REM Import complete, now reindex
echo %time% -- Reindexing Main DB echo %time% -- Reindexing Main DB
echo %time% -- Reindexing Main DB >> "%PlexData%\PlexDBRepair.log" echo %time% -- Reindexing Main DB >> "%PlexData%\DBRepair.log"
"%PlexSQL%" "%PlexData%\com.plexapp.plugins.library.db_%TimeStamp%" "REINDEX;" "%PlexSQL%" "%PlexData%\com.plexapp.plugins.library.db_%TimeStamp%" "REINDEX;"
echo %time% -- Reindexing Blobs DB echo %time% -- Reindexing Blobs DB
echo %time% -- Reindexing Blobs DB >> "%PlexData%\PlexDBRepair.log" echo %time% -- Reindexing Blobs DB >> "%PlexData%\DBRepair.log"
"%PlexSQL%" "%PlexData%\com.plexapp.plugins.library.blobs.db_%TimeStamp%" "REINDEX;" "%PlexSQL%" "%PlexData%\com.plexapp.plugins.library.blobs.db_%TimeStamp%" "REINDEX;"
REM Index complete, make active REM Index complete, make active
echo %time% -- Reindexing complete. echo %time% -- Reindexing complete.
echo %time% -- Reindexing complete. >> "%PlexData%\PlexDBRepair.log" echo %time% -- Reindexing complete. >> "%PlexData%\DBRepair.log"
echo %time% -- Moving current DBs to DBTMP and making new databases active echo %time% -- Moving current DBs to DBTMP and making new databases active
echo %time% -- Moving current DBs to DBTMP and making new databases active >> "%PlexData%\PlexDBRepair.log" echo %time% -- Moving current DBs to DBTMP and making new databases active >> "%PlexData%\DBRepair.log"
move "%PlexData%\com.plexapp.plugins.library.db" "%PlexData%\dbtmp\com.plexapp.plugins.library.db_%TimeStamp%" move "%PlexData%\com.plexapp.plugins.library.db" "%PlexData%\dbtmp\com.plexapp.plugins.library.db_%TimeStamp%"
move "%PlexData%\com.plexapp.plugins.library.db_%TimeStamp%" "%PlexData%\com.plexapp.plugins.library.db" move "%PlexData%\com.plexapp.plugins.library.db_%TimeStamp%" "%PlexData%\com.plexapp.plugins.library.db"
@ -188,9 +188,9 @@ move "%PlexData%\com.plexapp.plugins.library.blobs.db" "%PlexData%\d
move "%PlexData%\com.plexapp.plugins.library.blobs.db_%TimeStamp%" "%PlexData%\com.plexapp.plugins.library.blobs.db" move "%PlexData%\com.plexapp.plugins.library.blobs.db_%TimeStamp%" "%PlexData%\com.plexapp.plugins.library.blobs.db"
echo %time% -- Database repair/rebuild/reindex completed. echo %time% -- Database repair/rebuild/reindex completed.
echo %time% -- Database repair/rebuild/reindex completed. >> "%PlexData%\PlexDBRepair.log" echo %time% -- Database repair/rebuild/reindex completed. >> "%PlexData%\DBRepair.log"
echo %time% -- ====== Session completed. ====== echo %time% -- ====== Session completed. ======
echo %time% -- ====== Session completed. ====== >> "%PlexData%\PlexDBRepair.log" echo %time% -- ====== Session completed. ====== >> "%PlexData%\DBRepair.log"
exit /b exit /b
@ -201,5 +201,5 @@ REM Output - Write text to the console and the log file
:Output :Output
echo %time% %~1 echo %time% %~1
echo %time% %~1 >> "%PlexData%\PlexDBRepair.log" echo %time% %~1 >> "%PlexData%\DBRepair.log"
exit /B exit /B

View File

@ -1,12 +1,12 @@
######################################################################### #########################################################################
# Plex Media Server database check and repair utility script. # # Database check and repair utility script for Plex Media Server #
# # # #
######################################################################### #########################################################################
$PlexDBRepairVersion = 'v1.00.02' $DBRepairVersion = 'v1.01.00'
class PlexDBRepair { class DBRepair {
[PlexDBRepairOptions] $Options [DBRepairOptions] $Options
[string] $PlexDBDir # Path to Plex's Databases directory [string] $PlexDBDir # Path to Plex's Databases directory
[string] $PlexCache # Path to the PhotoTranscoder directory [string] $PlexCache # Path to the PhotoTranscoder directory
@ -16,8 +16,8 @@ class PlexDBRepair {
[string] $Version # Current script version [string] $Version # Current script version
[bool] $IsError # Whether we're currently in an error state [bool] $IsError # Whether we're currently in an error state
PlexDBRepair($Arguments, $Version) { DBRepair($Arguments, $Version) {
$this.Options = [PlexDBRepairOptions]::new() $this.Options = [DBRepairOptions]::new()
$this.Version = $Version $this.Version = $Version
$this.IsError = $false $this.IsError = $false
$Commands = $this.PreprocessArgs($Arguments) $Commands = $this.PreprocessArgs($Arguments)
@ -42,8 +42,8 @@ class PlexDBRepair {
} }
Write-Host "`n" Write-Host "`n"
Write-Host " Plex Media Server Database Repair Utility (Windows $($OS.Major), Build $($OS.Build))" Write-Host " Database Repair Utility for Plex Media Server (Windows $($OS.Major), Build $($OS.Build))"
Write-Host " Version $($this.Version) " Write-Host " Version $($this.Version) "
Write-Host Write-Host
} }
@ -138,7 +138,7 @@ class PlexDBRepair {
$AppData = $this.GetAppDataDir() $AppData = $this.GetAppDataDir()
$Success = $this.GetPlexDBDir($AppData) -and $this.GetPlexSQL() -and $this.GetPhotoTranscoderDir($AppData) $Success = $this.GetPlexDBDir($AppData) -and $this.GetPlexSQL() -and $this.GetPhotoTranscoderDir($AppData)
if ($Success) { if ($Success) {
$this.LogFile = Join-Path $this.PlexDBDir -ChildPath "PlexDBRepair.log" $this.LogFile = Join-Path $this.PlexDBDir -ChildPath "DBRepair.log"
} }
return $Success return $Success
@ -841,14 +841,14 @@ class PlexDBRepair {
} }
# Contains miscellaneous options/state over the course of a session. # Contains miscellaneous options/state over the course of a session.
class PlexDBRepairOptions { class DBRepairOptions {
[bool] $Scripted # Whether we're running in scripted or interactive mode [bool] $Scripted # Whether we're running in scripted or interactive mode
[bool] $ShowMenu # Whether to show the menu after each command executes [bool] $ShowMenu # Whether to show the menu after each command executes
[bool] $IgnoreErrors # Whether to honor or ignore constraint errors on import [bool] $IgnoreErrors # Whether to honor or ignore constraint errors on import
[bool] $CanIgnore # Some errors can't be ignored (e.g. integrity_check) [bool] $CanIgnore # Some errors can't be ignored (e.g. integrity_check)
[int32] $CacheAge # The date cutoff for pruning PhotoTranscoder cached images [int32] $CacheAge # The date cutoff for pruning PhotoTranscoder cached images
PlexDBRepairOptions() { DBRepairOptions() {
$this.CacheAge = 30 $this.CacheAge = 30
$this.ShowMenu = $true $this.ShowMenu = $true
$this.Scripted = $false $this.Scripted = $false
@ -883,7 +883,7 @@ $InputEncodingSave = [console]::InputEncoding
$OutputEncodingSave = [console]::OutputEncoding $OutputEncodingSave = [console]::OutputEncoding
[console]::InputEncoding = [console]::OutputEncoding = New-Object System.Text.UTF8Encoding [console]::InputEncoding = [console]::OutputEncoding = New-Object System.Text.UTF8Encoding
[void]([PlexDBRepair]::new($args, $PlexDBRepairVersion)) [void]([DBRepair]::new($args, $DBRepairVersion))
[console]::OutputEncoding = $OutputEncodingSave [console]::OutputEncoding = $OutputEncodingSave
[console]::InputEncoding = $InputEncodingSave [console]::InputEncoding = $InputEncodingSave

View File

@ -1,4 +1,4 @@
# PlexDBRepair-Windows # DBRepair-Windows
DBRepair-Windows.ps1 (and DBRepair-Windows.bat) are scripts run from the command line, which have DBRepair-Windows.ps1 (and DBRepair-Windows.bat) are scripts run from the command line, which have
sufficient privilege to read/write the Plex databases in the sufficient privilege to read/write the Plex databases in the
@ -9,13 +9,13 @@ sufficient privilege to read/write the Plex databases in the
Currently, there are two separate Windows scripts, a batch script (.bat) and a PowerShell script Currently, there are two separate Windows scripts, a batch script (.bat) and a PowerShell script
(.ps1). The batch script is a one-shot, zero-input script that attempts automatic database (.ps1). The batch script is a one-shot, zero-input script that attempts automatic database
maintenance (repair/rebuild, check, and reindex). The PowerShell script is intended to align with maintenance (repair/rebuild, check, and reindex). The PowerShell script is intended to align with
PlexDBRepair.sh, offering command-name-based functionality that can either be scripted or DBRepair.sh, offering command-name-based functionality that can either be scripted or
interactive. interactive.
In the future, DBRepair-Windows.bat will be removed in favor of DBRepair-Windows.ps1. The batch In the future, DBRepair-Windows.bat will be removed in favor of DBRepair-Windows.ps1. The batch
file is currently kept as a backup while the PowerShell script continues to be expanded and file is currently kept as a backup while the PowerShell script continues to be expanded and
tested. If any unexpected issues arise with the PowerShell script, please open an tested. If any unexpected issues arise with the PowerShell script, please open an
[issue](https://github.com/ChuckPa/PlexDBRepair/issues) so it can be investigated. [issue](https://github.com/ChuckPa/DBRepair/issues) so it can be investigated.
## Functions provided ## Functions provided

View File

@ -1,9 +1,12 @@
# PlexDBRepair-Windows # DBRepair-Windows
Release notes for the Windows counterpart to DBRepair.sh (DBRepair-Windows.ps1) Release notes for the Windows counterpart to DBRepair.sh (DBRepair-Windows.ps1)
# Release Info # Release Info
v1.01.00
- Rename this tool to be compliant with Plex inc. Trademark Policy.
v1.00.02 v1.00.02
- Check whether PMS is running at more points in the process. - Check whether PMS is running at more points in the process.
- Don't remove temp files in scripted mode if the last operation failed. - Don't remove temp files in scripted mode if the last operation failed.