From 303cde633d30a57fd069bfa08d3b1e81711572d7 Mon Sep 17 00:00:00 2001 From: ChuckPa Date: Wed, 9 Nov 2022 21:33:07 -0500 Subject: [PATCH] Timestamp changed, Add Undo to new code 1. To increase portability, changed the ':' in timestamo to '.' (MacOS problems) 2. Completed adding WriteLog and logic to support UNDO for importing Viewstate --- DBRepair.sh | 41 ++++++++++++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 9 deletions(-) diff --git a/DBRepair.sh b/DBRepair.sh index 8965325..8423463 100755 --- a/DBRepair.sh +++ b/DBRepair.sh @@ -548,7 +548,7 @@ do [ "$Choice" -eq 0 ] && echo " " && echo "'$Input' - Is invalid. Try again" # Update timestamp - TimeStamp="$(date "+%Y-%m-%d_%H:%M:%S")" + TimeStamp="$(date "+%Y-%m-%d_%H.%M.%S")" done # Spacing for legibility @@ -1068,18 +1068,34 @@ do continue fi + WriteLog "Import - Attempting to import watch history from '$Input' " + # Confirm our databases are intact if ! CheckDatabases; then Output "Error: PMS databases are damaged. Repair needed. Refusing to import." + WriteLog "Import - Verify main database - FAIL" continue fi # Check the given database if ! CheckDB "$Input"; then Output "Error: Given database is damaged. Repair needed. Database not trusted. Refusing to import." + WriteLog "Import - Verify '$Input' - FAIL" continue fi + # Make a backup + Output "Backing up databases" + if ! MakeBackups "Import "; then + Output "Error making backups. Cannot continue." + WriteLog "Import - MakeBackups - FAIL" + Fail=1 + continue + else + WriteLog "Import - MakeBackups - PASS" + 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" @@ -1101,17 +1117,24 @@ do # 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" + if ! CheckDB $CPPL.db ; then + + Output "Error $Result during import. Import corrupted database." + Output " Undoing viewstate import." + + RestoreSaved "$LastTimestamp" + WriteLog "Import - Import: $Input - FAIL" continue fi + # We were successful + Output "Viewstate import successful." + WriteLog "Import - Import: $Input - PASS" + + # We were successful + SetLast "Import" "$TimeStamp" + + # 8. - Show Logfile elif [ $Choice -eq 8 ]; then