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

From MythTV Official Wiki
Jump to: navigation, search
(Created page with "=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 manageme...")
 
m
(5 intermediate revisions by one other user not shown)
Line 1: Line 1:
 +
These scripts are to help restore customised channel logos, names, xmltv config, commercial skip, use of on air guide and channel numbering after a channel scan, based on serviceid. These script will restore the majority of your channel configuration and if a channel moves and it service id changes, you can easily update that channel's service id in the CSV file and restore the rest of the configuration.
 +
 +
It is also useful in validating a rescan has recaptured all your wanted channels, i.e. running the backup before and after a rescan and restore and performing a diff. I found some channels didn't reappear first scan.
 +
 +
Also this will hide all channels not listed in the csv file. The backup script will only output channels which are visible and have a different channel number to the service id - i.e. it thinks you've edited that one.
 +
 
=Backup Script=
 
=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.   
 
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.   
  
#!/bin/sh
+
{{Note box|MythTV no longer uses a 'mysql.txt' file, so this will not work on 0.26+.}}
 +
 
 +
{{Code box|backup_channels.sh|
 +
<pre>
 +
#!/bin/sh
 
   
 
   
. ~/.mythtv/mysql.txt
+
. ~/.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'
+
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'
 +
</pre>
 +
}}
  
 
==Example Output==
 
==Example Output==
Line 19: Line 31:
 
=Restore Script=
 
=Restore Script=
  
Expects to read a file called channels.csv in the current working directory.  
+
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.
 +
 
 +
{{Code box|restore_channels.py|
 +
<pre>
 +
#!/usr/bin/python
 +
 
 +
import csv
 +
import MySQLdb
 +
 
 +
conn = MySQLdb.connect (host = "localhost",
 +
                          user = "mythtv",
 +
                          passwd = "password",
 +
                          db = "mythconverg")
  
#!/usr/bin/python
+
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]))
 
   
 
   
import csv
+
cursor.close()
import MySQLdb
+
conn.close()
+
</pre>
conn = MySQLdb.connect (host = "localhost",
+
}}
                            user = "mythtv",
+
 
                            passwd = "password",
+
[[Category:Scripts]]
                            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 ()
 

Revision as of 15:09, 31 January 2013

These scripts are to help restore customised channel logos, names, xmltv config, commercial skip, use of on air guide and channel numbering after a channel scan, based on serviceid. These script will restore the majority of your channel configuration and if a channel moves and it service id changes, you can easily update that channel's service id in the CSV file and restore the rest of the configuration.

It is also useful in validating a rescan has recaptured all your wanted channels, i.e. running the backup before and after a rescan and restore and performing a diff. I found some channels didn't reappear first scan.

Also this will hide all channels not listed in the csv file. The backup script will only output channels which are visible and have a different channel number to the service id - i.e. it thinks you've edited that one.

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.


Important.png Note: MythTV no longer uses a 'mysql.txt' file, so this will not work on 0.26+.


Script.png backup_channels.sh

#!/bin/sh
 
. ~/.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

"channum","callsign","serviceid","name","default_authority","xmltvid","icon","commmethod","useonairguide"
"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.


Script.png restore_channels.py

#!/usr/bin/python

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()