98_configdb.pm 21 KB

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