[mythtv-users] easiest way to rename a myth host (was: turning things over - migrate to new master backend)

Craig Sanders cas at taz.net.au
Mon Jan 5 02:26:21 UTC 2009


On Mon, Nov 17, 2008 at 08:05:25PM -0500, Michael T. Dean wrote:
> On 11/17/2008 08:01 AM, Stefan G. Weichinger wrote:
> > What procedure would you recommend?
> >
> > Migrate the backend to the new hardware by following this:
> >
> > http://www.mythtv.org/docs/mythtv-HOWTO-23.html#ss23.7
> 
> I'd recommend
> http://www.mythtv.org/wiki/index.php/Database_Backup_and_Restore .
> The scripts can do backup and restore, and support changing hostname
> without using the "partial" restore described by the link above
> (though they do support partial restores, too).

is there any real need to do a complete dump and restore to rename a
host? wouldn't it be simpler just to issue the appropriate mysql SQL
commands to update the relevant records?

i've been looking into how to do this today because i set up myth a
few months ago with the FQDN of my machine rather than just the short
hostname. it's no big deal, but it annoys me.  I'd like to rename the
hostname in myth from 'ganesh.taz.net.au' to just plain 'ganesh'.

AFAICT, all that's needded is:

1. edit /etc/hostname, change to just plain 'ganesh'.
2. run 'hostname ganesh'.
3. exit the frontend if it's running.
4. /etc/init.d/mythtv-backend stop
5. run the 'rename-myth-host.pl' script (see below)
6. /etc/init.d/mythtv-backend start


i haven't run it yet, in case there's something i'm missing about
how myth works or the database structure.

AFAIK, the only tables that need to be updated are: capturecard,
displayprofilegroups, inuseprograms, jobqueue, jumppoints,
keybindings, music_playlists, recorded, settings, storagegroup, and
weathersourcesettings (if mythweather is installed).  They all use the
same fieldname 'hostname' for the host's name.


anyone know if there is there any reason why following the above steps
would be a bad idea? or if there's anything i've missed in either the
steps or the script?


WARNING: the following script is completely untested and based on a
far-from-complete knowledge of myth's db structure. there is also no
error-checking or even sanity-checking of the command-line args. RUN AT
YOUR OWN RISK.

---cut here--- rename-myth-host.pl ---cut here---
#! /usr/bin/perl -w

# rename-myth-host.pl
#
# rename a mythtv hostname in mysql.
#
# (C) Copyright Craig Sanders <cas at taz.net.au> 2009
#
# This script is licensed under the terms of the GNU General Public
# License.

use strict;
use DBI;

# get command-line args w/. defaults
my $old = shift || 'ganesh.taz.net.au';
my $new = shift || 'ganesh';

# set up mysql connection:
my ($dbname, $dbhost, $dsn, $dbuser, $dbpass, %dbattr, $dbh) ;

$dbname     = 'mythconverg';
$dbhost     = 'localhost';
$dsn        = "DBI:mysql:database=$dbname;host=$dbhost";
$dbuser     = 'XXXXXXXXXX';
$dbpass     = 'XXXXXXXXXX';
%dbattr     = ();

$dbh = DBI->connect_cached($dsn,$dbuser,$dbpass,\%dbattr) or die $DBI::errstr;


# list of tables to update
my @tables = qw(capturecard displayprofilegroups inuseprograms jobqueue
                jumppoints keybindings music_playlists recorded settings
                storagegroup weathersourcesettings) ;

# update the tables, renaming every matching instance of the hostname field in each table.
foreach my $table (@tables) {
    my $sth = $dbh->prepare('UPDATE ' . $table . ' SET hostname = ? where hostname = ?');
    $sth->execute($old,$new);
    $sth->finish();
};

$dbh->disconnect();
---cut here--- rename-myth-host.pl ---cut here---


craig

-- 
craig sanders <cas at taz.net.au>

BOFH excuse #217:

The MGs ran out of gas.


More information about the mythtv-users mailing list