#!/bin/sh

yesterday=`echo "print(os.date(\"%Y-%m-%d\",os.time()-24*60*60))" | /usr/bin/lua`

logdb=`uci get weathermon.process.logdb`

if [ -f "$logdb" ]; then

  dumpdir=`uci get weathermon.process.archive_dir`/`echo "print(os.date(\"%Y/%m/%d\",os.time()-22*60*60))" | /usr/bin/lua`

  mkdir -p $dumpdir

  /usr/bin/weather-filter $logdb dump-compacted $yesterday $dumpdir

  sqlite3 $logdb "delete from log where time_stamp<date('now','-2 day')"

fi