Import viewstate (watch history) from another database.

Viewstate import - Development complete

Developer initial testing complete.
1.  Copy DB from Syno to Linux workstation
2.  Setup empty PMS on Linux workstation
3.  Add library section
4.  Observe media all unwatched
5.  import the DS418's database 
6.  Verify on Linux workstation -- all titles now marked played
This commit is contained in:
ChuckPa 2022-11-07 18:52:12 -05:00
parent d967c08e2f
commit ba4474ed06
No known key found for this signature in database
GPG Key ID: 3CE28A0F6BC31B5B

View File

@ -338,7 +338,7 @@ HostConfig() {
cat override.conf local.conf *.conf 2>/dev/null | grep "APPLICATION_SUPPORT_DIR" | head -1)" cat override.conf local.conf *.conf 2>/dev/null | grep "APPLICATION_SUPPORT_DIR" | head -1)"
if [ "$NewSuppDir" != "" ]; then if [ "$NewSuppDir" != "" ]; then
NewSuppDir="$(sed -e 's/.*_DIR=//' | tr -d '"' | tr -d "'")" NewSuppDir="$(echo $NewSuppDir | sed -e 's/.*_DIR=//' | tr -d '"' | tr -d "'")"
if [ -d "$NewSuppDir" ]; then if [ -d "$NewSuppDir" ]; then
AppSuppDir="$NewSuppDir" AppSuppDir="$NewSuppDir"
@ -520,8 +520,9 @@ do
echo " 4. Attempt database repair" echo " 4. Attempt database repair"
echo " 5. Replace current database with newest usable backup copy" echo " 5. Replace current database with newest usable backup copy"
echo " 6. Undo last successful action (Vacuum, Reindex, Repair, or Replace)" echo " 6. Undo last successful action (Vacuum, Reindex, Repair, or Replace)"
echo " 7. Show logfile" echo " 7. Import Viewstate / Watch history from another PMS database"
echo " 8. Exit" echo " 8. Show logfile"
echo " 9. Exit"
echo " " echo " "
echo -n "Enter choice: " echo -n "Enter choice: "
if [ "$1" != "" ]; then if [ "$1" != "" ]; then
@ -542,6 +543,8 @@ do
[ "$Input" = "6" ] && Choice=6 [ "$Input" = "6" ] && Choice=6
[ "$Input" = "7" ] && Choice=7 [ "$Input" = "7" ] && Choice=7
[ "$Input" = "8" ] && Choice=8 [ "$Input" = "8" ] && Choice=8
[ "$Input" = "9" ] && Choice=9
[ "$Choice" -eq 0 ] && echo " " && echo "'$Input' - Is invalid. Try again" [ "$Choice" -eq 0 ] && echo " " && echo "'$Input' - Is invalid. Try again"
# Update timestamp # Update timestamp
@ -899,7 +902,7 @@ do
Dates=$(GetDates) Dates=$(GetDates)
# If no backups, error and exit # If no backups, error and exit
if [ "$Dates" == "" ] && [ $Damaged -eq 1 ]; then if [ "$Dates" = "" ] && [ $Damaged -eq 1 ]; then
Output "Database is damaged and no backups avaiable." Output "Database is damaged and no backups avaiable."
Output "Only available option is Repair." Output "Only available option is Repair."
WriteLog "Replace - Scan for usable candidates - FAIL" WriteLog "Replace - Scan for usable candidates - FAIL"
@ -1050,20 +1053,79 @@ do
WriteLog "Undo - Nothing to Undo." WriteLog "Undo - Nothing to Undo."
fi fi
# 7. - Show Logfile # 7. - Get Viewstate/Watch history from another DB and import
elif [ $Choice -eq 7 ]; then elif [ $Choice -eq 7 ]; then
echo -n "Pathname of database containing watch history to import: "
read Input
# Did we get something?
[ "$Input" = "" ] && continue
# Go see if it's a valid database
if [ ! -f "$Input" ]; then
Output "'$Input' does not exist."
continue
fi
# Confirm our databases are intact
if ! CheckDatabases; then
Output "Error: PMS databases are damaged. Repair needed. Refusing to import."
continue
fi
# Check the given database
if ! CheckDB "$Input" 2>1 >/dev/null; then
Output "Error: Given database is damaged. Repair needed. Database not trusted. Refusing to import."
continue
fi
# Export viewstate from DB
Output "Exporting Viewstate / Watch history"
echo ".dump metadata_item_settings" | "$PLEX_SQLITE" "$Input" | grep -v TABLE | grep -v INDEX > "$TMPDIR/Viewstate.sql-$TimeStamp"
# Make certain we got something usable
if [ $(wc -l "$TMPDIR/Viewstate.sql-$TimeStamp" | cut -d " " -f 1) -lt 1 ]; then
Output "No viewstates found to import."
continue
fi
# Make a working copy to import into
Output "Making backup copy of main database"
cp -p $CPPL.db "$TMPDIR/Viewstate.db-$TimeStamp"
# Import viewstates into working copy
Output "Importing Viewstate data"
"$PLEX_SQLITE" $CPPL.db < "$TMPDIR/Viewstate.sql-$TimeStamp"
Result=$?
# Make certain the resultant DB is OK
Output "Checking database following import"
if CheckDB $CPPL.db ; then
Output "Viewstate import successful."
WriteLog " Import - Import: $Input - PASS"
else
Output "Error $Result during import. Reverting to previous state."
Output " Viewstate history not imported."
mv -f "$TMPDIR/Viewstate.db-$TimeStamp" $CPPL.db
WriteLog " Import - Import: $Input - FAIL"
continue
fi
# 8. - Show Logfile
elif [ $Choice -eq 8 ]; then
echo ================================================================================== echo ==================================================================================
cat "$LOGFILE" cat "$LOGFILE"
echo ================================================================================== echo ==================================================================================
# 8. - Exit # 9. - Exit
elif [ $Choice -eq 8 ]; then elif [ $Choice -eq 9 ]; then
# Ask questions on graceful exit # Ask questions on graceful exit
if [ $Exit -eq 0 ]; then if [ $Exit -eq 0 ]; then
# Ask if the user wants to remove the DBTMP directory and all backups thus far # Ask if the user wants to remove the DBTMP directory and all backups thus far
if ConfirmYesNo "Ok to remove temporary work files for this session?" ; then if ConfirmYesNo "Ok to remove temporary databases/workfiles for this session?" ; then
# Here it goes # Here it goes
Output "Deleting all temporary work files." Output "Deleting all temporary work files."