Useful Utilities for Managing MythTV and Mythbuntu


MythTV is an excellent PVR, but on occasions thing can go wrong and it is useful to have a ready arsenal of utilities which you can run when things might go wrong!

Before your begin:

If you are not confident that a script won’t damage your database, it’s recommended you backup your database using the Backup and Restore feature in the Mythbuntu Control Centre

MythTV maintenance scripts are located in /usr/share/doc/mythtv-backend/contrib/maintenance

optimize_mythdb.pl

This a perl script to run MYSQL utilities Repair and Optimize on each table in your MythTV database. Whilst it is recommended to run this regularly from a Cron job (scheduled task), I prefer to run this manually so I can see what is happening.

From terminal, cd to the maintenance scripts directory and enter:

./optimize_mythdb.pl

The script will analyise and repair/ optimise any damaged database tables.

Find_orphans.py

This is a Python script which shows recordings with missing files or files with missing recordings. This is very useful if you are access your MythTV backend vis a DLNA enabled device like a TV as it will show all recordings listed in the database even if the files are no longer present on the MythTV backend. You can then use the script to clean things up.

By default it is not in the MythTV maintenance directory, but it can be easily added by creating a file of the same name in the maintenance directory and pasting in the code from the wiki.

To make the script executable enter:

chmod 755 Find_orphans.py

Now run the script by entering:

./Find_orphans.py

Below is an example of what you may see

At the bottom of the screen you will be given a menu of options:

Note: The menu will only display relevant options dependent on the problems it detects so may not look exactly like the screen shot.

In the above example I have orphaned recording entries, so I will select option 1 to delete the entries.

The script then lists the entries which will be deleted and then asks for confirmation (yes or no) before proceeding. Whilst the process appears to happen quickly, you will probably find that the orphaned entries are still being listed. This is because the listings are still being deleted in the background. Eventually they will disappear from the list.

Once finished press Ctrl-c to exit.

Once completed, I run the optimize_mythdv.pl script to make sure the database is optimised.

In my opinion this is a fantastic script and should be included by default in MythTV. In fact I would go further and say that it should be accessible from the Mythbuntu Control Centre menu, or MythTV Backend Setup.

MythTV Version Updates

Whilst not a command line utility, the Mythbuntu Control Centre is a very useful way for ensuring that your system us protected through backups, configured correctly and MythTV is up to date.

With Mythbuntu 12.04 being a LTS release there are by default no updates to MythTV 0.25 which ships with it. However, should you wish to receive the latest MythTV updates and fixes you can enable later MythTV repositories through the control centre.

Before you start the upgrade, make sure that /etc/mythtv/config.xml is not empty!

If it is your upgrade will fail and MythTV will be left in an unusable state. This is a know bug.

The contents of the file should look something like the example below:

<Configuration>

  <UPnP>

    <MythFrontend>

      <DefaultBackend>

        <!–

Set the <LocalHostName> hostname override below only if you want to use

something other than the machine’s real hostname for identifying settings

in the database.  This is useful if your hostname changes often, as

otherwise you’ll need to reconfigure mythtv every time.

NO TWO HOSTS MAY USE THE SAME VALUE

–>

        <DBHostName>localhost</DBHostName>

        <DBUserName>mythtv</DBUserName>

        <DBPassword>?????????</DBPassword>

        <DBName>mythconverg</DBName>

        <DBPort>3306</DBPort>

      </DefaultBackend>

    </MythFrontend>

  </UPnP>

</Configuration>

 

and should match the contents in /etc/mythtv/mysql.txt.

If empty this file will need to be corrected before proceeding with the upgrade.

Access the Mythbuntu Control Centre by selecting Applications> System > Mythbuntu Control Centre and select Repositories from the menu.

Check the box called Activate MythTV Updates repository

and select which version of MythTV you wish to upgrade to e.g. 0.27. If the version is not listed, press the Refresh button to the right of the version number.

Also check the box Activate Mythbuntu Update repositories.

Click Apply and then Quit the Mythbuntu Control Centre.

From Terminal (or from update manager) update Mythbuntu by entering:

sudo apt-get update

followed by

sudo apt-get upgrade

confirming that you wish to upgrade.

Once the upgrade has completed MythTV will be on the new version.

Advertisements

4 thoughts on “Useful Utilities for Managing MythTV and Mythbuntu

  1. The Find_orphans.py script isn’t working for me. I receive the following errors:
    =======================
    ./Find_orphans.py: 1: ./Find_orphans.py: #!/usr/bin/env: not found
    from: can’t read /var/mail/MythTV
    from: can’t read /var/mail/socket
    ./Find_orphans.py: 6: ./Find_orphans.py: import: not found
    ./Find_orphans.py: 7: ./Find_orphans.py: import: not found
    ./Find_orphans.py: 9: ./Find_orphans.py: Syntax error: “(” unexpected
    =======================

    Any ideas? Any help would be much appreciated!

    Thanks!

  2. I’m running mythtv-0.27.0.20140121_7 in a FreeNAS Jail.

    Running find_orphans.py (from https://github.com/wagnerrp/mythtv-scripts/blob/master/python/find_orphans.py) seems to work fine, until it gets to the lettter “E” where I get an error:

    mythtv: Earth’s Natural Wonders – Wonders of Water 1111_20151112020000.mpg
    mythtv: Earth’s Natural Wonders – Living Wonders 1111_20151119020000.mpg
    Traceback (most recent call last):
    File “/usr/local/bin/find_orphans.py”, line 231, in
    main()
    File “/usr/local/bin/find_orphans.py”, line 170, in main
    printrecs(“Recordings with missing files”, recs)
    File “/usr/local/bin/find_orphans.py”, line 44, in printrecs
    rec.pprint()
    File “/usr/local/bin/find_orphans.py”, line 39, in pprint
    print u’ {0:28}’.format(name,self.basename)
    UnicodeDecodeError: ‘ascii’ codec can’t decode byte 0xc3 in position 19: ordinal not in range(128)

    Can anyone tell me how to fix the script?

    Alternatively, can anyone tell me how to find the row in the recorded table that it is causing the error; I’d gladly modify the text.

    Thank you.

    nello

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s