2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-02-27 20:34:52 +00:00

configDB.pm: delete old files for large readings

git-svn-id: https://svn.fhem.de/fhem/trunk@25114 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
betateilchen 2021-10-24 10:39:08 +00:00
parent d33c52af5a
commit dc629a6842

@ -160,6 +160,8 @@
# #
# 2021-08-17 - changed adopt to Rudi's funny fakelog changes # 2021-08-17 - changed adopt to Rudi's funny fakelog changes
# #
# 2021-10-24 - added delete old files for large readings
#
############################################################################## ##############################################################################
=cut =cut
@ -219,6 +221,7 @@ sub _cfgDB_Uuid;
sub _cfgDB_table_exists; sub _cfgDB_table_exists;
sub _cfgDB_dump; sub _cfgDB_dump;
sub _cfgDB_knownAttr; sub _cfgDB_knownAttr;
sub _cfgDB_deleteRF;
################################################## ##################################################
# Read configuration file for DB connection # Read configuration file for DB connection
@ -518,6 +521,8 @@ sub cfgDB_SaveCfg { ## prototype used in fhem.pl
sub cfgDB_SaveState { sub cfgDB_SaveState {
my ($out,$val,$r,$rd,$t,@rowList); my ($out,$val,$r,$rd,$t,@rowList);
_cfgDB_deleteRF;
$t = localtime; $t = localtime;
$out = "#$t"; $out = "#$t";
push @rowList, $out; push @rowList, $out;
@ -559,6 +564,7 @@ sub cfgDB_SaveState {
my $uid = _cfgDB_Uuid(); my $uid = _cfgDB_Uuid();
FileWrite($uid,$val); FileWrite($uid,$val);
$out = "setstate $d $rd->{TIME} $c cfgDBkey:$uid"; $out = "setstate $d $rd->{TIME} $c cfgDBkey:$uid";
Log 5, "configDB: r:$c d:$d key:$uid";
} }
push @rowList, $out; push @rowList, $out;
} }
@ -961,6 +967,29 @@ sub _cfgDB_Info {
return join("\n", @r); return join("\n", @r);
} }
sub _cfgDB_Info_Json {
my $cSVN = shift;
$cSVN //= 'unknown';
my %info = ();
# add ./FHEM/98_configdb.pm svn id
$info{cSVN} = $cSVN;
# add ./configDB.pm svn id
my $dSVN = cfgDB_svnId;
$dSVN =~ s/# //;
$info{dSVN} = $dSVN;
# add configDB database info
$info{dbconn} = $cfgDB_dbconn;
$info{dbuser} = $configDB{attr}{private} ? 'private' : $cfgDB_dbuser;
$info{dbpass} = $configDB{attr}{private} ? 'private' : $cfgDB_dbpass;
$info{dbtype} = $cfgDB_dbtype;
$info{dbsize} = _cfgDB_filesize_str(-s $cfgDB_filename) if ($cfgDB_dbtype eq "SQLITE");
return toJSON \%info;
}
# recover former config from database archive # recover former config from database archive
sub _cfgDB_Recover { sub _cfgDB_Recover {
my ($version) = @_; my ($version) = @_;
@ -1215,6 +1244,22 @@ sub _cfgDB_knownAttr {
# "for internal use only"; # "for internal use only";
} }
sub _cfgDB_deleteRF {
# Delete old files containing large readings
my $filename;
my $fhem_dbh2 = _cfgDB_Connect;
my $sth = $fhem_dbh2->prepare( "SELECT filename FROM fhemb64filesave" );
$sth->execute();
while ($filename = $sth->fetchrow_array()) {
if ($filename =~ m/^[0-9A-F]+$/i) {
Log 5, "configDB delete file: $filename";
$fhem_dbh2->do("delete from fhemb64filesave where filename = '$filename'");
}
}
$fhem_dbh2->commit();
$fhem_dbh2->disconnect();
}
################################################## ##################################################
# functions used for file handling # functions used for file handling
# called by 98_configdb.pm # called by 98_configdb.pm
@ -1224,10 +1269,10 @@ sub _cfgDB_knownAttr {
sub _cfgDB_Filedelete { sub _cfgDB_Filedelete {
my ($filename,$fhem_dbh) = @_; my ($filename,$fhem_dbh) = @_;
my $internal_call = 1 if $fhem_dbh; my $internal_call = 1 if $fhem_dbh;
$fhem_dbh = _cfgDB_Connect unless $fhem_dbh; $fhem_dbh = _cfgDB_Connect unless $internal_call;
my $ret = $fhem_dbh->do("delete from fhemb64filesave where filename = '$filename'"); my $ret = $fhem_dbh->do("delete from fhemb64filesave where filename = '$filename'");
$fhem_dbh->commit(); $fhem_dbh->commit();
$fhem_dbh->disconnect() unless $fhem_dbh; $fhem_dbh->disconnect() unless $internal_call;
$ret = ($ret > 0) ? 1 : undef; $ret = ($ret > 0) ? 1 : undef;
return $ret; return $ret;
} }