98_configdb.pm 21 KB

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