Migrate MythTV Recordings to a New Server

Want to install MythTV onto a new system, or install things from scratch on the same system? The big problem is loosing all your recordings and data.

It not as simple as just copying your recording files over. You need to have the database information about each file for them to work.

It's fairly easy to transfer your important database information to a new server. Here's how.

Migrate your MythTV recordings in 3 easy steps:

  1. Backup the important database information from the old database
  2. Copy the files into the new install directory
  3. Restore the database information into the new database

Step 1 - Backup your existing data

I've seen a couple different ways to do this in the MythTV documentation, both of which seem a little awkward. I think I have a better way, which has worked fine for me once.

Basically what we need to do is export the information about the existing recordings, previous recordings, and future recordings. This data will be imported into an already setup database on the new system.

mysqldump -u mythtv -p -t mythconverg record recorded \ 
oldrecorded recordedprogram recordedrating \
recordedmarkup recordedseek > recordings.sql

That's all a single command that needs to be run on the command line. If you use a different database user, substitue your username in place of "mythtv" after the -u argument. If you use a different database name, replace mythconverg with your database name.

That command, after prompting for your database password, will export all the data you need to migrate into a file name recordings.sql. This is the file you will need to import on the new server when we get to that step. How to copy the file will be an exercise for you to figure out, since each situation may be different.

Step 2 - Copy your video files to the new MythTV recordings directory

Again, each situation may be different in terms of copying files over.

One tip is to find where you think they are going to be recorded, then start recording a show to see if a file shows up there. If a file shows up in that directory then you've got the right place. Copy all your video files over.

This may take a while if you are going between drives or over a network, but you can import the database records while files are copying. When I migrated to a new system, it took about 8 hours to copy all my recordings over the network.

Until everything is copied over, you will just get an error if you try to watch a recording that hasn't been copied yet if you go ahead and import the recording data.

Step 3 - Import the recording data into the new database

Start by copying the recordings.sql file to the target server if it's not already there. Then all we need to do is import it to the target database.

mysql -u mythtv -p mythconverg < recordings.sql

Provide your password, and the recording data will be imported.

Watch Your MythTV Recordings

That's it. If everything went as planned, all your recording will be in your new system as if nothing had changed.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

2 Easy steps instead of 3...

In step 1, instead of creating the recorded.sql file, you can send the output of the sql query directly into the new database by piping it into another mysql command line.

From the NEW server's command line do:

newserver # mysqldump -h oldserverIP -umythuser -pmythpass mythconverg \
record recorded oldrecorded recordedprogram recordedrating \
recordedmarkup recordedseek | \
mysql -umythuser -pmythpass mythconverg

Hope this helps. :)

--
Bill Arlofski

MySQL Pipe

Bill's correct. I presented it this way because in many cases, and mine in particular, you might not have access to both databases at the same time.

Thanks Bill, I appreciate your feedback.

moving among different versions

In case you're moving recordings to a different version of MythTV where the database layout has changed, you'll get an import error if the number of columns doesn't match.

You can work around that by adding the "-c" (--complete-insert) option to mysqldump when exporting the files. It'll leave the missing column(s) blank, but at least you'll be able to import the data.

Moving files

I found the smbget command useful for moving files between two recent versions of KnoppMyth (R5F1 and R5F27, I think.) Neither installation had ftp. Type 'smb' and hit 'TAB' to see a short list of the smb commands available on your machine. I used user mythtv, and the only prep I had to do was use smbpasswd to set that users smb password on the old machine. Then I executed the smbget command from the new machine. Over fast ethernet I moved about a G every two minutes or so. Of course, doing it over IDE would probably be faster, but that requires a screwdriver.

thanks!

Thanks for this information! It helped me a great deal. Here's my one piece of advice in case others encounter this problem. I attempted to transfer recordings from an existing mythtv installation to another--which had already made some recordings. When I tried to run "mysql" to import the old database into the new, I got the following error:

ERROR 1062 (23000) at line 24: Duplicate entry '18' for key 1

So, I added "-f" to the mysql command, to force the import (and ignore any errors). eg:

