diff --git a/CONTROL/postinst b/CONTROL/postinst new file mode 100755 index 0000000..7b2adef --- /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 0000000..924be78 --- /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 8ee9a18..72b8eae 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]} {