#!/mod/bin/jimsh package require cgi source /mod/var/mongoose/lib/setup require rsv.class set dir /mod/var/backup puts "Content-Type: text/html" puts "" cgi_input #cgi_dump #set _cgi(restore_file) "backup-2011-Jul-05-19:22" 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 $file does not exist." exit } if {[catch { set fd [open $ffile r] } msg]} { puts "Error opening backup file. - $msg" exit } proc findhsvc {channel} { global rsvdb set hsvc [$rsvdb query " select hSvc from channel.TBL_SVC where szSvcName = '$channel' or szSvcname = '\025$channel' limit 1 "] if {[llength $hsvc] == 1} { return [lindex [lindex $hsvc 0] 1] } else { return 0 } } puts "Restoring scheduled events..." $rsvdb query {delete from TBL_RESERVATION} set fields [lsort [[rsv] vars]] set data [split [read $fd] "\n"] foreach line $data { 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} { set hsvc [$rsv fix_hsvc] if {$hsvc == 0} { puts " Cannot find channel, restore failed." set bad 1 } elseif {$hsvc != $ohsvc} { puts -nonewline " Service number has " puts "changed $ohsvc -> $hsvc, fixing." } else { puts " No change in channel service." } } if {!$bad} { $rsv insert } } puts "Restoring favourite channels..." $rsvdb query {delete from channel.TBL_FAV} 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] set hsvc [findhsvc $chan] 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 } close [open /tmp/.restartpending w] close $fd rsv cleanup