mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-01-31 12:49:34 +00:00
fhem.pl & 92_Filelog.pm: archiveCompress attribute (Forum #41245)
git-svn-id: https://svn.fhem.de/fhem/trunk@9581 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
77832f5858
commit
8fde1df22a
@ -39,7 +39,8 @@ FileLog_Initialize($)
|
||||
$hash->{AttrFn} = "FileLog_Attr";
|
||||
# logtype is used by the frontend
|
||||
$hash->{AttrList} = "disable:0,1 disabledForIntervals logtype reformatFn ".
|
||||
"nrarchive archivedir archivecmd addStateEvent:0,1";
|
||||
"nrarchive archivedir archivecmd addStateEvent:0,1 ".
|
||||
"archiveCompress";
|
||||
|
||||
$hash->{FW_summaryFn} = "FileLog_fhemwebFn";
|
||||
$hash->{FW_detailFn} = "FileLog_fhemwebFn";
|
||||
@ -1202,14 +1203,20 @@ FileLog_regexpFn($$)
|
||||
shell command (no enclosing " is needed), and each % in the command
|
||||
will be replaced with the name of the old logfile.<br>
|
||||
|
||||
If this attribute is not set, but nrarchive and/or archivecmd are set,
|
||||
then nrarchive old logfiles are kept along the current one while older
|
||||
ones are moved to archivedir (or deleted if archivedir is not set).
|
||||
<br>
|
||||
If this attribute is not set, but nrarchive is set, then nrarchive old
|
||||
logfiles are kept along the current one while older ones are moved to
|
||||
archivedir (or deleted if archivedir is not set). <br>
|
||||
|
||||
Note: setting these attributes for the global instance will effect the
|
||||
<a href="#logfile">FHEM logfile</a> only.
|
||||
</li><br>
|
||||
|
||||
<a name="archiveCompress"></a>
|
||||
<li>archiveCompress<br>
|
||||
If nrarchive, archivedir and archiveCompress is set, then the files
|
||||
in the archivedir will be compressed.
|
||||
</li><br>
|
||||
|
||||
<li><a href="#disable">disable</a></li>
|
||||
<li><a href="#disabledForIntervals">disabledForIntervals</a></li>
|
||||
|
||||
@ -1486,18 +1493,22 @@ FileLog_regexpFn($$)
|
||||
shell-Kommando ( eine Einbettung in " ist nicht notwendig), und jedes %
|
||||
in diesem Befehl wird durch den Namen des alten Logfiles ersetzt.<br>
|
||||
|
||||
Wenn dieses Attribut nicht gesetzt wird, aber dafür nrarchive
|
||||
und/oder archivecmd, werden nrarchive viele Logfiles im aktuellen
|
||||
Verzeichnis gelassen, und ältere Dateien in das Archivverzeichnis
|
||||
(archivedir) verschoben (oder gelöscht, falls kein archivedir
|
||||
gesetzt wurde).<br>
|
||||
Wenn dieses Attribut nicht gesetzt wird, aber dafür nrarchive,
|
||||
werden nrarchive viele Logfiles im aktuellen Verzeichnis gelassen, und
|
||||
ältere Dateien in das Archivverzeichnis (archivedir) verschoben
|
||||
(oder gelöscht, falls kein archivedir gesetzt wurde).<br>
|
||||
|
||||
Hinweis: Werden diese Attribute als global instance gesetzt, hat das
|
||||
auschließlich auf das <a href="#logfile">FHEM logfile</a>
|
||||
Auswirkungen.
|
||||
Auswirkungen. </li><br>
|
||||
|
||||
<a name="archiveCompress"></a>
|
||||
<li>archiveCompress<br>
|
||||
Falls nrarchive, archivedir und archiveCompress gesetzt ist, dann
|
||||
werden die Dateien im archivedir komprimiert abgelegt.
|
||||
</li><br>
|
||||
|
||||
|
||||
<li><a href="#disable">disable</a></li>
|
||||
<li><a href="#addStateEvent">addStateEvent</a></li>
|
||||
|
||||
|
38
fhem/fhem.pl
38
fhem/fhem.pl
@ -114,7 +114,7 @@ sub getAllGets($);
|
||||
sub getAllSets($);
|
||||
sub getUniqueId();
|
||||
sub latin1ToUtf8($);
|
||||
sub myrename($$);
|
||||
sub myrename($$$);
|
||||
sub notifyRegexpChanged($$);
|
||||
sub readingsBeginUpdate($);
|
||||
sub readingsBulkUpdate($$$@);
|
||||
@ -255,6 +255,7 @@ my @globalAttrList = qw(
|
||||
apiversion
|
||||
archivecmd
|
||||
archivedir
|
||||
archiveCompress
|
||||
autoload_undefined_devices:1,0
|
||||
autosave:1,0
|
||||
backup_before_update
|
||||
@ -3121,10 +3122,20 @@ doGlobalDef($)
|
||||
#####################################
|
||||
# rename does not work over Filesystems: lets copy it
|
||||
sub
|
||||
myrename($$)
|
||||
myrename($$$)
|
||||
{
|
||||
my ($from, $to) = @_;
|
||||
my ($name, $from, $to) = @_;
|
||||
|
||||
my $ca = AttrVal($name, "archiveCompress", 0);
|
||||
if($ca) {
|
||||
eval { require Compress::Zlib; };
|
||||
if($@) {
|
||||
$ca = 0;
|
||||
Log 1, $@;
|
||||
}
|
||||
}
|
||||
$to .= ".gz" if($ca);
|
||||
|
||||
if(!open(F, $from)) {
|
||||
Log(1, "Rename: Cannot open $from: $!");
|
||||
return;
|
||||
@ -3133,8 +3144,18 @@ myrename($$)
|
||||
Log(1, "Rename: Cannot open $to: $!");
|
||||
return;
|
||||
}
|
||||
while(my $l = <F>) {
|
||||
print T $l;
|
||||
|
||||
if($ca) {
|
||||
my $d = Compress::Zlib::deflateInit(-WindowBits=>31);
|
||||
my $buf;
|
||||
while(sysread(F,$buf,32768) > 0) {
|
||||
syswrite(T, $d->deflate($buf));
|
||||
}
|
||||
syswrite(T, $d->flush());
|
||||
} else {
|
||||
while(my $l = <F>) {
|
||||
print T $l;
|
||||
}
|
||||
}
|
||||
close(F);
|
||||
close(T);
|
||||
@ -3146,13 +3167,14 @@ myrename($$)
|
||||
sub
|
||||
HandleArchiving($;$)
|
||||
{
|
||||
my ($log,$diff) = @_;
|
||||
my ($log,$flogInitial) = @_;
|
||||
my $ln = $log->{NAME};
|
||||
return if(!$attr{$ln});
|
||||
|
||||
# If there is a command, call that
|
||||
my $cmd = $attr{$ln}{archivecmd};
|
||||
if($cmd) {
|
||||
return if($flogInitial); # Forum #41245
|
||||
$cmd =~ s/%/$log->{currentlogfile}/g;
|
||||
Log 2, "Archive: calling $cmd";
|
||||
system($cmd);
|
||||
@ -3179,11 +3201,11 @@ HandleArchiving($;$)
|
||||
closedir(DH);
|
||||
|
||||
my $max = int(@files)-$nra;
|
||||
$max -= $diff if($diff);
|
||||
$max-- if($flogInitial);
|
||||
for(my $i = 0; $i < $max; $i++) {
|
||||
if($ard) {
|
||||
Log 2, "Moving $files[$i] to $ard";
|
||||
myrename("$dir/$files[$i]", "$ard/$files[$i]");
|
||||
myrename($ln, "$dir/$files[$i]", "$ard/$files[$i]");
|
||||
} else {
|
||||
Log 2, "Deleting $files[$i]";
|
||||
unlink("$dir/$files[$i]");
|
||||
|
Loading…
Reference in New Issue
Block a user