Restore owner and permissions

This commit is contained in:
Chuck 2023-03-16 02:02:10 -04:00 committed by ChuckPa
commit b15d5a55c8
No known key found for this signature in database
GPG Key ID: 3CE28A0F6BC31B5B

View File

@ -2,12 +2,12 @@
######################################################################### #########################################################################
# Plex Media Server database check and repair utility script. # # Plex Media Server database check and repair utility script. #
# Maintainer: ChuckPa # # Maintainer: ChuckPa #
# Version: v1.0.0 # # Version: v1.0.1 #
# Date: 13-Mar-2023 # # Date: 16-Mar-2023 #
######################################################################### #########################################################################
# Version for display purposes # Version for display purposes
Version="v1.0.0" Version="v1.0.1"
# Flag when temp files are to be retained # Flag when temp files are to be retained
Retain=0 Retain=0
@ -301,6 +301,7 @@ HostConfig() {
PIDOF="pidof" PIDOF="pidof"
STATFMT="-c" STATFMT="-c"
STATBYTES="%s" STATBYTES="%s"
STATPERMS="%a"
# Synology (DSM 7) # Synology (DSM 7)
if [ -d /var/packages/PlexMediaServer ] && \ if [ -d /var/packages/PlexMediaServer ] && \
@ -563,6 +564,7 @@ HostConfig() {
PIDOF="pgrep" PIDOF="pgrep"
STATFMT="-f" STATFMT="-f"
STATBYTES="%z" STATBYTES="%z"
STATPERMS="%A"
# make the TMP directory in advance to store plexmediaserver.pid # make the TMP directory in advance to store plexmediaserver.pid
mkdir -p "$DBDIR/dbtmp" mkdir -p "$DBDIR/dbtmp"
@ -724,9 +726,6 @@ DoRepair() {
Output "Exporting current databases using timestamp: $TimeStamp" Output "Exporting current databases using timestamp: $TimeStamp"
Fail=0 Fail=0
# Get the owning UID/GID before we proceed so we can restore
Owner="$(stat $STATFMT '%u:%g' $CPPL.db)"
# Attempt to export main db to SQL file (Step 1) # Attempt to export main db to SQL file (Step 1)
Output "Exporting Main DB" Output "Exporting Main DB"
"$PLEX_SQLITE" $CPPL.db ".output '$TMPDIR/library.plexapp.sql-$TimeStamp'" .dump "$PLEX_SQLITE" $CPPL.db ".output '$TMPDIR/library.plexapp.sql-$TimeStamp'" .dump
@ -843,6 +842,7 @@ DoRepair() {
# Set ownership on new files # Set ownership on new files
chown $Owner $CPPL.db $CPPL.blobs.db chown $Owner $CPPL.db $CPPL.blobs.db
chmod $Perms $CPPL.db $CPPL.blobs.db
# We didn't fail, set CheckedDB status true (passed above checks) # We didn't fail, set CheckedDB status true (passed above checks)
CheckedDB=1 CheckedDB=1
@ -1203,6 +1203,10 @@ DoImport(){
Output "Viewstate import successful." Output "Viewstate import successful."
WriteLog "Import - Import: $Input - PASS" WriteLog "Import - Import: $Input - PASS"
# Set owner and permissions
chown $Owner $CPPL.db
chmod $Perms $CPPL.db
# We were successful # We were successful
SetLast "Import" "$TimeStamp" SetLast "Import" "$TimeStamp"
return 0 return 0
@ -1350,6 +1354,7 @@ cd "$DBDIR"
# Get the owning UID/GID before we proceed so we can restore # Get the owning UID/GID before we proceed so we can restore
Owner="$(stat $STATFMT '%u:%g' $CPPL.db)" Owner="$(stat $STATFMT '%u:%g' $CPPL.db)"
Perms="$(stat $STATFMT $STATPERMS $CPPL.db)"
# Sanity check, We are either owner of the DB or root # Sanity check, We are either owner of the DB or root
if [ ! -w $CPPL.db ]; then if [ ! -w $CPPL.db ]; then