mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-05-04 22:19:38 +00:00
98_backup: add support for backupToStorage modul
git-svn-id: https://svn.fhem.de/fhem/trunk/fhem@22190 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
a47151c64e
commit
c98b5a0f83
1
CHANGED
1
CHANGED
@ -1,5 +1,6 @@
|
|||||||
# 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: 98_backup: add support for backupToStorage modul
|
||||||
- changed: 70_BRAVIA: use audio service instead of upnp access
|
- changed: 70_BRAVIA: use audio service instead of upnp access
|
||||||
- changed: 76_SMAPortal: add check login Templates, multiple choice for attr
|
- changed: 76_SMAPortal: add check login Templates, multiple choice for attr
|
||||||
verbose5Data
|
verbose5Data
|
||||||
|
@ -1,10 +1,13 @@
|
|||||||
################################################################
|
################################################################
|
||||||
# Developed with Kate
|
# Developed with Kate
|
||||||
#
|
#
|
||||||
# (c) 2012-2019 Copyright: Martin Fischer (m_fischer at gmx dot de)
|
# (c) 2012-2020 Copyright: Martin Fischer (m_fischer at gmx dot de)
|
||||||
# Rewrite and Maintained by Marko Oldenburg since 2019
|
# Rewrite and Maintained by Marko Oldenburg since 2019
|
||||||
# All rights reserved
|
# All rights reserved
|
||||||
#
|
#
|
||||||
|
# Contributors:
|
||||||
|
# - Marko Oldenburg (CoolTux)
|
||||||
|
#
|
||||||
# This script free software; you can redistribute it and/or modify
|
# This script free software; you can redistribute it and/or modify
|
||||||
# it under the terms of the GNU General Public License as published by
|
# it under the terms of the GNU General Public License as published by
|
||||||
# the Free Software Foundation; either version 2 of the License, or
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
@ -31,11 +34,13 @@ use warnings;
|
|||||||
use FHEM::Meta;
|
use FHEM::Meta;
|
||||||
|
|
||||||
#####################################
|
#####################################
|
||||||
sub backup_Initialize($$) {
|
sub backup_Initialize {
|
||||||
|
|
||||||
my %hash = (
|
my %hash = (
|
||||||
Fn => 'FHEM::backup::CommandBackup',
|
Fn => 'FHEM::backup::CommandBackup',
|
||||||
Hlp => ',create a backup of fhem configuration, state and modpath'
|
Hlp => ',create a backup of fhem configuration, state and modpath'
|
||||||
);
|
);
|
||||||
|
|
||||||
$cmds{backup} = \%hash;
|
$cmds{backup} = \%hash;
|
||||||
|
|
||||||
return FHEM::Meta::InitMod( __FILE__, \%hash );
|
return FHEM::Meta::InitMod( __FILE__, \%hash );
|
||||||
@ -59,6 +64,7 @@ BEGIN {
|
|||||||
InternalVal
|
InternalVal
|
||||||
gettimeofday
|
gettimeofday
|
||||||
ResolveDateWildcards
|
ResolveDateWildcards
|
||||||
|
readingsSingleUpdate
|
||||||
attr
|
attr
|
||||||
Log
|
Log
|
||||||
fhemForked
|
fhemForked
|
||||||
@ -75,8 +81,9 @@ BEGIN {
|
|||||||
|
|
||||||
my @pathname;
|
my @pathname;
|
||||||
|
|
||||||
sub CommandBackup($$) {
|
sub CommandBackup {
|
||||||
my ( $cl, $param ) = @_;
|
my $cl = shift;
|
||||||
|
my $param = shift;
|
||||||
|
|
||||||
my $byUpdate = ( $param && $param eq 'startedByUpdate' );
|
my $byUpdate = ( $param && $param eq 'startedByUpdate' );
|
||||||
my $modpath = AttrVal( 'global', 'modpath', '.' );
|
my $modpath = AttrVal( 'global', 'modpath', '.' );
|
||||||
@ -85,6 +92,8 @@ sub CommandBackup($$) {
|
|||||||
my $dir = AttrVal( 'global', 'backupdir', $modpath . '/backup');
|
my $dir = AttrVal( 'global', 'backupdir', $modpath . '/backup');
|
||||||
my $now = gettimeofday();
|
my $now = gettimeofday();
|
||||||
my @t = localtime($now);
|
my @t = localtime($now);
|
||||||
|
my $dateTime = dateTime();
|
||||||
|
|
||||||
$statefile = ResolveDateWildcards( $statefile, @t );
|
$statefile = ResolveDateWildcards( $statefile, @t );
|
||||||
|
|
||||||
# prevent duplicate entries in backup list for default config, forum #54826
|
# prevent duplicate entries in backup list for default config, forum #54826
|
||||||
@ -111,8 +120,17 @@ sub CommandBackup($$) {
|
|||||||
@all{@pathname}=1;
|
@all{@pathname}=1;
|
||||||
@pathname = keys %all;
|
@pathname = keys %all;
|
||||||
|
|
||||||
# create archiv
|
### create archiv
|
||||||
$ret = createArchiv( $backupdir, $cl, $byUpdate );
|
$ret = createArchiv( $backupdir, $cl, $byUpdate, $dateTime );
|
||||||
|
|
||||||
|
### support for backupToStorage Modul
|
||||||
|
readingsSingleUpdate($defs{join(' ',
|
||||||
|
devspec2array('TYPE=backupToStorage'))}
|
||||||
|
, 'fhemBackupFile'
|
||||||
|
, "$backupdir/FHEM-$dateTime.tar.gz"
|
||||||
|
, 0
|
||||||
|
)
|
||||||
|
if ( devspec2array('TYPE=backupToStorage') > 0 );
|
||||||
|
|
||||||
@pathname = [];
|
@pathname = [];
|
||||||
undef @pathname;
|
undef @pathname;
|
||||||
@ -120,8 +138,10 @@ sub CommandBackup($$) {
|
|||||||
return $ret;
|
return $ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub addConfDBFiles($$) {
|
sub addConfDBFiles {
|
||||||
my ($configfile,$statefile) = @_;
|
my $configfile = shift;
|
||||||
|
my $statefile = shift;
|
||||||
|
|
||||||
my $ret;
|
my $ret;
|
||||||
|
|
||||||
if ( configDBUsed() ) {
|
if ( configDBUsed() ) {
|
||||||
@ -151,8 +171,9 @@ sub addConfDBFiles($$) {
|
|||||||
return $ret;
|
return $ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub createBackupDir($$) {
|
sub createBackupDir {
|
||||||
my ($dir,$modpath) = @_;
|
my $dir = shift;
|
||||||
|
my $modpath = shift;
|
||||||
|
|
||||||
my $msg;
|
my $msg;
|
||||||
my $ret;
|
my $ret;
|
||||||
@ -172,9 +193,7 @@ sub createBackupDir($$) {
|
|||||||
return (undef,$backupdir);
|
return (undef,$backupdir);
|
||||||
}
|
}
|
||||||
|
|
||||||
sub parseConfig($);
|
sub parseConfig {
|
||||||
|
|
||||||
sub parseConfig($) {
|
|
||||||
my $configfile = shift;
|
my $configfile = shift;
|
||||||
|
|
||||||
# we need default value to read included files
|
# we need default value to read included files
|
||||||
@ -210,8 +229,10 @@ sub parseConfig($) {
|
|||||||
return $ret;
|
return $ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub readModpath($$) {
|
sub readModpath {
|
||||||
my ( $modpath, $backupdir ) = @_;
|
my $modpath = shift;
|
||||||
|
my $backupdir = shift;
|
||||||
|
|
||||||
my $msg;
|
my $msg;
|
||||||
my $ret;
|
my $ret;
|
||||||
|
|
||||||
@ -235,18 +256,23 @@ sub readModpath($$) {
|
|||||||
return $ret;
|
return $ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub createArchiv($$$) {
|
sub dateTime {
|
||||||
my ( $backupdir, $cl, $byUpdate ) = @_;
|
my $dateTime = TimeNow();
|
||||||
|
$dateTime =~ s/ /_/g;
|
||||||
|
$dateTime =~ s/(:|-)//g;
|
||||||
|
|
||||||
|
return $dateTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
sub createArchiv {
|
||||||
|
my ($backupdir, $cl, $byUpdate, $dateTime) = @_;
|
||||||
|
|
||||||
my $backupcmd = AttrVal('global','backupcmd',undef);
|
my $backupcmd = AttrVal('global','backupcmd',undef);
|
||||||
my $symlink = AttrVal('global','backupsymlink','no');
|
my $symlink = AttrVal('global','backupsymlink','no');
|
||||||
my $tarOpts;
|
my $tarOpts;
|
||||||
my $msg;
|
my $msg;
|
||||||
my $ret;
|
my $ret;
|
||||||
|
|
||||||
my $dateTime = TimeNow();
|
|
||||||
$dateTime =~ s/ /_/g;
|
|
||||||
$dateTime =~ s/(:|-)//g;
|
|
||||||
|
|
||||||
my $pathlist = join( '" "', @pathname );
|
my $pathlist = join( '" "', @pathname );
|
||||||
|
|
||||||
my $cmd = '';
|
my $cmd = '';
|
||||||
@ -260,7 +286,6 @@ sub createArchiv($$$) {
|
|||||||
|
|
||||||
# prevents tar's output of "Removing leading /" and return total bytes of
|
# prevents tar's output of "Removing leading /" and return total bytes of
|
||||||
# archive
|
# archive
|
||||||
# $cmd = "tar -$tarOpts - \"$pathlist\" |gzip > $backupdir/FHEM-$dateTime.tar.gz";
|
|
||||||
$cmd = "tar $tarOpts $backupdir/FHEM-$dateTime.tar.gz \"$pathlist\"";
|
$cmd = "tar $tarOpts $backupdir/FHEM-$dateTime.tar.gz \"$pathlist\"";
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -276,6 +301,7 @@ sub createArchiv($$$) {
|
|||||||
|
|
||||||
system( "($cmd; echo Backup done;"
|
system( "($cmd; echo Backup done;"
|
||||||
. "$^X $0 localhost:$tp 'trigger global backup done')2>&1 &" );
|
. "$^X $0 localhost:$tp 'trigger global backup done')2>&1 &" );
|
||||||
|
|
||||||
return
|
return
|
||||||
"Started the backup in the background, watch the log for details";
|
"Started the backup in the background, watch the log for details";
|
||||||
}
|
}
|
||||||
@ -298,9 +324,7 @@ sub createArchiv($$$) {
|
|||||||
return $ret;
|
return $ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub addLogPathToPathnameArray() {
|
sub addLogPathToPathnameArray {
|
||||||
# my $modpath = shift;
|
|
||||||
|
|
||||||
my $ret;
|
my $ret;
|
||||||
my @logpathname;
|
my @logpathname;
|
||||||
my $extlogpath;
|
my $extlogpath;
|
||||||
@ -377,7 +401,7 @@ sub addLogPathToPathnameArray() {
|
|||||||
"release_status": "stable",
|
"release_status": "stable",
|
||||||
"license": "GPL_2",
|
"license": "GPL_2",
|
||||||
"author": [
|
"author": [
|
||||||
"Marko Oldenburg <leongaultier@gmail.com>"
|
"Marko Oldenburg <fhemsupport@cooltux.net>"
|
||||||
],
|
],
|
||||||
"x_fhem_maintainer": [
|
"x_fhem_maintainer": [
|
||||||
"CoolTux"
|
"CoolTux"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user