mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-03-12 16:46:35 +00:00
maintainDB.cgi: add maintenance script
git-svn-id: https://svn.fhem.de/fhem/trunk@14770 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
a96d632d5b
commit
f1f6e56362
25
fhem/contrib/statistics/2017/maintainDB.cgi
Executable file
25
fhem/contrib/statistics/2017/maintainDB.cgi
Executable file
@ -0,0 +1,25 @@
|
||||
#!/usr/bin/perl -w
|
||||
# $Id$
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use DBI;
|
||||
|
||||
my $limit = "datetime('now', '-13 months')";
|
||||
|
||||
# directory cointains databases
|
||||
my $datadir = "./data";
|
||||
my $dbf = "$datadir/fhem_statistics_2017.sqlite";
|
||||
my $dsn = "dbi:SQLite:dbname=$dbf";
|
||||
my $sth;
|
||||
my $dbh = DBI->connect($dsn,"","", { RaiseError => 1, ShowErrorStatement => 1 }) ||
|
||||
die "Cannot connect: $DBI::errstr";
|
||||
|
||||
print "Deleting records...\n";
|
||||
$dbh->do("DELETE FROM jsonNodes where lastSeen < $limit");
|
||||
print "VACUUM...\n";
|
||||
$dbh->do("VACUUM");
|
||||
$dbh->disconnect();
|
||||
print "Done.\n";
|
||||
|
||||
1;
|
Loading…
x
Reference in New Issue
Block a user