Difference between revisions of "Custom Channel Configuration Backup and Restore"

From MythTV Official Wiki
Jump to: navigation, search
(Restore Script)
Line 42: Line 42:
  cursor.close ()
  cursor.close ()
  conn.close ()
  conn.close ()

Revision as of 09:45, 31 January 2013

Backup Script

Run this script before your perform a channel rescan and redirect the output to channels.csv. You can edit this file for easier channel logo and name management.


. ~/.mythtv/mysql.txt

mysql -u $DBUserName --password=$DBPassword $DBName -B -e "select channum, callsign, serviceid, name, default_authority, xmltvid, icon, commmethod, useonairguide from channel where visible=1 and channum!=serviceid order by (channum+0),serviceid;" | sed 's/\t/","/g;s/^/"/;s/$/"/;s/\n//g'

Example Output

"101","BBC 1 Scotland","4220","BBC 1 Scotland","fp.bbc.co.uk","","bbc_one_scotland.jpg","-2","1"
"101","BBC 1 Scotland","6421","BBC 1 Scotland","fp.bbc.co.uk","","bbc_one_scotland.jpg","-2","0"
"102","BBC 2 Scotland","4284","BBC 2 Scotland","fp.bbc.co.uk","","bbc2_scotland.jpg","-2","1"
"102","BBC 2 Scotland","6422","BBC 2 Scotland","fp.bbc.co.uk","","bbc2_scotland.jpg","-2","0"

Restore Script

Expects to read a file called channels.csv in the current working directory. Change the 'password' in your connection string to match your mythconverg password.


import csv
import MySQLdb

conn = MySQLdb.connect (host = "localhost",
                           user = "mythtv",
                           passwd = "password",
                           db = "mythconverg")

cursor = conn.cursor()

cursor.execute("UPDATE channel SET visible=0")

data = csv.reader(file("channels.csv"))
for row in data:
	#CSV Format: "channum","callsign","serviceid","name","default_authority","xmltvid","icon","commmethod"
	cursor.execute("UPDATE channel SET visible=1, channum=%s, callsign=%s, name=%s, default_authority=%s, xmltvid=%s, icon=%s, commmethod=%s, useonairguide=%s WHERE serviceid=%s",(row[0],row[1],row[3],row[4],row[5],row[6],row[7],row[8],row[2]))

cursor.close ()
conn.close ()