functional

but become error then file upload
	geändert:       lib/FHEM/backupToStorage.pm
This commit is contained in:
Marko Oldenburg 2020-06-17 16:57:08 +02:00
parent c04aa3314e
commit d9673cece4
2 changed files with 24 additions and 19 deletions

View File

@ -1,2 +1,2 @@
UPD 2020-06-17_15:03:50 3368 FHEM/98_backupToStorage.pm UPD 2020-06-17_15:03:50 3368 FHEM/98_backupToStorage.pm
UPD 2020-06-17_16:27:41 10991 lib/FHEM/backupToStorage.pm UPD 2020-06-17_16:56:54 11187 lib/FHEM/backupToStorage.pm

View File

@ -47,6 +47,7 @@ BEGIN {
GP_Import( GP_Import(
qw( qw(
readingsSingleUpdate readingsSingleUpdate
ReadingsVal
defs defs
modules modules
setKeyValue setKeyValue
@ -59,7 +60,8 @@ BEGIN {
deviceEvents deviceEvents
init_done init_done
devspec2array devspec2array
DoTrigger) DoTrigger
HttpUtils_NonblockingGet)
); );
} }
@ -133,8 +135,10 @@ sub Notify {
. Dumper $events); # mit Dumper . Dumper $events); # mit Dumper
PushToStorage($hash) PushToStorage($hash)
if ( grep m{^backup done$}xms, if ( (grep m{^backup.done(.+)?$}xms, @{$events})
@{$events} && $devname eq 'global' && $init_done ); && $devname eq 'global'
&& $init_done
);
CheckAttributsForCredentials($hash) CheckAttributsForCredentials($hash)
if ( if (
@ -173,8 +177,9 @@ sub Notify {
) )
if ( if (
( (
grep m{^DEFINED.$name$}xms, (grep m{^DEFINED.$name$}xms,@{$events})
@{$events} && $devname eq 'global' && $init_done && $devname eq 'global'
&& $init_done
) )
|| ( || (
grep m{^INITIALIZED$}xms, grep m{^INITIALIZED$}xms,
@ -233,11 +238,11 @@ sub PushToStorage {
my $name = $hash->{NAME}; my $name = $hash->{NAME};
Log3 $name, 4, "backupToStorage ($name) - push to storage function"; Log3($name, 4, "backupToStorage ($name) - push to storage function");
if ( AttrVal( $name, 'bTSType', 'Nextcloud' ) eq 'Nextcloud' ) { if ( AttrVal( $name, 'bTSType', 'Nextcloud' ) eq 'Nextcloud' ) {
Log3 $name, 4, Log3($name, 4,
"backupToStorage ($name) - push to storage function: Nextcloud detected"; "backupToStorage ($name) - push to storage function: Nextcloud detected");
ncUpload( $hash, ReadingsVal( $name, 'fhemBackupFile', 'none' ) ); ncUpload( $hash, ReadingsVal( $name, 'fhemBackupFile', 'none' ) );
} }
@ -250,7 +255,7 @@ sub ncUpload {
my $name = $hash->{NAME}; my $name = $hash->{NAME};
Log3 $name, 4, "backupToStorage ($name) - nextcloud upload function"; Log3($name, 4, "backupToStorage ($name) - nextcloud upload function");
open FD, '<', open FD, '<',
"$backupFile" "$backupFile"
@ -280,13 +285,13 @@ sub ncUpload {
. $ncUser . '/' . $ncUser . '/'
. $ncPath . '/' . $ncPath . '/'
. $fhemBackupFile, . $fhemBackupFile,
timeout => AttrVal( $name, 'btS_UploadTimeout', 30 ), timeout => AttrVal( $name, 'btS_UploadTimeout', 15 ),
method => 'PUT', method => 'PUT',
data => $cont, data => $cont,
hash => $hash, hash => $hash,
user => $ncUser, user => $ncUser,
pwd => $ncPass, pwd => $ncPass,
callback => \&FHEM::backup::ncUploadCb, callback => \&FHEM::backupToStorage::ncUploadCb,
}; };
HttpUtils_NonblockingGet($param); HttpUtils_NonblockingGet($param);
@ -303,9 +308,9 @@ sub ncUploadCb {
my $hash = $param->{hash}; my $hash = $param->{hash};
my $name = $hash->{NAME}; my $name = $hash->{NAME};
Log( 1, 'backup URL: ' . $param->{url} ); Log3($name, 1, "backupToStorage ($name) - backup URL: $param->{url}");
Log( 1, 'backup User: ' . $param->{user} ); Log3($name, 1, "backupToStorage ($name) - backup User: $param->{user}");
Log( 1, 'backup Pass: ' . $param->{pwd} ); Log3($name, 1, "backupToStorage ($name) - backup Pass: $param->{pwd}");
Log3( Log3(
$name, 3, $name, 3,
@ -360,14 +365,14 @@ sub ReadPassword {
my $key = getUniqueId() . $index; my $key = getUniqueId() . $index;
my ( $password, $err ); my ( $password, $err );
Log3 $name, 4, "backupToStorage ($name) - Read password from file"; Log3($name, 4, "backupToStorage ($name) - Read password from file");
( $err, $password ) = getKeyValue($index); ( $err, $password ) = getKeyValue($index);
if ( defined($err) ) { if ( defined($err) ) {
Log3 $name, 3, Log3($name, 3,
"backupToStorage ($name) - unable to read password from file: $err"; "backupToStorage ($name) - unable to read password from file: $err");
return undef; return undef;
} }
@ -389,7 +394,7 @@ sub ReadPassword {
return $dec_pwd; return $dec_pwd;
} }
else { else {
Log3 $name, 3, "backupToStorage ($name) - No password in file"; Log3($name, 3, "backupToStorage ($name) - No password in file");
return undef; return undef;
} }