98_configdb.pm 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668
  1. # $Id: 98_configdb.pm 16218 2018-02-18 19:23:23Z betateilchen $
  2. #
  3. package main;
  4. use strict;
  5. use warnings;
  6. use feature qw/say switch/;
  7. use POSIX;
  8. use configDB;
  9. no if $] >= 5.017011, warnings => 'experimental';
  10. sub CommandConfigdb($$);
  11. sub _cfgDB_readConfig();
  12. my @pathname;
  13. sub configdb_Initialize($$) {
  14. my %hash = ( Fn => "CommandConfigdb",
  15. Hlp => "help ,access additional functions from configDB" );
  16. $cmds{configdb} = \%hash;
  17. }
  18. sub CommandConfigdb($$) {
  19. my ($cl, $param) = @_;
  20. my @a = split("[ \t][ \t]*", $param);
  21. my ($cmd, $param1, $param2) = @a;
  22. $cmd //= "";
  23. $param1 //= "";
  24. $param2 //= "";
  25. my $configfile = $attr{global}{configfile};
  26. return "\n error: configDB not used!" unless($configfile eq 'configDB' || $cmd eq 'migrate');
  27. my $ret;
  28. given ($cmd) {
  29. when ('attr') {
  30. Log3('configdb', 4, "configdb: attr $param1 $param2 requested.");
  31. if ($param1 eq "" && $param2 eq "") {
  32. # list attributes
  33. foreach my $c (sort keys %{$configDB{attr}}) {
  34. my $val = $configDB{attr}{$c};
  35. $val =~ s/;/;;/g;
  36. $val =~ s/\n/\\\n/g;
  37. $ret .= "configdb attr $c $val\n";
  38. }
  39. } elsif($param2 eq "") {
  40. # delete attribute
  41. delete $configDB{attr}{$param1};
  42. $ret = " attribute $param1 deleted";
  43. } else {
  44. # set attribute
  45. $configDB{attr}{$param1} = $param2;
  46. $ret = " attribute $param1 set to value $param2";
  47. }
  48. }
  49. when ('dump') {
  50. return _cfgDB_dump($param1);
  51. }
  52. # my ($dbconn,$dbuser,$dbpass,$dbtype) = _cfgDB_readConfig();
  53. # my ($dbname,$dbhostname,$dbport,$gzip,$mp,$ret,$size,$source,$target,$ts);
  54. # $ts = strftime('%Y-%m-%d_%H-%M-%S',localtime);
  55. # $mp = $configDB{attr}{'dumpPath'};
  56. # $mp //= AttrVal('global','modpath','.').'/log';
  57. # $target = "$mp/configDB_$ts.dump";
  58. #
  59. # if (lc($param1) eq 'unzipped') {
  60. # $gzip = '';
  61. # } else {
  62. # $gzip = '| gzip -c';
  63. # $target .= '.gz';
  64. # }
  65. #
  66. # if ($dbtype eq 'SQLITE') {
  67. # (undef,$source) = split (/=/, $dbconn);
  68. # my $dumpcmd = "echo '.dump fhem%' | sqlite3 $source $gzip > $target";
  69. # Log 4,"configDB: $dumpcmd";
  70. # $ret = qx($dumpcmd);
  71. # return $ret if $ret; # return error message if available
  72. #
  73. # } elsif ($dbtype eq 'MYSQL') {
  74. # ($dbname,$dbhostname,$dbport) = split (/;/,$dbconn);
  75. # $dbport //= '=3306';
  76. # (undef,$dbname) = split (/=/,$dbname);
  77. # (undef,$dbhostname) = split (/=/,$dbhostname);
  78. # (undef,$dbport) = split (/=/,$dbport);
  79. # my $dbtables = "fhemversions fhemconfig fhemstate fhemb64filesave";
  80. # my $dumpcmd = "mysqldump --user=$dbuser --password=$dbpass --host=$dbhostname --port=$dbport -Q $dbname $dbtables $gzip > $target";
  81. # Log 4,"configDB: $dumpcmd";
  82. # $ret = qx($dumpcmd);
  83. # return $ret if $ret;
  84. # $source = $dbname;
  85. #
  86. # } elsif ($dbtype eq 'POSTGRESQL') {
  87. # ($dbname,$dbhostname,$dbport) = split (/;/,$dbconn);
  88. # $dbport //= '=5432';
  89. # (undef,$dbname) = split (/=/,$dbname);
  90. # (undef,$dbhostname) = split (/=/,$dbhostname);
  91. # (undef,$dbport) = split (/=/,$dbport);
  92. # my $dbtables = "-t fhemversions -t fhemconfig -t fhemstate -t fhemb64filesave";
  93. # my $dumpcmd = "PGPASSWORD=$dbpass pg_dump -U $dbuser -h $dbhostname -p $dbport $dbname $dbtables $gzip > $target";
  94. # Log 4,"configDB: $dumpcmd";
  95. # $ret = qx($dumpcmd);
  96. # return $ret if $ret;
  97. # $source = $dbname;
  98. #
  99. # } else {
  100. # return "configdb dump not supported for $dbtype!";
  101. # }
  102. #
  103. # $size = -s $target;
  104. # $size //= 0;
  105. # $ret = "configDB dumped $size bytes\nfrom: $source\n to: $target";
  106. # return $ret;
  107. # }
  108. when ('diff') {
  109. return "\n Syntax: configdb diff <device> <version>" if @a != 3;
  110. Log3('configdb', 4, "configdb: diff requested for device: $param1 in version $param2.");
  111. $ret = _cfgDB_Diff($param1, $param2);
  112. }
  113. when ('filedelete') {
  114. return "\n Syntax: configdb filedelete <pathToFile>" if @a != 2;
  115. my $filename;
  116. if($param1 =~ m,^[./],) {
  117. $filename = $param1;
  118. } else {
  119. $filename = $attr{global}{modpath};
  120. $filename .= "/$param1";
  121. }
  122. $ret = "File $filename ";
  123. $ret .= defined(_cfgDB_Filedelete($filename)) ? "deleted from" : "not found in";
  124. $ret .= " database.";
  125. }
  126. when ('fileexport') {
  127. return "\n Syntax: configdb fileexport <pathToFile>" if @a != 2;
  128. if ($param1 ne 'all') {
  129. my $filename;
  130. if($param1 =~ m,^[./],) {
  131. $filename = $param1;
  132. } else {
  133. $filename = $attr{global}{modpath};
  134. $filename .= "/$param1";
  135. }
  136. $ret = _cfgDB_Fileexport $filename;
  137. } else { # start export all
  138. my $flist = _cfgDB_Filelist(1);
  139. my @filelist = split(/\n/,$flist);
  140. undef $flist;
  141. foreach my $f (@filelist) {
  142. Log3 (4,undef,"configDB: exporting $f");
  143. my ($path,$file) = $f =~ m|^(.*[/\\])([^/\\]+?)$|;
  144. $path = "/tmp/$path";
  145. eval qx(mkdir -p $path) unless (-e "$path");
  146. $ret .= _cfgDB_Fileexport $f;
  147. $ret .= "\n";
  148. }
  149. } # end export all
  150. }
  151. when ('fileimport') {
  152. return "\n Syntax: configdb fileimport <pathToFile>" if @a != 2;
  153. my $filename;
  154. if($param1 =~ m,^[./],) {
  155. $filename = $param1;
  156. } else {
  157. $filename = $attr{global}{modpath};
  158. $filename .= "/$param1";
  159. }
  160. if ( -r $filename ) {
  161. my $filesize = -s $filename;
  162. $ret = _cfgDB_binFileimport($filename,$filesize);
  163. } elsif ( -e $filename) {
  164. $ret = "\n Read error on file $filename";
  165. } else {
  166. $ret = "\n File $filename not found.";
  167. }
  168. }
  169. when ('filelist') {
  170. return _cfgDB_Filelist;
  171. }
  172. when ('filemove') {
  173. return "\n Syntax: configdb filemove <pathToFile>" if @a != 2;
  174. my $filename;
  175. if($param1 =~ m,^[./],) {
  176. $filename = $param1;
  177. } else {
  178. $filename = $attr{global}{modpath};
  179. $filename .= "/$param1";
  180. }
  181. if ( -r $filename ) {
  182. my $filesize = -s $filename;
  183. $ret = _cfgDB_binFileimport ($filename,$filesize,1);
  184. $ret .= "\nFile $filename deleted from local filesystem.";
  185. } elsif ( -e $filename) {
  186. $ret = "\n Read error on file $filename";
  187. } else {
  188. $ret = "\n File $filename not found.";
  189. }
  190. }
  191. when ('fileshow') {
  192. return "\n Syntax: configdb fileshow <pathToFile>" if @a != 2;
  193. my @rets = cfgDB_FileRead($param1);
  194. my $r = (int(@rets)) ? join "\n",@rets : "File $param1 not found in database.";
  195. return $r;
  196. }
  197. when ('info') {
  198. Log3('configdb', 4, "info requested.");
  199. $ret = _cfgDB_Info('$Id: 98_configdb.pm 16218 2018-02-18 19:23:23Z betateilchen $');
  200. }
  201. when ('list') {
  202. $param1 = $param1 ? $param1 : '%';
  203. $param2 = $param2 ? $param2 : 0;
  204. $ret = "list not allowed for configDB itself.";
  205. break if($param1 =~ m/configdb/i);
  206. Log3('configdb', 4, "configdb: list requested for device: $param1 in version $param2.");
  207. $ret = _cfgDB_Search($param1,$param2,1);
  208. }
  209. when ('migrate') {
  210. return "\n Migration not possible. Already running with configDB!" if $configfile eq 'configDB';
  211. Log3('configdb', 4, "configdb: migration requested.");
  212. $ret = _cfgDB_Migrate;
  213. }
  214. when ('recover') {
  215. return "\n Syntax: configdb recover <version>" if @a != 2;
  216. Log3('configdb', 4, "configdb: recover for version $param1 requested.");
  217. $ret = _cfgDB_Recover($param1);
  218. }
  219. when ('reorg') {
  220. # $param1 = $param1 ? $param1 : 3;
  221. $param1 //= 3;
  222. Log3('configdb', 4, "configdb: reorg requested with keep: $param1.");
  223. $ret = _cfgDB_Reorg($a[1]);
  224. }
  225. when ('search') {
  226. return "\n Syntax: configdb search <searchTerm> [searchVersion]" if @a < 2;
  227. $param1 = $param1 ? $param1 : '%';
  228. $param2 = $param2 ? $param2 : 0;
  229. Log3('configdb', 4, "configdb: list requested for device: $param1 in version $param2.");
  230. $ret = _cfgDB_Search($param1,$param2);
  231. }
  232. when ('uuid') {
  233. $param1 = _cfgDB_Uuid;
  234. Log3('configdb', 4, "configdb: uuid requested: $param1");
  235. $ret = $param1;
  236. }
  237. default {
  238. $ret = "\n Syntax:\n".
  239. " configdb attr [attribute] [value]\n".
  240. " configdb diff <device> <version>\n".
  241. " configdb dump\n".
  242. " configDB filedelete <pathToFilename>\n".
  243. " configDB fileimport <pathToFilename>\n".
  244. " configDB fileexport <pathToFilename>\n".
  245. " configDB filelist\n".
  246. " configDB filemove <pathToFilename>\n".
  247. " configDB fileshow <pathToFilename>\n".
  248. " configdb info\n".
  249. " configdb list [device] [version]\n".
  250. " configdb migrate\n".
  251. " configdb recover <version>\n".
  252. " configdb reorg [keepVersions]\n".
  253. " configdb search <searchTerm> [version]\n".
  254. " configdb uuid\n".
  255. "";
  256. }
  257. }
  258. return $ret;
  259. }
  260. sub _cfgDB_readConfig() {
  261. if(!open(CONFIG, 'configDB.conf')) {
  262. Log3('configDB', 1, 'Cannot open database configuration file configDB.conf');
  263. return 0;
  264. }
  265. my @config=<CONFIG>;
  266. close(CONFIG);
  267. use vars qw(%configDB);
  268. my %dbconfig;
  269. eval join("", @config);
  270. my $cfgDB_dbconn = $dbconfig{connection};
  271. my $cfgDB_dbuser = $dbconfig{user};
  272. my $cfgDB_dbpass = $dbconfig{password};
  273. my $cfgDB_dbtype;
  274. %dbconfig = ();
  275. @config = ();
  276. if($cfgDB_dbconn =~ m/pg:/i) {
  277. $cfgDB_dbtype ="POSTGRESQL";
  278. } elsif ($cfgDB_dbconn =~ m/mysql:/i) {
  279. $cfgDB_dbtype = "MYSQL";
  280. } elsif ($cfgDB_dbconn =~ m/sqlite:/i) {
  281. $cfgDB_dbtype = "SQLITE";
  282. } else {
  283. $cfgDB_dbtype = "unknown";
  284. }
  285. return($cfgDB_dbconn,$cfgDB_dbuser,$cfgDB_dbpass,$cfgDB_dbtype);
  286. }
  287. 1;
  288. =pod
  289. =item command
  290. =item summary frontend command for configDB configuration
  291. =item summary_DE Befehl zur Konfiguration der configDB
  292. =begin html
  293. <a name="configdb"></a>
  294. <h3>configdb</h3>
  295. <ul>
  296. <a href="https://forum.fhem.de/index.php?board=46.0">Link to FHEM forum</a><br/><br/>
  297. Starting with version 5079, fhem can be used with a configuration database instead of a plain text file (e.g. fhem.cfg).<br/>
  298. This offers the possibility to completely waive all cfg-files, "include"-problems and so on.<br/>
  299. Furthermore, configDB offers a versioning of several configuration together with the possibility to restore a former configuration.<br/>
  300. Access to database is provided via perl's database interface DBI.<br/>
  301. <br/>
  302. <b>Interaction with other modules</b><br/>
  303. <ul><br/>
  304. Currently the fhem modules<br/>
  305. <br/>
  306. <li>02_RSS.pm</li>
  307. <li>55_InfoPanel.pm</li>
  308. <li>91_eventTypes</li>
  309. <li>93_DbLog.pm</li>
  310. <li>95_holiday.pm</li>
  311. <li>98_SVG.pm</li>
  312. <br/>
  313. will use configDB to read their configuration data from database<br/>
  314. instead of formerly used configuration files inside the filesystem.<br/>
  315. <br/>
  316. This requires you to import your configuration files from filesystem into database.<br/>
  317. <br/>
  318. Example:<br/>
  319. <code>configdb fileimport FHEM/nrw.holiday</code><br/>
  320. <code>configdb fileimport FHEM/myrss.layout</code><br/>
  321. <code>configdb fileimport www/gplot/xyz.gplot</code><br/>
  322. <br/>
  323. <b>This does not affect the definitons of your holiday or RSS entities.</b><br/>
  324. <br/>
  325. <b>During migration all external configfiles used in current configuration<br/>
  326. will be imported aufmatically.</b><br>
  327. <br/>
  328. Each fileimport into database will overwrite the file if it already exists in database.<br/>
  329. <br/>
  330. </ul><br/>
  331. <br/>
  332. <b>Prerequisits / Installation</b><br/>
  333. <ul><br/>
  334. <li>Please install perl package Text::Diff if not already installed on your system.</li><br/>
  335. <li>You must have access to a SQL database. Supported database types are SQLITE, MYSQL and POSTGRESQL.</li><br/>
  336. <li>The corresponding DBD module must be available in your perl environment,<br/>
  337. e.g. sqlite3 running on a Debian systems requires package libdbd-sqlite3-perl</li><br/>
  338. <li>Create an empty database, e.g. with sqlite3:<br/>
  339. <pre>
  340. mba:fhem udo$ sqlite3 configDB.db
  341. SQLite version 3.7.13 2012-07-17 17:46:21
  342. Enter ".help" for instructions
  343. Enter SQL statements terminated with a ";"
  344. sqlite> pragma auto_vacuum=2;
  345. sqlite> .quit
  346. mba:fhem udo$
  347. </pre></li>
  348. <li>The database tables will be created automatically.</li><br/>
  349. <li>Create a configuration file containing the connection string to access database.<br/>
  350. <br/>
  351. <b>IMPORTANT:</b>
  352. <ul><br/>
  353. <li>This file <b>must</b> be named "configDB.conf"</li>
  354. <li>This file <b>must</b> be located in the same directory containing fhem.pl and configDB.pm, e.g. /opt/fhem</li>
  355. </ul>
  356. <br/>
  357. <pre>
  358. ## for MySQL
  359. ################################################################
  360. #%dbconfig= (
  361. # connection => "mysql:database=configDB;host=db;port=3306",
  362. # user => "fhemuser",
  363. # password => "fhempassword",
  364. #);
  365. ################################################################
  366. #
  367. ## for PostgreSQL
  368. ################################################################
  369. #%dbconfig= (
  370. # connection => "Pg:database=configDB;host=localhost",
  371. # user => "fhemuser",
  372. # password => "fhempassword"
  373. #);
  374. ################################################################
  375. #
  376. ## for SQLite (username and password stay empty for SQLite)
  377. ################################################################
  378. #%dbconfig= (
  379. # connection => "SQLite:dbname=/opt/fhem/configDB.db",
  380. # user => "",
  381. # password => ""
  382. #);
  383. ################################################################
  384. </pre></li><br/>
  385. </ul>
  386. <b>Start with a complete new "fresh" fhem Installation</b><br/>
  387. <ul><br/>
  388. It's easy... simply start fhem by issuing following command:<br/><br/>
  389. <ul><code>perl fhem.pl configDB</code></ul><br/>
  390. <b>configDB</b> is a keyword which is recognized by fhem to use database for configuration.<br/>
  391. <br/>
  392. <b>That's all.</b> Everything (save, rereadcfg etc) should work as usual.
  393. </ul>
  394. <br/>
  395. <b>or:</b><br/>
  396. <br/>
  397. <b>Migrate your existing fhem configuration into the database</b><br/>
  398. <ul><br/>
  399. It's easy, too... <br/>
  400. <br/>
  401. <li>start your fhem the last time with fhem.cfg<br/><br/>
  402. <ul><code>perl fhem.pl fhem.cfg</code></ul></li><br/>
  403. <br/>
  404. <li>transfer your existing configuration into the database<br/><br/>
  405. <ul>enter<br/><br/><code>configdb migrate</code><br/>
  406. <br/>
  407. into frontend's command line</ul><br/></br>
  408. Be patient! Migration can take some time, especially on mini-systems like RaspberryPi or Beaglebone.<br/>
  409. Completed migration will be indicated by showing database statistics.<br/>
  410. Your original configfile will not be touched or modified by this step.</li><br/>
  411. <li>shutdown fhem</li><br/>
  412. <li>restart fhem with keyword configDB<br/><br/>
  413. <ul><code>perl fhem.pl configDB</code></ul></li><br/>
  414. <b>configDB</b> is a keyword which is recognized by fhem to use database for configuration.<br/>
  415. <br/>
  416. <b>That's all.</b> Everything (save, rereadcfg etc) should work as usual.
  417. </ul>
  418. <br/><br/>
  419. <b>Additional functions provided</b><br/>
  420. <ul><br/>
  421. A new command <code>configdb</code> is propagated to fhem.<br/>
  422. This command can be used with different parameters.<br/>
  423. <br/>
  424. <li><code>configdb attr [attribute] [value]</code></li><br/>
  425. Provides the possibility to pass attributes to backend and frontend.<br/>
  426. <br/>
  427. <code> configdb attr private 1</code> - set the attribute named 'private' to value 1.<br/>
  428. <br/>
  429. <code> configdb attr private</code> - delete the attribute named 'private'<br/>
  430. <br/>
  431. <code> configdb attr</code> - show all defined attributes.<br/>
  432. <br/>
  433. <ul>Supported attributes:</ul>
  434. <br/>
  435. <ul><b>deleteimported</b> if set to 1 files will always be deleted from filesystem after import to database.<br/></ul><br/>
  436. <ul><b>maxversions</b> set the maximum number of configurations stored in database. <br/>
  437. The oldest version will be dropped in a "save config" if it would exceed this number.</ul><br/>
  438. <ul><b>private</b> if set to 1 the user and password info will not be shown in 'configdb info' output.</ul><br/>
  439. <ul><b>useCache</b> (experimental!) if set to 1 fileread from database will be cached.</ul><br/>
  440. <br/>
  441. <li><code>configdb diff &lt;device&gt; &lt;version&gt;</code></li><br/>
  442. Compare configuration dataset for device &lt;device&gt;
  443. from current version 0 with version &lt;version&gt;<br/>
  444. Example for valid request:<br/>
  445. <br/>
  446. <code>configdb diff telnetPort 1</code><br/>
  447. <br/>
  448. will show a result like this:
  449. <pre>
  450. compare device: telnetPort in current version 0 (left) to version: 1 (right)
  451. +--+--------------------------------------+--+--------------------------------------+
  452. | 1|define telnetPort telnet 7072 global | 1|define telnetPort telnet 7072 global |
  453. * 2|attr telnetPort room telnet * | |
  454. +--+--------------------------------------+--+--------------------------------------+</pre>
  455. <b>Special: configdb diff all current</b><br/>
  456. <br/>
  457. Will show a diff table containing all changes between saved version 0<br/>
  458. and UNSAVED version from memory (currently running installation).<br/>
  459. <br/>
  460. <li><code>configdb dump [unzipped]</code></li><br/>
  461. Create a gzipped dump file from from database.<br/>
  462. If optional parameter 'unzipped' provided, dump file will be written unzipped.<br/>
  463. <br/>
  464. <br/>
  465. <li><code>configdb filedelete &lt;Filename&gt;</code></li><br/>
  466. Delete file from database.<br/>
  467. <br/>
  468. <br/>
  469. <li><code>configdb fileexport &lt;targetFilename&gt;|all</code></li><br/>
  470. Exports specified file (or all files) from database into filesystem.<br/>
  471. Example:<br/>
  472. <br/>
  473. <code>configdb fileexport FHEM/99_myUtils.pm</code><br/>
  474. <br/>
  475. <br/>
  476. <li><code>configdb fileimport &lt;sourceFilename&gt;</code></li><br/>
  477. Imports specified text file from from filesystem into database.<br/>
  478. Example:<br/>
  479. <br/>
  480. <code>configdb fileimport FHEM/99_myUtils.pm</code><br/>
  481. <br/>
  482. <br/>
  483. <li><code>configdb filelist</code></li><br/>
  484. Show a list with all filenames stored in database.<br/>
  485. <br/>
  486. <br/>
  487. <li><code>configdb filemove &lt;sourceFilename&gt;</code></li><br/>
  488. Imports specified fhem file from from filesystem into database and<br/>
  489. deletes the file from local filesystem afterwards.<br/>
  490. Example:<br/>
  491. <br/>
  492. <code>configdb filemove FHEM/99_myUtils.pm</code><br/>
  493. <br/>
  494. <br/>
  495. <li><code>configdb fileshow &lt;Filename&gt;</code></li><br/>
  496. Show content of specified file stored in database.<br/>
  497. <br/>
  498. <br/>
  499. <li><code>configdb info</code></li><br/>
  500. Returns some database statistics<br/>
  501. <pre>
  502. --------------------------------------------------------------------------------
  503. configDB Database Information
  504. --------------------------------------------------------------------------------
  505. dbconn: SQLite:dbname=/opt/fhem/configDB.db
  506. dbuser:
  507. dbpass:
  508. dbtype: SQLITE
  509. --------------------------------------------------------------------------------
  510. fhemconfig: 7707 entries
  511. Ver 0 saved: Sat Mar 1 11:37:00 2014 def: 293 attr: 1248
  512. Ver 1 saved: Fri Feb 28 23:55:13 2014 def: 293 attr: 1248
  513. Ver 2 saved: Fri Feb 28 23:49:01 2014 def: 293 attr: 1248
  514. Ver 3 saved: Fri Feb 28 22:24:40 2014 def: 293 attr: 1247
  515. Ver 4 saved: Fri Feb 28 22:14:03 2014 def: 293 attr: 1246
  516. --------------------------------------------------------------------------------
  517. fhemstate: 1890 entries saved: Sat Mar 1 12:05:00 2014
  518. --------------------------------------------------------------------------------
  519. </pre>
  520. Ver 0 always indicates the currently running configuration.<br/>
  521. <br/>
  522. <li><code>configdb list [device] [version]</code></li><br/>
  523. Search for device named [device] in configuration version [version]<br/>
  524. in database archive.<br/>
  525. Default value for [device] = % to show all devices.<br/>
  526. Default value for [version] = 0 to show devices from current version.<br/>
  527. Examples for valid requests:<br/>
  528. <br/>
  529. <code>get configDB list</code><br/>
  530. <code>get configDB list global</code><br/>
  531. <code>get configDB list '' 1</code><br/>
  532. <code>get configDB list global 1</code><br/>
  533. <br/>
  534. <li><code>configdb recover &lt;version&gt;</code></li><br/>
  535. Restores an older version from database archive.<br/>
  536. <code>configdb recover 3</code> will <b>copy</b> version #3 from database
  537. to version #0.<br/>
  538. Original version #0 will be lost.<br/><br/>
  539. <b>Important!</b><br/>
  540. The restored version will <b>NOT</b> be activated automatically!<br/>
  541. You must do a <code>rereadcfg</code> or - even better - <code>shutdown restart</code> yourself.<br/>
  542. <br/>
  543. <li><code>configdb reorg [keep]</code></li><br/>
  544. Deletes all stored versions with version number higher than [keep].<br/>
  545. Default value for optional parameter keep = 3.<br/>
  546. This function can be used to create a nightly running job for<br/>
  547. database reorganisation when called from an at-Definition.<br/>
  548. <br/>
  549. <li><code>configdb search <searchTerm> [searchVersion]</code></li><br/>
  550. Search for specified searchTerm in any given version (default=0)<br/>
  551. <pre>
  552. Example:
  553. configdb search %2286BC%
  554. Result:
  555. search result for: %2286BC% in version: 0
  556. --------------------------------------------------------------------------------
  557. define az_RT CUL_HM 2286BC
  558. define az_RT_Clima CUL_HM 2286BC04
  559. define az_RT_Climate CUL_HM 2286BC02
  560. define az_RT_ClimaTeam CUL_HM 2286BC05
  561. define az_RT_remote CUL_HM 2286BC06
  562. define az_RT_Weather CUL_HM 2286BC01
  563. define az_RT_WindowRec CUL_HM 2286BC03
  564. attr Melder_FAl peerIDs 00000000,2286BC03,
  565. attr Melder_FAr peerIDs 00000000,2286BC03,
  566. </pre>
  567. <br/>
  568. <li><code>configdb uuid</code></li><br/>
  569. Returns a uuid that can be used for own purposes.<br/>
  570. <br/>
  571. </ul>
  572. <br/>
  573. <br/>
  574. <b>Author's notes</b><br/>
  575. <br/>
  576. <ul>
  577. <li>You can find two template files for datebase and configfile (sqlite only!) for easy installation.<br/>
  578. Just copy them to your fhem installation directory (/opt/fhem) and have fun.</li>
  579. <br/>
  580. <li>The frontend option "Edit files"-&gt;"config file" will be removed when running configDB.</li>
  581. <br/>
  582. <li>Please be patient when issuing a "save" command
  583. (either manually or by clicking on "save config").<br/>
  584. This will take some moments, due to writing version informations.<br/>
  585. Finishing the save-process will be indicated by a corresponding message in frontend.</li>
  586. <br/>
  587. <li>There still will be some more (planned) development to this extension,
  588. especially regarding some perfomance issues.</li>
  589. <br/>
  590. <li>Have fun!</li>
  591. </ul>
  592. </ul>
  593. =end html
  594. =cut