From a189b524ab4ec5a65ee4226a8a68845b3517b76c Mon Sep 17 00:00:00 2001 From: hummypkg Date: Fri, 9 Dec 2011 10:35:21 +0000 Subject: [PATCH] automatic daily schedule backups git-svn-id: file:///root/webif/svn/humax/pkg/src/webif/trunk@551 2a923420-c742-0410-a762-8d5b09965624 --- CONTROL/postinst | 17 +++++++++++++++++ CONTROL/prerm | 10 ++++++++++ var/mongoose/cgi-bin/backup/backup.jim | 19 +++++++++++++++---- 3 files changed, 42 insertions(+), 4 deletions(-) create mode 100755 CONTROL/postinst create mode 100755 CONTROL/prerm diff --git a/CONTROL/postinst b/CONTROL/postinst new file mode 100755 index 00000000..7b2adef1 --- /dev/null +++ b/CONTROL/postinst @@ -0,0 +1,17 @@ +#!/bin/sh + +export tmpf=/tmp/cronf.$$ + +# Add anacron jobs + +ana=$PKG_ROOT/etc/anacrontab +grep -v 'backup/backup.jim' $ana > $tmpf +( + cat $tmpf + echo "1 30 /mod/var/mongoose/cgi-bin/backup/backup.jim" +) > $ana + +$PKG_ROOT/etc/init.d/S02anacron start < /dev/null > /dev/null 2>&1 & + +exit 0 + diff --git a/CONTROL/prerm b/CONTROL/prerm new file mode 100755 index 00000000..924be78b --- /dev/null +++ b/CONTROL/prerm @@ -0,0 +1,10 @@ +#!/bin/sh + +export tmpf=/tmp/cronf.$$ + +ana=/mod/etc/anacrontab +grep -v 'backup/backup.jim' $ana > $tmpf +cp $tmpf $ana + +exit 0 + diff --git a/var/mongoose/cgi-bin/backup/backup.jim b/var/mongoose/cgi-bin/backup/backup.jim index 8ee9a18f..72b8eaef 100755 --- a/var/mongoose/cgi-bin/backup/backup.jim +++ b/var/mongoose/cgi-bin/backup/backup.jim @@ -13,12 +13,23 @@ puts "" cgi_input #cgi_dump -if {![dict exists $_cgi file]} { - puts "No filename supplied." - exit +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 $(7 * 3600) + 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 file [file tail [dict get $_cgi file]] set ffile "/$dir/$file.rbk" if {[file exists $ffile]} {