Backend install has missing link needed for optimize_mythdb

For discussion of topics specific to MythTV on Raspberry Pi devices
Post Reply
User avatar
jfabernathy
Senior
Posts: 577
Joined: Wed Feb 18, 2015 2:37 pm
Location: Raleigh, NC
United States of America

Backend install has missing link needed for optimize_mythdb

Post by jfabernathy »

In a recent install of mythtv using the pi-utils (https://github.com/MikeB2013/pi-utils):
1. pi-setup_mythtv_31.sh
2. pi-mythbackend-helper.sh

I was completing the setup by adding a cronjob to run the contributor script 'optimize_mythdb.pl'. I've used this script on my Ubuntu based backend without issue. It seems that the standard Ubuntu install for mythtv includes a link in /root/.mythtv/ for config.xml to the main file in /etc/mythtv/config.xml.

The pi-mythbackend-helper.sh doesn't include this link and my first run of the optimize_mythdb failed with this error:

Code: Select all

/etc/cron.daily/optimize_mythdb:
No backends found.  Please copy config.xml from a working MythTV installation to /root/.mythtv.
Compilation failed in require at /usr/share/doc/mythtv-backend/contrib/maintenance/optimize_mythdb.pl line 15.
BEGIN failed--compilation aborted at /usr/share/doc/mythtv-backend/contrib/maintenance/optimize_mythdb.pl line 15.
I fixed it by adding the link.

Code: Select all

sudo ln -s /etc/mythtv/config.xml /root/.mythtv/config.xml
It might be worth adding that link to the pi-mythbackend-helper.sh, and maybe the daily optimize_mythdb cron.daily job??
I know I always have both the daily database backup and optimize jobs included in any backend I run.
User avatar
jfabernathy
Senior
Posts: 577
Joined: Wed Feb 18, 2015 2:37 pm
Location: Raleigh, NC
United States of America

Re: Backend install has missing link needed for optimize_mythdb

Post by jfabernathy »

another potential fix would be to NOT do the link /root/.mythtv/config.xml and create the cron.daily job similar to the newest v31 mythtv-database cron.daily job that has the logic to run as user mythtv, then the link is not needed??
User avatar
jfabernathy
Senior
Posts: 577
Joined: Wed Feb 18, 2015 2:37 pm
Location: Raleigh, NC
United States of America

Re: Backend install has missing link needed for optimize_mythdb

Post by jfabernathy »

I've opted for fixing the cron.daily job and NOT including the link for /root/.mythtv/config.xml.

For what it's worth my script (which I probably stole from somebody) in cron.daily called optimize-mythdb is:

Code: Select all

#!/bin/sh

set -e -u

OPT_MYTHDB='/usr/share/doc/mythtv-backend/contrib/maintenance/optimize_mythdb.pl' 
LOG='/var/log/mythtv/optimize_mythdb.log'
USER="mythtv"

if [ -z "${USER:-}" ]; then
   CMDPREFIX=""
else
   CMDPREFIX="sudo -H -u $USER"
fi

# Debug:
/usr/bin/logger -p daemon.info -i -t${0##*/} "Debug: cron.daily optimize_mythdb started."

echo "Started ${OPT_MYTHDB} on `date`" >> ${LOG}
$CMDPREFIX ${OPT_MYTHDB} >> ${LOG}
echo "Finished ${OPT_MYTHDB} on `date`" >> ${LOG}

# Debug:
/usr/bin/logger -p daemon.info -i -t${0##*/} "Debug: cron.daily optimize_mythdb ended."
now="$(date)"
echo "rpi-mythtv-nas optimize_mythdb has been run on $now" | mail -s "optimized_mythdb" my-email.address@gmail.com

User avatar
Steve Goodey
Moderator
Posts: 220
Joined: Fri Feb 07, 2014 6:30 pm
Location: Colchester, England
Great Britain

Re: Backend install has missing link needed for optimize_mythdb

Post by Steve Goodey »

Thanks very much for sharing this script.

For anyone else intending to use this don't do what Mr. Stupid here did. I printed out a copy of the post to make typing in easier, not realising the code box had a scroll bar, so only ending up with half the script. :o

By the way, in the script there are two instances of the variable 'date', I believe they should be replaced by $(date).

Regards, Steve.
Don't forget the Wiki.
User avatar
jfabernathy
Senior
Posts: 577
Joined: Wed Feb 18, 2015 2:37 pm
Location: Raleigh, NC
United States of America

Re: Backend install has missing link needed for optimize_mythdb

Post by jfabernathy »

Steve Goodey wrote:
Wed Feb 03, 2021 10:55 am
Thanks very much for sharing this script.

For anyone else intending to use this don't do what Mr. Stupid here did. I printed out a copy of the post to make typing in easier, not realising the code box had a scroll bar, so only ending up with half the script. :o

By the way, in the script there are two instances of the variable 'date', I believe they should be replaced by $(date).

Regards, Steve.
Steve, I know next to nothing about scripting, but I just checked my main backend running on Ubuntu and it has this as the last line in the log file:

Code: Select all

Finished /usr/share/doc/mythtv-backend/contrib/maintenance/optimize_mythdb.pl on Wed 03 Feb 2021 05:41:02 AM EST
and that line is produced by the following line in the script on exit:

Code: Select all

echo "Finished ${OPT_MYTHDB} on `date`" >> ${LOG}
User avatar
Steve Goodey
Moderator
Posts: 220
Joined: Fri Feb 07, 2014 6:30 pm
Location: Colchester, England
Great Britain

Re: Backend install has missing link needed for optimize_mythdb

Post by Steve Goodey »

Well that's weird, running Xubuntu, before I made that change the log showed:-
Finished /usr/share/doc/mythtv-backend/contrib/maintenance/optimize_mythdb.pl on 'date'
Changing it to $(date) gives:-
Finished /usr/share/doc/mythtv-backend/contrib/maintenance/optimize_mythdb.pl on Wed 3 Feb 07:37:17 GMT 2021
:roll:

Steve.
Don't forget the Wiki.
gedakc
Junior
Posts: 97
Joined: Fri Jul 18, 2014 1:28 am
Canada

Re: Backend install has missing link needed for optimize_mythdb

Post by gedakc »

In shell scripts there is a difference between an apostrophe (') the key immediately to the left of the Enter key on a US keyboard, and the back tick (`) the key immediately above the tab key on a US keyboard.

The text between back ticks (`) is interpreted to be a command.

For example with back ticks (`):

Code: Select all

#!/bin/bash
echo "Current date is `date`"
Should display:

Code: Select all

Current date is Wed Feb  3 10:08:13 MST 2021
Whereas an apostrophe (') should display:

Code: Select all

Current date is 'date'
'Hope that helps.

EDIT:

Note that using

Code: Select all

"$(date)"
will also treat the text as a command similar using back ticks, e.g.

Code: Select all

"`date`"
User avatar
Steve Goodey
Moderator
Posts: 220
Joined: Fri Feb 07, 2014 6:30 pm
Location: Colchester, England
Great Britain

Re: Backend install has missing link needed for optimize_mythdb

Post by Steve Goodey »

'Hope that helps.
It certainly does, looking closer at jfabernathy's code snippet I can now see the difference. Must concentrate more. :lol:

Thanks very much.
Don't forget the Wiki.
Post Reply