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