2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-03-13 17:26:34 +00:00

configDB: new command configdb dump added

git-svn-id: https://svn.fhem.de/fhem/trunk@11494 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
betateilchen 2016-05-22 16:21:33 +00:00
parent 6b75b35306
commit 12aa7c71ef
3 changed files with 34 additions and 0 deletions

View File

@ -1,5 +1,7 @@
# Add changes at the top of the list. Keep it in ASCII, and 80-char wide. # Add changes at the top of the list. Keep it in ASCII, and 80-char wide.
# Do not insert empty lines here, update check depends on it. # Do not insert empty lines here, update check depends on it.
- feature: configDB: new command 'configdb dump' added.
currently only supported for sqlite!
- bugfix: FB_CALLLIST: fix not working calllist when renaming the - bugfix: FB_CALLLIST: fix not working calllist when renaming the
configured FB_CALLMONITOR definition. configured FB_CALLMONITOR definition.
- feature: 10_SOMFY : Added readingFnAttributes - feature: 10_SOMFY : Added readingFnAttributes

View File

@ -5,6 +5,7 @@ package main;
use strict; use strict;
use warnings; use warnings;
use feature qw/say switch/; use feature qw/say switch/;
use POSIX;
use configDB; use configDB;
no if $] >= 5.017011, warnings => 'experimental'; no if $] >= 5.017011, warnings => 'experimental';
@ -57,6 +58,24 @@ sub CommandConfigdb($$) {
} }
} }
when ('dump') {
my $dbtype = _cfgDB_typeInfo();
if ($dbtype eq 'SQLITE') {
my $ts = strftime('%Y-%m-%d_%H-%M-%S',localtime);
my $target = AttrVal('global','modpath','.')."/log/configDB_$ts.dump.gz";
Log3('configdb', 4, "configdb: target for database dump: $target");
my $ret = qx(echo '.dump' | sqlite3 /opt/fhem/configDB.db | gzip -c > $target);
return $ret if $ret; # return error message if available
my $size = -s $target;
$ret = "configDB dumped $size bytes to file\n$target";
# You can use 'zcat $target | sqlite3 configDB.db' in a terminal to restore database.
return $ret;
} else {
return "configdb dump is only supported for sqlite!";
}
}
when ('diff') { when ('diff') {
return "\n Syntax: configdb diff <device> <version>" if @a != 3; return "\n Syntax: configdb diff <device> <version>" if @a != 3;
Log3('configdb', 4, "configdb: diff requested for device: $param1 in version $param2."); Log3('configdb', 4, "configdb: diff requested for device: $param1 in version $param2.");
@ -184,6 +203,7 @@ sub CommandConfigdb($$) {
$ret = "\n Syntax:\n". $ret = "\n Syntax:\n".
" configdb attr [attribute] [value]\n". " configdb attr [attribute] [value]\n".
" configdb diff <device> <version>\n". " configdb diff <device> <version>\n".
" configdb dump\n".
" configDB filedelete <pathToFilename>\n". " configDB filedelete <pathToFilename>\n".
" configDB fileimport <pathToFilename>\n". " configDB fileimport <pathToFilename>\n".
" configDB fileexport <pathToFilename>\n". " configDB fileexport <pathToFilename>\n".
@ -385,6 +405,12 @@ compare device: telnetPort in current version 0 (left) to version: 1 (right)
and UNSAVED version from memory (currently running installation).<br/> and UNSAVED version from memory (currently running installation).<br/>
<br/> <br/>
<li><code>configdb dump</code></li><br/>
Create a dump file from from database.<br/>
Currently only supported for sqlite!<br/>
<br/>
<br/>
<li><code>configdb filedelete &lt;Filename&gt;</code></li><br/> <li><code>configdb filedelete &lt;Filename&gt;</code></li><br/>
Delete file from database.<br/> Delete file from database.<br/>
<br/> <br/>

View File

@ -107,6 +107,8 @@
# #
# 2016-03-26 - added log entry for search (verbose=5) # 2016-03-26 - added log entry for search (verbose=5)
# #
# 2016-05-22 - added configdb dump (for sqlite only!)
#
############################################################################## ##############################################################################
# #
@ -151,6 +153,7 @@ sub _cfgDB_Filedelete($);
sub _cfgDB_Fileexport($;$); sub _cfgDB_Fileexport($;$);
sub _cfgDB_Filelist(;$); sub _cfgDB_Filelist(;$);
sub _cfgDB_Info(); sub _cfgDB_Info();
sub _cfgDB_typeInfo();
sub _cfgDB_Migrate(); sub _cfgDB_Migrate();
sub _cfgDB_ReadCfg(@); sub _cfgDB_ReadCfg(@);
sub _cfgDB_ReadState(@); sub _cfgDB_ReadState(@);
@ -817,6 +820,9 @@ sub _cfgDB_Info() {
return join("\n", @r); return join("\n", @r);
} }
# return database type
sub _cfgDB_typeInfo() { return $cfgDB_dbtype; }
# recover former config from database archive # recover former config from database archive
sub _cfgDB_Recover($) { sub _cfgDB_Recover($) {
my ($version) = @_; my ($version) = @_;