mysql -f -u mythtv -p mythconverg < recordings.sql

This error was still reported, but the rest of the import appeared to work. I suspect that one of my recordings (at entry 18) did not get imported, but that's ok.

Anyhow, thanks for this website. It's a great resource.

thanks and thanks

thanks for the guide, and then thanks for the -f option. i had a duplicate error and this allowed me to get past it.

migrating mysql data and recordings

A question about this process. I originally had Mythbuntu v8.04.1 installed (on a 500gb drive). Now I have v8.10 installed (on a 1tb drive). I believe I should be able to mount the 500gb drive and copy the recordings from the old drive to the new drive. I am not sure about the db though. Will I have any problem opening the mythconverg db on the old drive and the new drive? Will my current install get confused and hit the wrong copy of mythconverg? My GUESS is that it should be ok but I'd REALLY like to NOT mess up my system now that it's running ok. I don't even actually know WHERE mythconverg is located on the drive... I dug around for it early on, but then it seemed it wasn't that important to know so moved on. I'm pretty new to Linux/Myth... so if I'm missing something obvious, feel free to point it out. Thanks.

One other thing

I went from one machine to another (different hostname). I had to update the hostname field of the recorded table in order to see my previously-recorded files. I ran mysql -umythtv -psecretPassword mythconverg; and executed: mysql> update recorded set hostname='newhostname' where hostname='oldhostname'; After that, I could see my old files.

How does mythtv know where the old recordings are?

Thanks for your helpful posting. I had a question: in my old mythtv, the recordings are in a directory /video while in the new mythdora 10.21 upgraded machine, recordings are saved in /storage/recordings. If I move my old files to the upgraded mythtv, does the new database look for the files in /video or in /storage/recordings? I.e., does the database record the location of the files? If so, how do I tell the updated mythtv to look for the old files?

Mythtv settings

Hey, Can I use this method for migrating mythtv-setup database (which is the settings table) too? i used mysqldump -u mythtv -p -t mythconverg settings > settings.sql to put the settings onto a file.... and then used mysql -u mythtv -p mythconverg < settings.sql when i run select * from settings query i can see the settings in the database. but when i run > mythtv-setup .... it still shows the old settings.... is this the right method to do it? Any help will be highly appreciated. Thank You Prerak Mehta

No, the MythTV database does

No, the MythTV database does not store the directory location for each recorded file. It just stores the filename, and then each time you play the video it checks all the recording locations you have defined. So you just need to move/copy your old files to (one of) the new recording locations, and then update the database like the article shows.

If your old database computer is dead

My old mythtv backend computer had a major hardware failure and would not boot. So I didn't have access to the old database to do a normal dump, just the database files on the old harddrive. This is what I ended up doing to import the tables. Note that you must have the same major MySQL version on both machines (like MySQL 5.x).

First I stopped mythbackend and mysql (these are commands for Debian squeeze, your system may be slightly different):

# /etc/init.d/mythtv-backend stop
# /etc/init.d/mysql stop

Then I temporarily renamed the new mythtv database, copied my old one in it's place, and fixed the file permissions to be the same as the new database files:

# cd /var/lib/mysql/
# mv mythconverg mythconverg-new
# cp -a /mnt/old-drive/var/lib/mysql/mythconverg .
# chown -R mythtv:mythtv mythconverg

Next I restarted mysql and did the database dump (now using the old database):

# /etc/init.d/mysql start
# mysqldump -u mythtv -p -t mythconverg record recorded \
oldrecorded recordedprogram recordedrating \
recordedmarkup recordedseek > ~/recordings.sql

Then I switched back over to the new database:

# /etc/init.d/mysql stop
# mv mythconverg mythconverg-old
# mv mythconverg-new mythconverg

And imported the setting into the new database:

# /etc/init.d/mysql start
# mysql -u mythtv -p mythconverg < ~/recordings.sql

Finally, I brought mythtv back up:

# /etc/init.d/mythtv-backend start
$ mythfrontend

And watched my old recordings. Yay!