mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-04-04 17:08:43 +00:00
configDB update
- removed 98_configDBwrap, replaced by new command interface - added 98_configdb.pm, adds new command interface - restructured and updated docu git-svn-id: https://svn.fhem.de/fhem/trunk@5192 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
d762312a4b
commit
447ec2577c
@ -1,336 +0,0 @@
|
||||
# $Id$
|
||||
# Wrapper module for configDB
|
||||
package main;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use feature qw/say switch/;
|
||||
|
||||
sub configDBwrap_Initialize($) {
|
||||
my ($hash) = @_;
|
||||
$hash->{DefFn} = "configDBwrap_Define";
|
||||
$hash->{SetFn} = "configDBwrap_Set";
|
||||
$hash->{GetFn} = "configDBwrap_Get";
|
||||
$hash->{AttrList} = "private:1,0 ";
|
||||
}
|
||||
|
||||
sub configDBwrap_Define($$) {
|
||||
return "configDB not enabled!" unless $attr{global}{configfile} eq 'configDB';
|
||||
my ($hash, $def) = @_;
|
||||
my @a = split("[ \t][ \t]*", $def);
|
||||
return "Wrong syntax: use define <name> configDB" if(int(@a) != 2);
|
||||
my @version = split(/ /,cfgDB_svnId);
|
||||
readingsSingleUpdate($hash, 'version', "$version[3] - $version[4]", 0);
|
||||
readingsSingleUpdate($hash, 'state', 'active', 0);
|
||||
return undef;
|
||||
}
|
||||
|
||||
sub configDBwrap_Set($@) {
|
||||
my ($hash, @a) = @_;
|
||||
my $name = $hash->{NAME};
|
||||
my $usage = "Unknown argument, choose one of reorg recover";
|
||||
return $usage if(int(@a) < 2);
|
||||
my $ret;
|
||||
|
||||
given ($a[1]) {
|
||||
|
||||
when ('reorg') {
|
||||
$a[2] = $a[2] ? $a[2] : 3;
|
||||
$ret = cfgDB_Reorg($a[2]);
|
||||
}
|
||||
|
||||
when ('recover') {
|
||||
$a[2] = $a[2] ? $a[2] : 3;
|
||||
$ret = cfgDB_Recover($a[2]);
|
||||
}
|
||||
|
||||
default { $ret = $usage; }
|
||||
|
||||
}
|
||||
|
||||
return $ret;
|
||||
|
||||
}
|
||||
|
||||
sub configDBwrap_Get($@) {
|
||||
|
||||
my ($hash, @a) = @_;
|
||||
my $name = $hash->{NAME};
|
||||
my $usage = "Unknown argument, choose one of diff info:noArg list uuid";
|
||||
return $usage if(int(@a) < 2);
|
||||
my $ret;
|
||||
|
||||
given ($a[1]) {
|
||||
|
||||
when ('info') {
|
||||
$ret = cfgDB_Info;
|
||||
}
|
||||
|
||||
when ('list') {
|
||||
$a[2] = $a[2] ? $a[2] : '%';
|
||||
$a[3] = $a[3] ? $a[3] : 0;
|
||||
$ret = cfgDB_List($a[2],$a[3]);
|
||||
}
|
||||
|
||||
when ('diff') {
|
||||
$ret = cfgDB_Diff($a[2],$a[3]);
|
||||
}
|
||||
|
||||
when ('uuid') {
|
||||
$ret = _cfgDB_Uuid;
|
||||
}
|
||||
|
||||
default { $ret = $usage; }
|
||||
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
=pod
|
||||
=begin html
|
||||
|
||||
<a name="configDBwrap"></a>
|
||||
<h3>configDBwrap</h3>
|
||||
<ul>
|
||||
This module is a wrapper to support set and get compatibility <br/>
|
||||
for additional functions provided by configDB.<br/>
|
||||
<br/>
|
||||
<a name="GDSdefine"></a>
|
||||
<b>Define</b>
|
||||
<ul>
|
||||
<br/>
|
||||
<code>define configDB configDBwrap</code>
|
||||
<br/><br/>
|
||||
Important: the name <b>must</b> be configDB!
|
||||
</ul>
|
||||
<br/>
|
||||
<br/>
|
||||
<a name="GDSset"></a>
|
||||
<b>Set-Commands</b><br/>
|
||||
<br/>
|
||||
<ul>
|
||||
<li><code>set configDB reorg [keep]</code></li><br/>
|
||||
Deletes all stored versions with version number higher than [keep].<br/>
|
||||
Default value for optional parameter keep = 3.<br/>
|
||||
This function can be used to create a nightly running job for<br/>
|
||||
database reorganisation when called from an at-Definition.<br/>
|
||||
<br/>
|
||||
|
||||
<li><code>set configDB recover <version></code></li><br/>
|
||||
Restores an older version from database archive.<br/>
|
||||
<code>set configDB recover 3</code> will <b>copy</b> version #3 from database
|
||||
to version #0.<br/>
|
||||
Original version #0 will be lost.<br/><br/>
|
||||
<b>Important!</b><br/>
|
||||
The restored version will <b>NOT</b> be activated automatically!<br/>
|
||||
You must do a <code>rereadcfg</code> or - even better - <code>shutdown restart</code> yourself.<br/>
|
||||
</ul>
|
||||
<br/>
|
||||
<br/>
|
||||
<a name="GDSget"></a>
|
||||
<b>Get-Commands</b><br/>
|
||||
<br/>
|
||||
<ul>
|
||||
<li><code>get configDB info</code></li><br/>
|
||||
Returns some database statistics<br/>
|
||||
<pre>
|
||||
--------------------------------------------------------------------------------
|
||||
configDB Database Information
|
||||
--------------------------------------------------------------------------------
|
||||
dbconn: SQLite:dbname=/opt/fhem/configDB.db
|
||||
dbuser:
|
||||
dbpass:
|
||||
dbtype: SQLITE
|
||||
--------------------------------------------------------------------------------
|
||||
fhemconfig: 7707 entries
|
||||
|
||||
Ver 0 saved: Sat Mar 1 11:37:00 2014 def: 293 attr: 1248
|
||||
Ver 1 saved: Fri Feb 28 23:55:13 2014 def: 293 attr: 1248
|
||||
Ver 2 saved: Fri Feb 28 23:49:01 2014 def: 293 attr: 1248
|
||||
Ver 3 saved: Fri Feb 28 22:24:40 2014 def: 293 attr: 1247
|
||||
Ver 4 saved: Fri Feb 28 22:14:03 2014 def: 293 attr: 1246
|
||||
--------------------------------------------------------------------------------
|
||||
fhemstate: 1890 entries saved: Sat Mar 1 12:05:00 2014
|
||||
--------------------------------------------------------------------------------
|
||||
</pre>
|
||||
Ver 0 always indicates the currently running configuration.<br/>
|
||||
<br/>
|
||||
|
||||
<li><code>get configDB list [device] [version]</code></li><br/>
|
||||
Search for device named [device] in configuration version [version]<br/>
|
||||
in database archive.<br/>
|
||||
Default value for [device] = % to show all devices.<br/>
|
||||
Default value for [version] = 0 to show devices from current version.<br/>
|
||||
Examples for valid requests:<br/>
|
||||
<br/>
|
||||
<code>get configDB list</code><br/>
|
||||
<code>get configDB list global</code><br/>
|
||||
<code>get configDB list '' 1</code><br/>
|
||||
<code>get configDB list global 1</code><br/>
|
||||
<br/>
|
||||
|
||||
<li><code>get configDB diff <device> <version></code></li><br/>
|
||||
Compare configuration dataset for device <device>
|
||||
from current version 0 with version <version><br/>
|
||||
Example for valid request:<br/>
|
||||
<br/>
|
||||
<code>get configDB telnetPort 1</code><br/>
|
||||
<br/>
|
||||
will show a result like this:
|
||||
<pre>
|
||||
compare device: telnetPort in current version 0 (left) to version: 1 (right)
|
||||
+--+--------------------------------------+--+--------------------------------------+
|
||||
| 1|define telnetPort telnet 7072 global | 1|define telnetPort telnet 7072 global |
|
||||
* 2|attr telnetPort room telnet * | |
|
||||
+--+--------------------------------------+--+--------------------------------------+</pre>
|
||||
|
||||
<li><code>get configDB uuid</code></li><br/>
|
||||
Returns a uuid that can be used for own purposes.<br/>
|
||||
</ul>
|
||||
<br/>
|
||||
<a name="GDSattr"></a>
|
||||
<b>Attributes</b><br/>
|
||||
<br/>
|
||||
<ul>
|
||||
<li><code>private <1|0></code></li><br/>
|
||||
If set to 1 user and password info will not be shown in get ... info.<br/>
|
||||
</ul>
|
||||
<br/>
|
||||
<b>Author's notes</b><br/>
|
||||
<br/>
|
||||
<ul>
|
||||
<li>You may need to install perl package Text::Diff to use the diff-function.</li>
|
||||
<br/>
|
||||
<li>There still will be some more (planned) development to this extension.</li>
|
||||
<br/>
|
||||
<li>Have fun!</li>
|
||||
</ul>
|
||||
</ul>
|
||||
|
||||
=end html
|
||||
|
||||
=begin html_DE
|
||||
|
||||
<a name="configDBwrap"></a>
|
||||
<h3>configDBwrap</h3>
|
||||
<ul>
|
||||
Ein Wrapper-Modul, um die von configDB bereitgestellten Zusatzfunktionen<br/>
|
||||
mit regulären set und get Befehlen nutzen zu können.<br/>
|
||||
<br/>
|
||||
<a name="GDSdefine"></a>
|
||||
<b>Define</b>
|
||||
<ul>
|
||||
<br/>
|
||||
<code>define configDB configDBwrap</code>
|
||||
<br/><br/>
|
||||
Wichtig: der Name <b>muss</b> configDB lauten!
|
||||
</ul>
|
||||
<br/>
|
||||
<br/>
|
||||
<a name="GDSset"></a>
|
||||
<b>Set-Befehle</b><br/>
|
||||
<br/>
|
||||
<ul>
|
||||
<li><code>set configDB reorg [keep]</code></li><br/>
|
||||
Löscht alle gespeicherten Konfigurationen mit Versionsnummern größer als [keep].<br/>
|
||||
Standardwert für den optionalen Parameter keep = 3.<br/>
|
||||
Mit dieser Funktion läßt sich eine nächtliche Reorganisation per at umsetzen.<br/>
|
||||
<br/>
|
||||
|
||||
<li><code>set configDB recover <version></code></li><br/>
|
||||
Stellt eine ältere Version aus dem Datenbankarchiv wieder her.<br/>
|
||||
<code>set configDB recover 3</code> <b>kopiert</b> die Version #3 aus der Datenbank
|
||||
zur Version #0.<br/>
|
||||
Die ursprüngliche Version #0 wird dabei gelöscht.<br/><br/>
|
||||
<b>Wichtig!</b><br/>
|
||||
Die zurückgeholte Version wird <b>NICHT</b> automatisch aktiviert!<br/>
|
||||
Ein <code>rereadcfg</code> oder - besser - <code>shutdown restart</code> muss manuell erfolgen.<br/>
|
||||
</ul>
|
||||
<br/>
|
||||
<br/>
|
||||
<a name="GDSget"></a>
|
||||
<b>Get-Befehle</b><br/>
|
||||
<br/>
|
||||
<ul>
|
||||
<li><code>get configDB info</code></li><br/>
|
||||
Liefert eine Datenbankstatistik<br/>
|
||||
<pre>
|
||||
--------------------------------------------------------------------------------
|
||||
configDB Database Information
|
||||
--------------------------------------------------------------------------------
|
||||
dbconn: SQLite:dbname=/opt/fhem/configDB.db
|
||||
dbuser:
|
||||
dbpass:
|
||||
dbtype: SQLITE
|
||||
--------------------------------------------------------------------------------
|
||||
fhemconfig: 7707 entries
|
||||
|
||||
Ver 0 saved: Sat Mar 1 11:37:00 2014 def: 293 attr: 1248
|
||||
Ver 1 saved: Fri Feb 28 23:55:13 2014 def: 293 attr: 1248
|
||||
Ver 2 saved: Fri Feb 28 23:49:01 2014 def: 293 attr: 1248
|
||||
Ver 3 saved: Fri Feb 28 22:24:40 2014 def: 293 attr: 1247
|
||||
Ver 4 saved: Fri Feb 28 22:14:03 2014 def: 293 attr: 1246
|
||||
--------------------------------------------------------------------------------
|
||||
fhemstate: 1890 entries saved: Sat Mar 1 12:05:00 2014
|
||||
--------------------------------------------------------------------------------
|
||||
</pre>
|
||||
Ver 0 bezeichnet immer die aktuell verwendete Konfiguration.<br/>
|
||||
<br/>
|
||||
|
||||
<li><code>get configDB list [device] [version]</code></li><br/>
|
||||
Sucht das Gerät [device] in der Konfiguration der Version [version]<br/>
|
||||
in der Datenbank.<br/>
|
||||
Standardwert für [device] = % um alle Geräte anzuzeigen<br/>
|
||||
Standardwert für [version] = 0 um Geräte in der aktuellen Version anzuzeigen.<br/>
|
||||
Beispiele für gültige Aufrufe:<br/>
|
||||
<br/>
|
||||
<code>get configDB list</code><br/>
|
||||
<code>get configDB list global</code><br/>
|
||||
<code>get configDB list '' 1</code><br/>
|
||||
<code>get configDB list global 1</code><br/>
|
||||
<br/>
|
||||
|
||||
<li><code>get configDB diff <device> <version></code></li><br/>
|
||||
Vergleicht die Konfigurationsdaten des Gerätes <device> aus der aktuellen Version 0 mit den Daten aus Version <version><br/>
|
||||
Beispielaufruf:<br/>
|
||||
<br/>
|
||||
<code>get configDB diff telnetPort 1</code><br/>
|
||||
<br/>
|
||||
liefert ein Ergebnis ähnlich dieser Ausgabe:
|
||||
<pre>
|
||||
compare device: telnetPort in current version 0 (left) to version: 1 (right)
|
||||
+--+--------------------------------------+--+--------------------------------------+
|
||||
| 1|define telnetPort telnet 7072 global | 1|define telnetPort telnet 7072 global |
|
||||
* 2|attr telnetPort room telnet * | |
|
||||
+--+--------------------------------------+--+--------------------------------------+</pre>
|
||||
|
||||
<li><code>get configDB uuid</code></li><br/>
|
||||
Liefert eine uuid, die man für eigene Zwecke verwenden kann.<br/>
|
||||
</ul>
|
||||
<br/>
|
||||
<a name="GDSattr"></a>
|
||||
<b>Attribute</b><br/>
|
||||
<br/>
|
||||
<ul>
|
||||
<li><code>private <1|0></code></li><br/>
|
||||
Benutzername und Passwort werden in get ... info nicht angezeigt, wenn private auf 1 gesetzt wird.<br/>
|
||||
</ul>
|
||||
<br/>
|
||||
<b>Hinweise:</b><br/>
|
||||
<br/>
|
||||
<ul>
|
||||
<br/>
|
||||
<li>Für die Nutzung von get ... diff wird das perl Paket Text::Diff benötigt.</li>
|
||||
<br/>
|
||||
<li>Diese Erweiterung wird laufend weiterentwickelt.</li>
|
||||
<br/>
|
||||
<li>Viel Spass!</li>
|
||||
</ul>
|
||||
</ul>
|
||||
|
||||
=end html_DE
|
||||
|
||||
=cut
|
625
fhem/FHEM/98_configdb.pm
Normal file
625
fhem/FHEM/98_configdb.pm
Normal file
@ -0,0 +1,625 @@
|
||||
package main;
|
||||
use strict;
|
||||
use warnings;
|
||||
use feature qw/say switch/;
|
||||
|
||||
sub CommandConfigdb($$);
|
||||
|
||||
my @pathname;
|
||||
|
||||
sub configdb_Initialize($$) {
|
||||
my %hash = ( Fn => "CommandConfigdb",
|
||||
Hlp => "info|list|diff|uuid|
|
||||
reorg|recover|backup ,access additional functions from configDB" );
|
||||
$cmds{configdb} = \%hash;
|
||||
}
|
||||
|
||||
#####################################
|
||||
|
||||
sub _configdb_rM($$) {
|
||||
my ($modpath,$backupdir) = @_;
|
||||
my $msg;
|
||||
my $ret;
|
||||
|
||||
if (!opendir(DH, $modpath)) {
|
||||
$msg = "Can't open $modpath: $!";
|
||||
Log 1, "backup $msg";
|
||||
return $msg;
|
||||
}
|
||||
my @files = <$modpath/*>;
|
||||
foreach my $file (@files) {
|
||||
if ($file eq $backupdir && (-d $file || -l $file)) {
|
||||
Log 4, "backup exclude: '$file'";
|
||||
} else {
|
||||
Log 4, "backup include: '$file'";
|
||||
push @pathname, $file;
|
||||
}
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
sub _configdb_cA($) {
|
||||
my $backupdir = shift;
|
||||
my $backupcmd = (!defined($attr{global}{backupcmd}) ? undef : $attr{global}{backupcmd});
|
||||
my $symlink = (!defined($attr{global}{backupsymlink}) ? "no" : $attr{global}{backupsymlink});
|
||||
my $tarOpts;
|
||||
my $msg;
|
||||
my $ret;
|
||||
|
||||
my $dateTime = TimeNow();
|
||||
$dateTime =~ s/ /_/g;
|
||||
$dateTime =~ s/(:|-)//g;
|
||||
|
||||
my $cmd="";
|
||||
if (!defined($backupcmd)) {
|
||||
if (lc($symlink) eq "no") {
|
||||
$tarOpts = "cf";
|
||||
} else {
|
||||
$tarOpts = "chf";
|
||||
}
|
||||
|
||||
# prevents tar's output of "Removing leading /" and return total bytes of archive
|
||||
$cmd = "tar -$tarOpts - @pathname |gzip > $backupdir/FHEM-$dateTime.tar.gz";
|
||||
|
||||
} else {
|
||||
$cmd = "$backupcmd \"@pathname\"";
|
||||
|
||||
}
|
||||
Log 2, "Backup with command: $cmd";
|
||||
$ret = `($cmd) 2>&1`;
|
||||
|
||||
if($ret) {
|
||||
chomp $ret;
|
||||
Log 1, "backup $ret";
|
||||
}
|
||||
if (!defined($backupcmd) && -e "$backupdir/FHEM-$dateTime.tar.gz") {
|
||||
my $size = -s "$backupdir/FHEM-$dateTime.tar.gz";
|
||||
$msg = "backup done: FHEM-$dateTime.tar.gz ($size Bytes)";
|
||||
Log 1, $msg;
|
||||
$ret .= "\n".$msg;
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
sub _configdb_backup {
|
||||
my $modpath = $attr{global}{modpath};
|
||||
my $msg;
|
||||
my $ret;
|
||||
|
||||
# set backupdir
|
||||
my $backupdir;
|
||||
if (!defined($attr{global}{backupdir})) {
|
||||
$backupdir = "$modpath/backup";
|
||||
} else {
|
||||
if ($attr{global}{backupdir} =~ m/^\/.*/) {
|
||||
$backupdir = $attr{global}{backupdir};
|
||||
} elsif ($attr{global}{backupdir} =~ m/^\.+\/.*/) {
|
||||
$backupdir = "$modpath/$attr{global}{backupdir}";
|
||||
} else {
|
||||
$backupdir = "$modpath/$attr{global}{backupdir}";
|
||||
}
|
||||
}
|
||||
|
||||
# create backupdir if not exists
|
||||
if (!-d $backupdir) {
|
||||
Log 4, "backup create backupdir: '$backupdir'";
|
||||
$ret = `(mkdir -p $backupdir) 2>&1`;
|
||||
if ($ret) {
|
||||
chomp $ret;
|
||||
$msg = "backup: $ret";
|
||||
return $msg;
|
||||
}
|
||||
}
|
||||
|
||||
# get pathnames to archiv
|
||||
$ret = _configdb_rM($modpath,$backupdir);
|
||||
|
||||
# create archiv
|
||||
$ret = _configdb_cA($backupdir);
|
||||
|
||||
@pathname = [];
|
||||
undef @pathname;
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
sub CommandConfigdb($$) {
|
||||
my ($cl, $param) = @_;
|
||||
|
||||
my $configfile = $attr{global}{configfile};
|
||||
return "\n error: configDB not used!" unless($configfile eq 'configDB');
|
||||
|
||||
my @a = split(/ /,$param);
|
||||
my ($ret,$usage);
|
||||
|
||||
given ($a[0]) {
|
||||
|
||||
when ('info') {
|
||||
$ret = cfgDB_Info;
|
||||
}
|
||||
|
||||
when ('list') {
|
||||
$a[1] = $a[1] ? $a[1] : '%';
|
||||
$a[2] = $a[2] ? $a[2] : 0;
|
||||
$ret = cfgDB_List($a[1],$a[2]);
|
||||
}
|
||||
|
||||
when ('diff') {
|
||||
$ret = cfgDB_Diff($a[1],$a[2]);
|
||||
}
|
||||
|
||||
when ('uuid') {
|
||||
$ret = _cfgDB_Uuid;
|
||||
}
|
||||
|
||||
when ('reorg') {
|
||||
$a[1] = $a[1] ? $a[1] : 3;
|
||||
$ret = cfgDB_Reorg($a[1]);
|
||||
}
|
||||
|
||||
when ('recover') {
|
||||
$a[1] = $a[1] ? $a[1] : 1;
|
||||
$ret = cfgDB_Recover($a[1]);
|
||||
}
|
||||
|
||||
when ('backup') {
|
||||
if($^O =~ m/Win/) {
|
||||
$ret = "\n error: backup not supported for Windows";
|
||||
} else {
|
||||
$ret = _configdb_backup;
|
||||
}
|
||||
}
|
||||
default {
|
||||
$ret = "\n Syntax: configdb info\n".
|
||||
" configdb list [device] [version]\n".
|
||||
" configdb diff <device> <version>\n".
|
||||
" configdb uuid\n".
|
||||
" configdb backup\n".
|
||||
" configdb recover <version>\n".
|
||||
" configdb reorg [keepVersions]\n";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $ret;
|
||||
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
=pod
|
||||
=begin html
|
||||
|
||||
<a name="configdb"></a>
|
||||
<h3>configdb</h3>
|
||||
<ul>
|
||||
Starting with version 5079, fhem can be used with a configuration database instead of a plain text file (e.g. fhem.cfg).<br/>
|
||||
This offers the possibility to completely waive all cfg-files, "include"-problems and so on.<br/>
|
||||
Furthermore, configDB offers a versioning of several configuration together with the possibility to restore a former configuration.<br/>
|
||||
Access to database is provided via perl's database interface DBI.<br/>
|
||||
<br/>
|
||||
<b>Prerequisits / Installation</b><br/>
|
||||
<ul><br/>
|
||||
<li>You must have access to a SQL database. Supported database types are SQLITE, MYSQL and POSTGRESQL.</li><br/>
|
||||
<li>The corresponding DBD module must be available in your perl environment,<br/>
|
||||
e.g. sqlite3 running on a Debian systems requires package libdbd-sqlite3-perl</li><br/>
|
||||
<li>Create an empty database, e.g. with sqlite3:<br/>
|
||||
<pre>
|
||||
mba:fhem udo$ sqlite3 configDB.db
|
||||
|
||||
SQLite version 3.7.13 2012-07-17 17:46:21
|
||||
Enter ".help" for instructions
|
||||
Enter SQL statements terminated with a ";"
|
||||
sqlite> pragma auto_vacuum=2;
|
||||
sqlite> .quit
|
||||
|
||||
mba:fhem udo$
|
||||
</pre></li>
|
||||
<li>The database tables will be created automatically.</li><br/>
|
||||
<li>Create a configuration file containing the connection string to access database.<br/>
|
||||
<br/>
|
||||
<b>IMPORTANT:</b>
|
||||
<ul><br/>
|
||||
<li>This file <b>must</b> be named "configDB.conf"</li>
|
||||
<li>This file <b>must</b> be located in your fhem main directory, e.g. /opt/fhem</li>
|
||||
</ul>
|
||||
<br/>
|
||||
<pre>
|
||||
## for MySQL
|
||||
################################################################
|
||||
#%dbconfig= (
|
||||
# connection => "mysql:database=configDB;host=db;port=3306",
|
||||
# user => "fhemuser",
|
||||
# password => "fhempassword",
|
||||
#);
|
||||
################################################################
|
||||
#
|
||||
## for PostgreSQL
|
||||
################################################################
|
||||
#%dbconfig= (
|
||||
# connection => "Pg:database=configDB;host=localhost",
|
||||
# user => "fhemuser",
|
||||
# password => "fhempassword"
|
||||
#);
|
||||
################################################################
|
||||
#
|
||||
## for SQLite (username and password stay empty for SQLite)
|
||||
################################################################
|
||||
#%dbconfig= (
|
||||
# connection => "SQLite:dbname=/opt/fhem/configDB.db",
|
||||
# user => "",
|
||||
# password => ""
|
||||
#);
|
||||
################################################################
|
||||
</pre></li><br/>
|
||||
</ul>
|
||||
|
||||
<b>Start with a complete new "fresh" fhem Installation</b><br/>
|
||||
<ul><br/>
|
||||
It's easy... simply start fhem by issuing following command:<br/><br/>
|
||||
<ul><code>perl fhem.pl configDB</code></ul><br/>
|
||||
|
||||
<b>configDB</b> is a keyword which is recognized by fhem to use database for configuration.<br/>
|
||||
<br/>
|
||||
<b>That's all.</b> Everything (save, rereadcfg etc) should work as usual.
|
||||
</ul>
|
||||
|
||||
<br/>
|
||||
<b>or:</b><br/>
|
||||
<br/>
|
||||
|
||||
<b>Migrate your existing fhem configuration into the database</b><br/>
|
||||
<ul><br/>
|
||||
It's easy, too... <br/>
|
||||
<br/>
|
||||
<li>start your fhem the last time with fhem.cfg<br/><br/>
|
||||
<ul><code>perl fhem.pl fhem.cfg</code></ul></li><br/>
|
||||
<br/>
|
||||
<li>transfer your existing configuration into the database<br/><br/>
|
||||
<ul>enter <code>{use configDB;; cfgDB_Migrate}</code><br/>
|
||||
<br/>
|
||||
into frontend's command line</ul><br/></br>
|
||||
Be patient! Migration can take some time, especially on mini-systems like RaspberryPi or Beaglebone.<br/>
|
||||
Completed migration will be indicated by showing database statistics.<br/>
|
||||
Your original configfile will not be touched or modified by this step.</li><br/>
|
||||
<li>shutdown fhem</li><br/>
|
||||
<li>restart fhem with keyword configDB<br/><br/>
|
||||
<ul><code>perl fhem.pl configDB</code></ul></li><br/>
|
||||
<b>configDB</b> is a keyword which is recognized by fhem to use database for configuration.<br/>
|
||||
<br/>
|
||||
<b>That's all.</b> Everything (save, rereadcfg etc) should work as usual.
|
||||
</ul>
|
||||
<br/><br/>
|
||||
|
||||
<b>Additional functions provided</b><br/>
|
||||
<ul><br/>
|
||||
A new command <code>configdb</code> is propagated to fhem.<br/>
|
||||
This command can be used with different parameters.<br/>
|
||||
<br/>
|
||||
|
||||
<li><code>configdb info</code></li><br/>
|
||||
Returns some database statistics<br/>
|
||||
<pre>
|
||||
--------------------------------------------------------------------------------
|
||||
configDB Database Information
|
||||
--------------------------------------------------------------------------------
|
||||
dbconn: SQLite:dbname=/opt/fhem/configDB.db
|
||||
dbuser:
|
||||
dbpass:
|
||||
dbtype: SQLITE
|
||||
--------------------------------------------------------------------------------
|
||||
fhemconfig: 7707 entries
|
||||
|
||||
Ver 0 saved: Sat Mar 1 11:37:00 2014 def: 293 attr: 1248
|
||||
Ver 1 saved: Fri Feb 28 23:55:13 2014 def: 293 attr: 1248
|
||||
Ver 2 saved: Fri Feb 28 23:49:01 2014 def: 293 attr: 1248
|
||||
Ver 3 saved: Fri Feb 28 22:24:40 2014 def: 293 attr: 1247
|
||||
Ver 4 saved: Fri Feb 28 22:14:03 2014 def: 293 attr: 1246
|
||||
--------------------------------------------------------------------------------
|
||||
fhemstate: 1890 entries saved: Sat Mar 1 12:05:00 2014
|
||||
--------------------------------------------------------------------------------
|
||||
</pre>
|
||||
Ver 0 always indicates the currently running configuration.<br/>
|
||||
<br/>
|
||||
|
||||
<li><code>configdb list [device] [version]</code></li><br/>
|
||||
Search for device named [device] in configuration version [version]<br/>
|
||||
in database archive.<br/>
|
||||
Default value for [device] = % to show all devices.<br/>
|
||||
Default value for [version] = 0 to show devices from current version.<br/>
|
||||
Examples for valid requests:<br/>
|
||||
<br/>
|
||||
<code>get configDB list</code><br/>
|
||||
<code>get configDB list global</code><br/>
|
||||
<code>get configDB list '' 1</code><br/>
|
||||
<code>get configDB list global 1</code><br/>
|
||||
<br/>
|
||||
|
||||
<li><code>configdb diff <device> <version></code></li><br/>
|
||||
Compare configuration dataset for device <device>
|
||||
from current version 0 with version <version><br/>
|
||||
Example for valid request:<br/>
|
||||
<br/>
|
||||
<code>get configDB telnetPort 1</code><br/>
|
||||
<br/>
|
||||
will show a result like this:
|
||||
<pre>
|
||||
compare device: telnetPort in current version 0 (left) to version: 1 (right)
|
||||
+--+--------------------------------------+--+--------------------------------------+
|
||||
| 1|define telnetPort telnet 7072 global | 1|define telnetPort telnet 7072 global |
|
||||
* 2|attr telnetPort room telnet * | |
|
||||
+--+--------------------------------------+--+--------------------------------------+</pre>
|
||||
|
||||
<li><code>configdb uuid</code></li><br/>
|
||||
Returns a uuid that can be used for own purposes.<br/>
|
||||
<br/>
|
||||
<li><code>configdb backup</code></li><br/>
|
||||
Replaces fhem's default backup process, since backup is no longer supported <br/>
|
||||
with activated configDB.<br/>
|
||||
<br/>
|
||||
<b>Important:</b><br/>
|
||||
Please be aware you are responsible for data backup of your database yourself!<br/>
|
||||
The backup command can and will not do this job for you!<br/>
|
||||
<br/>
|
||||
<li><code>configdb reorg [keep]</code></li><br/>
|
||||
Deletes all stored versions with version number higher than [keep].<br/>
|
||||
Default value for optional parameter keep = 3.<br/>
|
||||
This function can be used to create a nightly running job for<br/>
|
||||
database reorganisation when called from an at-Definition.<br/>
|
||||
<br/>
|
||||
|
||||
<li><code>configdb recover <version></code></li><br/>
|
||||
Restores an older version from database archive.<br/>
|
||||
<code>set configDB recover 3</code> will <b>copy</b> version #3 from database
|
||||
to version #0.<br/>
|
||||
Original version #0 will be lost.<br/><br/>
|
||||
<b>Important!</b><br/>
|
||||
The restored version will <b>NOT</b> be activated automatically!<br/>
|
||||
You must do a <code>rereadcfg</code> or - even better - <code>shutdown restart</code> yourself.<br/>
|
||||
|
||||
</ul>
|
||||
<br/>
|
||||
<br/>
|
||||
<b>Author's notes</b><br/>
|
||||
<br/>
|
||||
<ul>
|
||||
<li>You can find two template files for datebase and configfile (sqlite only!) for easy installation.<br/>
|
||||
Just copy them to your fhem installation directory (/opt/fhem) and have fun.</li>
|
||||
<br/>
|
||||
<li>The frontend option "Edit files"->"config file" will be removed when running configDB.</li>
|
||||
<br/>
|
||||
<li>Please be patient when issuing a "save" command
|
||||
(either manually or by clicking on "save config").<br/>
|
||||
This will take some moments, due to writing version informations.<br/>
|
||||
Finishing the save-process will be indicated by a corresponding message in frontend.</li>
|
||||
<br/>
|
||||
<li>You may need to install perl package Text::Diff to use cfgDB_Diff()</li>
|
||||
<br/>
|
||||
<li>There still will be some more (planned) development to this extension,
|
||||
especially regarding some perfomance issues.</li>
|
||||
<br/>
|
||||
<li>Have fun!</li>
|
||||
</ul>
|
||||
|
||||
</ul>
|
||||
|
||||
=end html
|
||||
|
||||
=begin html_DE
|
||||
|
||||
<a name="configdb"></a>
|
||||
<h3>configdb</h3>
|
||||
<ul>
|
||||
Seit version 5079 unterstützt fhem die Verwendung einer SQL Datenbank zum Abspeichern der kompletten Konfiguration<br/>
|
||||
Dadurch kann man auf alle cfg Dateien, includes usw. verzichten und die daraus immer wieder resultierenden Probleme vermeiden.<br/>
|
||||
Desweiteren gibt es damit eine Versionierung von Konfigurationen und die Möglichkeit,
|
||||
jederzeit eine ältere Version wiederherstellen zu können.<br/>
|
||||
Der Zugriff auf die Datenbank erfolgt über die perl-eigene Datenbankschnittstelle DBI.<br/>
|
||||
<br/>
|
||||
<b>Voraussetzungen / Installation</b><br/>
|
||||
<ul><br/>
|
||||
<li>Es muss eine SQL Datenbank verfügbar sein, untsrstützt werden SQLITE, MYSQL und POSTGRESQLL.</li><br/>
|
||||
<li>Das zum Datenbanktype gehörende DBD Modul muss in perl installiert sein,<br/>
|
||||
für sqlite3 auf einem Debian System z.B. das Paket libdbd-sqlite3-perl</li><br/>
|
||||
<li>Eine leere Datenbank muss angelegt werden, z.B. in sqlite3:<br/>
|
||||
<pre>
|
||||
mba:fhem udo$ sqlite3 configDB.db
|
||||
|
||||
SQLite version 3.7.13 2012-07-17 17:46:21
|
||||
Enter ".help" for instructions
|
||||
Enter SQL statements terminated with a ";"
|
||||
sqlite> pragma auto_vacuum=2;
|
||||
sqlite> .quit
|
||||
|
||||
mba:fhem udo$
|
||||
</pre></li>
|
||||
<li>Die benötigten Datenbanktabellen werden automatisch angelegt.</li><br/>
|
||||
<li>Eine Konfigurationsdatei für die Verbindung zur Datenbank muss angelegt werden.<br/>
|
||||
<br/>
|
||||
<b>WICHTIG:</b>
|
||||
<ul><br/>
|
||||
<li>Diese Datei <b>muss</b> den Namen "configDB.conf" haben</li>
|
||||
<li>Diese Datei <b>muss</b> im fhem Verzeichnis liegen, z.B. /opt/fhem</li>
|
||||
</ul>
|
||||
<br/>
|
||||
<pre>
|
||||
## für MySQL
|
||||
################################################################
|
||||
#%dbconfig= (
|
||||
# connection => "mysql:database=configDB;host=db;port=3306",
|
||||
# user => "fhemuser",
|
||||
# password => "fhempassword",
|
||||
#);
|
||||
################################################################
|
||||
#
|
||||
## für PostgreSQL
|
||||
################################################################
|
||||
#%dbconfig= (
|
||||
# connection => "Pg:database=configDB;host=localhost",
|
||||
# user => "fhemuser",
|
||||
# password => "fhempassword"
|
||||
#);
|
||||
################################################################
|
||||
#
|
||||
## für SQLite (username and password bleiben bei SQLite leer)
|
||||
################################################################
|
||||
#%dbconfig= (
|
||||
# connection => "SQLite:dbname=/opt/fhem/configDB.db",
|
||||
# user => "",
|
||||
# password => ""
|
||||
#);
|
||||
################################################################
|
||||
</pre></li><br/>
|
||||
</ul>
|
||||
|
||||
<b>Aufruf mit einer vollständig neuen fhem Installation</b><br/>
|
||||
<ul><br/>
|
||||
Sehr einfach... fhem muss lediglich folgendermassen gestartet werden:<br/><br/>
|
||||
<ul><code>perl fhem.pl configDB</code></ul><br/>
|
||||
<b>configDB</b> ist das Schlüsselwort, an dem fhem erkennt, <br/>
|
||||
dass eine Datenbank für die Konfiguration verwendet werden soll.<br/>
|
||||
<br/>
|
||||
<b>Das war es schon.</b> Alle Befehle (save, rereadcfg etc) arbeiten wie gewohnt.
|
||||
</ul>
|
||||
|
||||
<br/>
|
||||
<b>oder:</b><br/>
|
||||
<br/>
|
||||
|
||||
<b>übertragen einer bestehenden fhem Konfiguration in die Datenbank</b><br/>
|
||||
<ul><br/>
|
||||
Auch sehr einfach... <br/>
|
||||
<br/>
|
||||
<li>fhem wird zum letzten Mal mit der fhem.cfg gestartet<br/><br/>
|
||||
<ul><code>perl fhem.pl fhem.cfg</code></ul></li><br/>
|
||||
<br/>
|
||||
<li>Bestehende Konfiguration in die Datenbank übertragen<br/><br/>
|
||||
<ul><code>{use configDB;; cfgDB_Migrate}</code><br/>
|
||||
<br/>
|
||||
in die Befehlszeile der fhem-Oberfläche eingeben</ul><br/></br>
|
||||
Nicht die Geduld verlieren! Die Migration eine Weile dauern, speziell bei Mini-Systemen wie<br/>
|
||||
RaspberryPi or Beaglebone.<br/>
|
||||
Am Ende der Migration wird eine aktuelle Datenbankstatistik angezeigt.<br/>
|
||||
Die ursprüngliche Konfigurationsdatei wird bei diesem Vorgang nicht angetastet.</li><br/>
|
||||
<li>fhem beenden.</li><br/>
|
||||
<li>fhem mit dem Schlüsselwort configDB starten<br/><br/>
|
||||
<ul><code>perl fhem.pl configDB</code></ul></li><br/>
|
||||
<b>configDB</b> ist das Schlüsselwort, an dem fhem erkennt, <br/>
|
||||
dass eine Datenbank für die Konfiguration verwendet werden soll.<br/>
|
||||
<br/>
|
||||
<b>Das war es schon.</b> Alle Befehle (save, rereadcfg etc) arbeiten wie gewohnt.
|
||||
</ul>
|
||||
<br/><br/>
|
||||
|
||||
<b>Zusätzliche Funktionen</b><br/>
|
||||
<ul><br/>
|
||||
Es wird ein neuer Befehl <code>configdb</code> bereitgestellt,<br/>
|
||||
der mit verschiedenen Parametern aufgerufen werden kann.<br/>
|
||||
<br/>
|
||||
<li><code>configdb info</code></li><br/>
|
||||
Liefert eine Datenbankstatistik<br/>
|
||||
<pre>
|
||||
--------------------------------------------------------------------------------
|
||||
configDB Database Information
|
||||
--------------------------------------------------------------------------------
|
||||
dbconn: SQLite:dbname=/opt/fhem/configDB.db
|
||||
dbuser:
|
||||
dbpass:
|
||||
dbtype: SQLITE
|
||||
--------------------------------------------------------------------------------
|
||||
fhemconfig: 7707 entries
|
||||
|
||||
Ver 0 saved: Sat Mar 1 11:37:00 2014 def: 293 attr: 1248
|
||||
Ver 1 saved: Fri Feb 28 23:55:13 2014 def: 293 attr: 1248
|
||||
Ver 2 saved: Fri Feb 28 23:49:01 2014 def: 293 attr: 1248
|
||||
Ver 3 saved: Fri Feb 28 22:24:40 2014 def: 293 attr: 1247
|
||||
Ver 4 saved: Fri Feb 28 22:14:03 2014 def: 293 attr: 1246
|
||||
--------------------------------------------------------------------------------
|
||||
fhemstate: 1890 entries saved: Sat Mar 1 12:05:00 2014
|
||||
--------------------------------------------------------------------------------
|
||||
</pre>
|
||||
Ver 0 bezeichnet immer die aktuell verwendete Konfiguration.<br/>
|
||||
<br/>
|
||||
|
||||
<li><code>configdb list [device] [version]</code></li><br/>
|
||||
Sucht das Gerät [device] in der Konfiguration der Version [version]<br/>
|
||||
in der Datenbank.<br/>
|
||||
Standardwert für [device] = % um alle Geräte anzuzeigen<br/>
|
||||
Standardwert für [version] = 0 um Geräte in der aktuellen Version anzuzeigen.<br/>
|
||||
Beispiele für gültige Aufrufe:<br/>
|
||||
<br/>
|
||||
<code>get configDB list</code><br/>
|
||||
<code>get configDB list global</code><br/>
|
||||
<code>get configDB list '' 1</code><br/>
|
||||
<code>get configDB list global 1</code><br/>
|
||||
<br/>
|
||||
|
||||
<li><code>configdb diff <device> <version></code></li><br/>
|
||||
Vergleicht die Konfigurationsdaten des Gerätes <device> aus der aktuellen Version 0 mit den Daten aus Version <version><br/>
|
||||
Beispielaufruf:<br/>
|
||||
<br/>
|
||||
<code>get configDB diff telnetPort 1</code><br/>
|
||||
<br/>
|
||||
liefert ein Ergebnis ähnlich dieser Ausgabe:
|
||||
<pre>
|
||||
compare device: telnetPort in current version 0 (left) to version: 1 (right)
|
||||
+--+--------------------------------------+--+--------------------------------------+
|
||||
| 1|define telnetPort telnet 7072 global | 1|define telnetPort telnet 7072 global |
|
||||
* 2|attr telnetPort room telnet * | |
|
||||
+--+--------------------------------------+--+--------------------------------------+</pre>
|
||||
|
||||
<li><code>configdb uuid</code></li><br/>
|
||||
Liefert eine uuid, die man für eigene Zwecke verwenden kann.<br/>
|
||||
<br/>
|
||||
|
||||
<li><code>configdb backup</code></li><br/>
|
||||
Ersetzt den Standard-Backup-Befehl von fhem, da dieser bei Verwendung von configDB nicht mehr<br/>
|
||||
zur Verfügung steht.<br/>
|
||||
<br/>
|
||||
<b>Wichtig:</b><br/>
|
||||
Für die Sicherung der Datenbank ist der Anwender selbst verantwortlich!<br/>
|
||||
Der backup Befehl kann diese Aufgabe nicht übernehmen.<br/>
|
||||
Ausnahme: Nutzer einer im fhem Verzeichnis liegenden sqlite Datenbank profitieren von der Einfachheit<br/>
|
||||
dieser Datenbank, denn das fhem Verzeichnis wird ohnehin komplett gesichert.<br/>
|
||||
<br/>
|
||||
|
||||
<li><code>configdb reorg [keep]</code></li><br/>
|
||||
Löscht alle gespeicherten Konfigurationen mit Versionsnummern größer als [keep].<br/>
|
||||
Standardwert für den optionalen Parameter keep = 3.<br/>
|
||||
Mit dieser Funktion läßt sich eine nächtliche Reorganisation per at umsetzen.<br/>
|
||||
<br/>
|
||||
|
||||
<li><code>configdb recover <version></code></li><br/>
|
||||
Stellt eine ältere Version aus dem Datenbankarchiv wieder her.<br/>
|
||||
<code>set configDB recover 3</code> <b>kopiert</b> die Version #3 aus der Datenbank
|
||||
zur Version #0.<br/>
|
||||
Die ursprüngliche Version #0 wird dabei gelöscht.<br/><br/>
|
||||
<b>Wichtig!</b><br/>
|
||||
Die zurückgeholte Version wird <b>NICHT</b> automatisch aktiviert!<br/>
|
||||
Ein <code>rereadcfg</code> oder - besser - <code>shutdown restart</code> muss manuell erfolgen.<br/>
|
||||
</ul>
|
||||
<br/>
|
||||
<br/>
|
||||
|
||||
<b>Hinweise</b><br/>
|
||||
<br/>
|
||||
<ul>
|
||||
<li>Im Verzeichnis contrib/configDB befinden sich zwei Vorlagen für Datenbank und Konfiguration,<br/>
|
||||
die durch einfaches Kopieren in das fhem Verzeichnis sofort verwendet werden können (Nur für sqlite!).</li>
|
||||
<br/>
|
||||
<li>Der Menüpunkt "Edit files"->"config file" wird bei Verwendung von configDB nicht mehr angezeigt.</li>
|
||||
<br/>
|
||||
<li>Beim Speichern einer Konfiguration nicht ungeduldig werden (egal ob manuell oder durch Klicken auf "save config")<br/>
|
||||
Durch das Schreiben der Versionsinformationen dauert das ein paar Sekunden.<br/>
|
||||
Der Abschluss des Speichern wird durch eine entsprechende Meldung angezeigt.</li>
|
||||
<br/>
|
||||
<li>Diese Erweiterung wird laufend weiterentwickelt. Speziell an der Verbesserung der Performance wird gearbeitet.</li>
|
||||
<br/>
|
||||
<li>Viel Spass!</li>
|
||||
</ul>
|
||||
|
||||
</ul>
|
||||
|
||||
=end html_DE
|
||||
|
||||
=cut
|
256
fhem/configDB.pm
256
fhem/configDB.pm
@ -594,137 +594,14 @@ sub cfgDB_Diff($$) {
|
||||
1;
|
||||
|
||||
=pod
|
||||
|
||||
=begin html
|
||||
|
||||
<a name="configDB"></a>
|
||||
<h3>configDB</h3>
|
||||
<ul>
|
||||
Starting with version 5079, fhem can be used with a configuration database instead of a plain text file (e.g. fhem.cfg).<br/>
|
||||
This offers the possibility to completely waive all cfg-files, "include"-problems and so on.<br/>
|
||||
Furthermore, configDB offers a versioning of several configuration together with the possibility to restore a former configuration.<br/>
|
||||
Access to database is provided via perl's database interface DBI.<br/>
|
||||
<br/>
|
||||
<b>Prerequisits / Installation</b><br/>
|
||||
<ul><br/>
|
||||
<li>You must have access to a SQL database. Supported database types are SQLITE, MYSQL and POSTGRESQL.</li><br/>
|
||||
<li>The corresponding DBD module must be available in your perl environment,<br/>
|
||||
e.g. sqlite3 running on a Debian systems requires package libdbd-sqlite3-perl</li><br/>
|
||||
<li>Create an empty database, e.g. with sqlite3:<br/>
|
||||
<pre>
|
||||
mba:fhem udo$ sqlite3 configDB.db
|
||||
|
||||
SQLite version 3.7.13 2012-07-17 17:46:21
|
||||
Enter ".help" for instructions
|
||||
Enter SQL statements terminated with a ";"
|
||||
sqlite> pragma auto_vacuum=2;
|
||||
sqlite> .quit
|
||||
|
||||
mba:fhem udo$
|
||||
</pre></li>
|
||||
<li>The database tables will be created automatically.</li><br/>
|
||||
<li>Create a configuration file containing the connection string to access database.<br/>
|
||||
<br/>
|
||||
<b>IMPORTANT:</b>
|
||||
<ul><br/>
|
||||
<li>This file <b>must</b> be named "configDB.conf"</li>
|
||||
<li>This file <b>must</b> be located in your fhem main directory, e.g. /opt/fhem</li>
|
||||
</ul>
|
||||
<br/>
|
||||
<pre>
|
||||
## for MySQL
|
||||
################################################################
|
||||
#%dbconfig= (
|
||||
# connection => "mysql:database=configDB;host=db;port=3306",
|
||||
# user => "fhemuser",
|
||||
# password => "fhempassword",
|
||||
#);
|
||||
################################################################
|
||||
#
|
||||
## for PostgreSQL
|
||||
################################################################
|
||||
#%dbconfig= (
|
||||
# connection => "Pg:database=configDB;host=localhost",
|
||||
# user => "fhemuser",
|
||||
# password => "fhempassword"
|
||||
#);
|
||||
################################################################
|
||||
#
|
||||
## for SQLite (username and password stay empty for SQLite)
|
||||
################################################################
|
||||
#%dbconfig= (
|
||||
# connection => "SQLite:dbname=/opt/fhem/configDB.db",
|
||||
# user => "",
|
||||
# password => ""
|
||||
#);
|
||||
################################################################
|
||||
</pre></li><br/>
|
||||
</ul>
|
||||
|
||||
<b>Start with a complete new "fresh" fhem Installation</b><br/>
|
||||
<ul><br/>
|
||||
It's easy... simply start fhem by issuing following command:<br/><br/>
|
||||
<ul><code>perl fhem.pl configDB</code></ul><br/>
|
||||
|
||||
<b>configDB</b> is a keyword which is recognized by fhem to use database for configuration.<br/>
|
||||
<br/>
|
||||
<b>That's all.</b> Everything (save, rereadcfg etc) should work as usual.
|
||||
</ul>
|
||||
|
||||
<br/>
|
||||
<b>or:</b><br/>
|
||||
<br/>
|
||||
|
||||
<b>Migrate your existing fhem configuration into the database</b><br/>
|
||||
<ul><br/>
|
||||
It's easy, too... <br/>
|
||||
<br/>
|
||||
<li>start your fhem the last time with fhem.cfg<br/><br/>
|
||||
<ul><code>perl fhem.pl fhem.cfg</code></ul></li><br/>
|
||||
<br/>
|
||||
<li>transfer your existing configuration into the database<br/><br/>
|
||||
<ul>enter <code>{use configDB;; cfgDB_Migrate}</code><br/>
|
||||
<br/>
|
||||
into frontend's command line</ul><br/></br>
|
||||
Be patient! Migration can take some time, especially on mini-systems like RaspberryPi or Beaglebone.<br/>
|
||||
Completed migration will be indicated by showing database statistics.<br/>
|
||||
Your original configfile will not be touched or modified by this step.</li><br/>
|
||||
<li>shutdown fhem</li><br/>
|
||||
<li>restart fhem with keyword configDB<br/><br/>
|
||||
<ul><code>perl fhem.pl configDB</code></ul></li><br/>
|
||||
<b>configDB</b> is a keyword which is recognized by fhem to use database for configuration.<br/>
|
||||
<br/>
|
||||
<b>That's all.</b> Everything (save, rereadcfg etc) should work as usual.
|
||||
</ul>
|
||||
<br/><br/>
|
||||
|
||||
<b>Additional functions provided</b><br/>
|
||||
<ul><br/>
|
||||
You can define an extension with module <a href="#configDBwrap">98_configDBwrap</a><br/>
|
||||
to gain access to some additional functionality.
|
||||
</ul>
|
||||
<br/>
|
||||
<br/>
|
||||
<b>Author's notes</b><br/>
|
||||
<br/>
|
||||
<ul>
|
||||
<li>You can find two template files for datebase and configfile (sqlite only!) for easy installation.<br/>
|
||||
Just copy them to your fhem installation directory (/opt/fhem) and have fun.</li>
|
||||
<br/>
|
||||
<li>The frontend option "Edit files"->"config file" will be removed when running configDB.</li>
|
||||
<br/>
|
||||
<li>Please be patient when issuing a "save" command
|
||||
(either manually or by clicking on "save config").<br/>
|
||||
This will take some moments, due to writing version informations.<br/>
|
||||
Finishing the save-process will be indicated by a corresponding message in frontend.</li>
|
||||
<br/>
|
||||
<li>You may need to install perl package Text::Diff to use cfgDB_Diff()</li>
|
||||
<br/>
|
||||
<li>There still will be some more (planned) development to this extension,
|
||||
especially regarding some perfomance issues.</li>
|
||||
<br/>
|
||||
<li>Have fun!</li>
|
||||
</ul>
|
||||
|
||||
This is the core library for configuration from SQL database.<br/>
|
||||
See <a href="#configdb">configdb command documentation</a> for detailed info.<br/>
|
||||
</ul>
|
||||
|
||||
=end html
|
||||
@ -734,131 +611,8 @@ sub cfgDB_Diff($$) {
|
||||
<a name="configDB"></a>
|
||||
<h3>configDB</h3>
|
||||
<ul>
|
||||
Seit version 5079 unterstützt fhem die Verwendung einer SQL Datenbank zum Abspeichern der kompletten Konfiguration<br/>
|
||||
Dadurch kann man auf alle cfg Dateien, includes usw. verzichten und die daraus immer wieder resultierenden Probleme vermeiden.<br/>
|
||||
Desweiteren gibt es damit eine Versionierung von Konfigurationen und die Möglichkeit,
|
||||
jederzeit eine ältere Version wiederherstellen zu können.<br/>
|
||||
Der Zugriff auf die Datenbank erfolgt über die perl-eigene Datenbankschnittstelle DBI.<br/>
|
||||
<br/>
|
||||
<b>Voraussetzungen / Installation</b><br/>
|
||||
<ul><br/>
|
||||
<li>Es muss eine SQL Datenbank verfügbar sein, untsrstützt werden SQLITE, MYSQL und POSTGRESQLL.</li><br/>
|
||||
<li>Das zum Datenbanktype gehörende DBD Modul muss in perl installiert sein,<br/>
|
||||
für sqlite3 auf einem Debian System z.B. das Paket libdbd-sqlite3-perl</li><br/>
|
||||
<li>Eine leere Datenbank muss angelegt werden, z.B. in sqlite3:<br/>
|
||||
<pre>
|
||||
mba:fhem udo$ sqlite3 configDB.db
|
||||
|
||||
SQLite version 3.7.13 2012-07-17 17:46:21
|
||||
Enter ".help" for instructions
|
||||
Enter SQL statements terminated with a ";"
|
||||
sqlite> pragma auto_vacuum=2;
|
||||
sqlite> .quit
|
||||
|
||||
mba:fhem udo$
|
||||
</pre></li>
|
||||
<li>Die benötigten Datenbanktabellen werden automatisch angelegt.</li><br/>
|
||||
<li>Eine Konfigurationsdatei für die Verbindung zur Datenbank muss angelegt werden.<br/>
|
||||
<br/>
|
||||
<b>WICHTIG:</b>
|
||||
<ul><br/>
|
||||
<li>Diese Datei <b>muss</b> den Namen "configDB.conf" haben</li>
|
||||
<li>Diese Datei <b>muss</b> im fhem Verzeichnis liegen, z.B. /opt/fhem</li>
|
||||
</ul>
|
||||
<br/>
|
||||
<pre>
|
||||
## für MySQL
|
||||
################################################################
|
||||
#%dbconfig= (
|
||||
# connection => "mysql:database=configDB;host=db;port=3306",
|
||||
# user => "fhemuser",
|
||||
# password => "fhempassword",
|
||||
#);
|
||||
################################################################
|
||||
#
|
||||
## für PostgreSQL
|
||||
################################################################
|
||||
#%dbconfig= (
|
||||
# connection => "Pg:database=configDB;host=localhost",
|
||||
# user => "fhemuser",
|
||||
# password => "fhempassword"
|
||||
#);
|
||||
################################################################
|
||||
#
|
||||
## für SQLite (username and password bleiben bei SQLite leer)
|
||||
################################################################
|
||||
#%dbconfig= (
|
||||
# connection => "SQLite:dbname=/opt/fhem/configDB.db",
|
||||
# user => "",
|
||||
# password => ""
|
||||
#);
|
||||
################################################################
|
||||
</pre></li><br/>
|
||||
</ul>
|
||||
|
||||
<b>Aufruf mit einer vollständig neuen fhem Installation</b><br/>
|
||||
<ul><br/>
|
||||
Sehr einfach... fhem muss lediglich folgendermassen gestartet werden:<br/><br/>
|
||||
<ul><code>perl fhem.pl configDB</code></ul><br/>
|
||||
<b>configDB</b> ist das Schlüsselwort, an dem fhem erkennt, <br/>
|
||||
dass eine Datenbank für die Konfiguration verwendet werden soll.<br/>
|
||||
<br/>
|
||||
<b>Das war es schon.</b> Alle Befehle (save, rereadcfg etc) arbeiten wie gewohnt.
|
||||
</ul>
|
||||
|
||||
<br/>
|
||||
<b>oder:</b><br/>
|
||||
<br/>
|
||||
|
||||
<b>übertragen einer bestehenden fhem Konfiguration in die Datenbank</b><br/>
|
||||
<ul><br/>
|
||||
Auch sehr einfach... <br/>
|
||||
<br/>
|
||||
<li>fhem wird zum letzten Mal mit der fhem.cfg gestartet<br/><br/>
|
||||
<ul><code>perl fhem.pl fhem.cfg</code></ul></li><br/>
|
||||
<br/>
|
||||
<li>Bestehende Konfiguration in die Datenbank übertragen<br/><br/>
|
||||
<ul><code>{use configDB;; cfgDB_Migrate}</code><br/>
|
||||
<br/>
|
||||
in die Befehlszeile der fhem-Oberfläche eingeben</ul><br/></br>
|
||||
Nicht die Geduld verlieren! Die Migration eine Weile dauern, speziell bei Mini-Systemen wie<br/>
|
||||
RaspberryPi or Beaglebone.<br/>
|
||||
Am Ende der Migration wird eine aktuelle Datenbankstatistik angezeigt.<br/>
|
||||
Die ursprüngliche Konfigurationsdatei wird bei diesem Vorgang nicht angetastet.</li><br/>
|
||||
<li>fhem beenden.</li><br/>
|
||||
<li>fhem mit dem Schlüsselwort configDB starten<br/><br/>
|
||||
<ul><code>perl fhem.pl configDB</code></ul></li><br/>
|
||||
<b>configDB</b> ist das Schlüsselwort, an dem fhem erkennt, <br/>
|
||||
dass eine Datenbank für die Konfiguration verwendet werden soll.<br/>
|
||||
<br/>
|
||||
<b>Das war es schon.</b> Alle Befehle (save, rereadcfg etc) arbeiten wie gewohnt.
|
||||
</ul>
|
||||
<br/><br/>
|
||||
|
||||
<b>Zusätzliche Funktionen</b><br/>
|
||||
<ul><br/>
|
||||
Es kann mit Hilfe des Moduls <a href="#configDBwrap">98_configDBwrap</a> eine Erweiterung <br/>
|
||||
definiert werden, die zusätzliche Funktionen bereitstellt.
|
||||
</ul>
|
||||
<br/>
|
||||
<br/>
|
||||
<b>Hinweise</b><br/>
|
||||
<br/>
|
||||
<ul>
|
||||
<li>Im Verzeichnis contrib/configDB befinden sich zwei Vorlagen für Datenbank und Konfiguration,<br/>
|
||||
die durch einfaches Kopieren in das fhem Verzeichnis sofort verwendet werden können (Nur für sqlite!).</li>
|
||||
<br/>
|
||||
<li>Der Menüpunkt "Edit files"->"config file" wird bei Verwendung von configDB nicht mehr angezeigt.</li>
|
||||
<br/>
|
||||
<li>Beim Speichern einer Konfiguration nicht ungeduldig werden (egal ob manuell oder durch Klicken auf "save config")<br/>
|
||||
Durch das Schreiben der Versionsinformationen dauert das ein paar Sekunden.<br/>
|
||||
Der Abschluss des Speichern wird durch eine entsprechende Meldung angezeigt.</li>
|
||||
<br/>
|
||||
<li>Diese Erweiterung wird laufend weiterentwickelt. Speziell an der Verbesserung der Performance wird gearbeitet.</li>
|
||||
<br/>
|
||||
<li>Viel Spass!</li>
|
||||
</ul>
|
||||
|
||||
configDB ist die Funktionsbibliothek für die Konfiguration aus einer SQL Datenbank.<br/>
|
||||
Die ausführliche Dokumentation findet sich in der <a href="#configdb">configdb Befehlsbeschreibung</a>.
|
||||
</ul>
|
||||
|
||||
=end html_DE
|
||||
|
@ -38,6 +38,7 @@
|
||||
<a href="#backup">backup</a>
|
||||
<a href="#CULflash">CULflash</a>
|
||||
<a href="#cmdalias">cmdalias</a>
|
||||
<a href="#configdb">configdb</a>
|
||||
<a href="#createlog">createlog</a>
|
||||
<a href="#define">define</a>
|
||||
<a href="#delete">delete</a>
|
||||
@ -89,7 +90,6 @@
|
||||
<a href="#average">average</a>
|
||||
<a href="#Calendar">Calendar</a>
|
||||
<a href="#configDB">configDB</a>
|
||||
<a href="#configDBwrap">configDBwrap</a>
|
||||
<a href="#Dashboard">Dashboard</a>
|
||||
<a href="#DbLog">DbLog</a>
|
||||
<a href="#dewpoint">dewpoint</a>
|
||||
|
@ -37,6 +37,7 @@
|
||||
<a href="#backup">backup</a>
|
||||
<a href="#CULflash">CULflash</a>
|
||||
<a href="#cmdalias">cmdalias</a>
|
||||
<a href="#configdb">configdb</a>
|
||||
<a href="#createlog">createlog</a>
|
||||
<a href="#define">define</a>
|
||||
<a href="#delete">delete</a>
|
||||
@ -88,7 +89,6 @@
|
||||
<a href="#average">average</a>
|
||||
<a href="#Calendar">Calendar</a>
|
||||
<a href="#configDB">configDB</a>
|
||||
<a href="#configDBwrap">configDBwrap</a>
|
||||
<a href="#Dashboard">Dashboard</a>
|
||||
<a href="#DbLog">DbLog</a>
|
||||
<a href="#dewpoint">dewpoint</a>
|
||||
|
Loading…
x
Reference in New Issue
Block a user