webif/var/mongoose/cgi-bin/backup/backup.jim
hummypkg 2ab6f7caa2 0.12.0
git-svn-id: file:///root/webif/svn/humax/pkg/src/webif/trunk@1398 2a923420-c742-0410-a762-8d5b09965624
2013-02-09 22:46:15 +00:00

84 lines
1.6 KiB
Plaintext
Executable File

#!/mod/bin/jimsh
package require cgi
source /mod/webif/lib/setup
require rsv.class
set dir /mod/var/backup
httpheader
set now [clock seconds]
set file [file tail [cgi_get file \
[clock format $now -format "auto-%Y-%b-%d-%H:%M"]]]
if {[string match {auto-*} $file]} {
# Delete any automatic backups over 7 days old.
set mt $(15 * 86400)
foreach af [glob -nocomplain "$dir/auto-*"] {
set aft [file mtime $af]
set diff $($now - $aft)
if {$diff > $mt} {
puts "Removing $af"
file delete $af
}
}
}
set ffile "/$dir/$file.rbk"
if {[file exists $ffile]} {
puts "Backup file <i>$file</i> already exists."
exit
}
if {[catch { set fd [open $ffile w] } msg]} {
puts "Error creating backup file. - $msg"
exit
}
puts "Backing up scheduled recordings and events..."
set events [rsv list]
set fields [lsort [[rsv] vars]]
#puts $fd "# [join $fields "\t"]"
foreach event $events {
puts " Backing up scheduled event '[$event name]'"
puts -nonewline $fd "event\t"
foreach f $fields {
if {$f eq "aulEventToRecordInfo"} { continue }
puts -nonewline $fd "[$event get $f]\t"
}
puts $fd ""
}
puts "Done."
puts "Backing up channel favourites..."
set grp 0
foreach res [$rsvdb query {
select eFavGroup,
TBL_FAV.eSvcType,
substr(szSvcName, 2) as szSvcName,
favIdx
from TBL_FAV join TBL_SVC using (hSvc)
order by eFavGroup, favIdx
}] {
if {$res(eFavGroup) != $grp} {
set grp $res(eFavGroup)
puts " Group $grp"
}
puts " $res(szSvcName)"
puts $fd "fav\t$res(eFavGroup)\t$res(eSvcType)\t$res(szSvcName)\t$res(favIdx)"
}
puts "Done."
close $fd
rsv cleanup