2011-07-05 22:59:34 +00:00
|
|
|
#!/mod/bin/jimsh
|
|
|
|
|
|
|
|
package require cgi
|
|
|
|
source /mod/var/mongoose/lib/setup
|
|
|
|
|
2011-09-07 18:07:06 +00:00
|
|
|
require rsv.class findhsvc system.class
|
2011-07-05 22:59:34 +00:00
|
|
|
|
|
|
|
set dir /mod/var/backup
|
|
|
|
|
|
|
|
puts "Content-Type: text/html"
|
|
|
|
puts ""
|
|
|
|
|
|
|
|
cgi_input
|
|
|
|
#cgi_dump
|
|
|
|
|
2011-07-09 20:12:33 +00:00
|
|
|
#set _cgi(restore_file) "backup-2011-Jul-09-20:37"
|
2011-07-05 22:59:34 +00:00
|
|
|
|
|
|
|
if {![dict exists $_cgi restore_file]} {
|
|
|
|
puts "No filename supplied."
|
|
|
|
exit
|
|
|
|
}
|
|
|
|
|
|
|
|
set file [file tail [dict get $_cgi restore_file]]
|
|
|
|
set ffile "/$dir/$file.rbk"
|
|
|
|
|
|
|
|
if {![file exists $ffile]} {
|
|
|
|
puts "Backup file <i>$file</i> does not exist."
|
|
|
|
exit
|
|
|
|
}
|
|
|
|
|
|
|
|
if {[catch { set fd [open $ffile r] } msg]} {
|
2011-09-14 16:58:11 +00:00
|
|
|
puts "Error opening <i>$file</i> - $msg"
|
2011-07-05 22:59:34 +00:00
|
|
|
exit
|
|
|
|
}
|
|
|
|
|
2011-09-14 16:58:11 +00:00
|
|
|
puts "Restoring scheduled events from <i>$file</i>..."
|
2011-07-05 22:59:34 +00:00
|
|
|
|
2011-07-09 20:12:33 +00:00
|
|
|
$rsvdb query {begin transaction;}
|
|
|
|
$rsvdb query {delete from TBL_RESERVATION;}
|
2011-07-07 22:33:19 +00:00
|
|
|
|
2011-07-05 22:59:34 +00:00
|
|
|
set fields [lsort [[rsv] vars]]
|
|
|
|
|
2011-07-07 22:33:19 +00:00
|
|
|
set data [split [read $fd] "\n"]
|
|
|
|
|
|
|
|
foreach line $data {
|
2011-07-05 22:59:34 +00:00
|
|
|
set vals [split $line "\t"]
|
|
|
|
if {[lindex $vals 0] ne "event"} { continue }
|
|
|
|
set vars {}
|
|
|
|
set i 0
|
|
|
|
foreach f $fields {
|
|
|
|
if {$f eq "aulEventToRecordInfo"} { continue }
|
|
|
|
incr i
|
|
|
|
lappend vars $f [lindex $vals $i]
|
|
|
|
}
|
|
|
|
|
|
|
|
set rsv [rsv new $vars]
|
|
|
|
|
|
|
|
# Need to fix up channel and CRID mappings in case something has
|
|
|
|
# changed during a channel scan.
|
|
|
|
|
|
|
|
puts " Restoring [$rsv name]"
|
|
|
|
|
|
|
|
set bad 0
|
|
|
|
# First, the service number
|
|
|
|
set ohsvc [$rsv get hsvc]
|
|
|
|
if {$ohsvc > 0} {
|
2011-07-07 22:33:19 +00:00
|
|
|
set hsvc [$rsv fix_hsvc]
|
2011-07-06 23:16:20 +00:00
|
|
|
if {$hsvc == 0} {
|
2011-07-05 22:59:34 +00:00
|
|
|
puts " Cannot find channel, restore failed."
|
|
|
|
set bad 1
|
2011-07-06 23:16:20 +00:00
|
|
|
} elseif {$hsvc != $ohsvc} {
|
|
|
|
puts -nonewline " Service number has "
|
|
|
|
puts "changed $ohsvc -> $hsvc, fixing."
|
2011-07-05 22:59:34 +00:00
|
|
|
} else {
|
2011-07-06 23:16:20 +00:00
|
|
|
puts " No change in channel service."
|
2011-07-05 22:59:34 +00:00
|
|
|
}
|
|
|
|
}
|
2011-07-07 22:33:19 +00:00
|
|
|
|
2011-09-14 16:58:11 +00:00
|
|
|
if {!$bad} {
|
|
|
|
if {[catch {$rsv insert pending 1} msg]} {
|
|
|
|
puts " Error inserting event, $msg"
|
|
|
|
}
|
|
|
|
}
|
2011-07-07 22:33:19 +00:00
|
|
|
}
|
|
|
|
|
2011-07-09 20:12:33 +00:00
|
|
|
$rsvdb query {commit transaction;}
|
|
|
|
|
2011-07-07 22:33:19 +00:00
|
|
|
puts "Restoring favourite channels..."
|
2011-07-09 20:12:33 +00:00
|
|
|
$rsvdb query {begin transaction;}
|
2011-07-07 22:33:19 +00:00
|
|
|
$rsvdb query {delete from channel.TBL_FAV}
|
|
|
|
|
2011-07-08 20:39:57 +00:00
|
|
|
set grp 0
|
2011-07-07 22:33:19 +00:00
|
|
|
foreach line $data {
|
|
|
|
set vals [split $line "\t"]
|
|
|
|
if {[lindex $vals 0] ne "fav"} { continue }
|
|
|
|
|
|
|
|
set group [lindex $vals 1]
|
|
|
|
set type [lindex $vals 2]
|
|
|
|
set chan [lindex $vals 3]
|
2011-09-03 23:26:54 +00:00
|
|
|
set hsvc [get_channel_attr $chan]
|
2011-07-07 22:33:19 +00:00
|
|
|
|
2011-07-08 20:39:57 +00:00
|
|
|
if {$grp != $group} {
|
|
|
|
set grp $group
|
|
|
|
puts " Group $grp"
|
|
|
|
}
|
|
|
|
|
2011-07-07 22:33:19 +00:00
|
|
|
puts " $chan"
|
|
|
|
|
|
|
|
if {!$hsvc} {
|
|
|
|
puts " Cannot map channel name to service."
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
set query "
|
|
|
|
insert into channel.TBL_FAV(hSvc, eFavGroup, eSvcType)
|
|
|
|
values($hsvc, $group, $type);
|
|
|
|
"
|
|
|
|
|
|
|
|
$rsvdb query $query
|
2011-07-05 22:59:34 +00:00
|
|
|
}
|
|
|
|
|
2011-07-09 20:12:33 +00:00
|
|
|
$rsvdb query {commit transaction;}
|
|
|
|
|
2011-09-05 22:23:29 +00:00
|
|
|
system restartpending
|
2011-07-07 22:33:19 +00:00
|
|
|
|
2011-07-05 22:59:34 +00:00
|
|
|
close $fd
|
|
|
|
rsv cleanup
|
|
|
|
|