From 7e8f02a105f1e2b8f89c9ffec020da453eae4182 Mon Sep 17 00:00:00 2001 From: rudolfkoenig Date: Tue, 18 Oct 2011 08:19:08 +0000 Subject: [PATCH] updatefhem backup by RueBe git-svn-id: https://fhem.svn.sourceforge.net/svnroot/fhem/trunk/fhem@1078 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- FHEM/99_SUNRISE_EL.pm | 1 + FHEM/99_updatefhem.pm | 37 ++++++++++++++++++++ docs/commandref.html | 78 ++++++++++++++++++++++++++++++------------- fhem.pl | 4 +-- 4 files changed, 94 insertions(+), 26 deletions(-) diff --git a/FHEM/99_SUNRISE_EL.pm b/FHEM/99_SUNRISE_EL.pm index fa5b5bb94..4d671894e 100755 --- a/FHEM/99_SUNRISE_EL.pm +++ b/FHEM/99_SUNRISE_EL.pm @@ -33,6 +33,7 @@ sub SUNRISE_EL_Initialize($) { my ($hash) = @_; + $modules{Global}{AttrList} .= " latitude longitude"; } diff --git a/FHEM/99_updatefhem.pm b/FHEM/99_updatefhem.pm index c0c741101..cbc55dd36 100644 --- a/FHEM/99_updatefhem.pm +++ b/FHEM/99_updatefhem.pm @@ -23,6 +23,8 @@ updatefhem_Initialize($$) my %chash = ( Fn=>"CommandCULflash", Hlp=>" ,flash the CUL from the nightly CVS" ); $cmds{CULflash} = \%chash; + + $modules{Global}{AttrList} .= " backupdir"; } @@ -36,6 +38,41 @@ CommandUpdatefhem($$) my $moddir = "$attr{global}{modpath}/FHEM"; #my $moddir = "XXX"; + ## backup by RueBe + my @commandchain = split(/ +/,$param); + + # Check if the first parameter is "backup" + if(uc($commandchain[0]) eq "BACKUP") { + my $backupdir = AttrVal("global", "backupdir", "/tmp/FHEM_Backup"); + # create the backupfolder + if(!-d $backupdir) { + if(!mkdir($backupdir)) { + return "Can't create backup folder $!"; + } + } + # full backup, for compatibility, we use the native copy unction, not + # dircopy from File::Copy::Recursive + if($commandchain[1] eq "") { + opendir(IMD, $moddir) || return "Cannot open fhem-module directory"; + my @files= readdir(IMD); + closedir(IMD); + my $f; + + foreach $f (@files) { + unless ( ($f eq ".") || ($f eq "..") ) { + my $ret = copy("$moddir/$f", "$backupdir/$f"); + } + } + $param = ""; + + } else { + # one file backup + copy("$moddir/$commandchain[1]", "$backupdir/$commandchain[1]"); + # recreate $param for further use + $param = $commandchain[1]; + } + } + # Read in the OLD filetimes.txt my %oldtime; if(open FH, "$moddir/$ftime") { diff --git a/docs/commandref.html b/docs/commandref.html index c0f06cbc3..5d102c3bf 100644 --- a/docs/commandref.html +++ b/docs/commandref.html @@ -548,7 +548,7 @@ A line ending with \ will be concatenated with the next one, so long lines

updatefhem

    - updatefhem [filename]
    + updatefhem [backup] [filename]

    Update the fhem modules and documentation from a nightly CVS chekout. For this purpose fhem contacts http://fhem.de/fhemupdate, compares the stored @@ -557,9 +557,31 @@ A line ending with \ will be concatenated with the next one, so long lines reload will be scheduled if the corresponding module is loaded.
    If an explicit filename is given, then only this file will be downloaded.
    + Note: if the main program (fhem.pl) is changed, a manual restart of fhem will be necessary to apply the changes.
    + + If backup is specified, then the old files are saved before overwriting + them. They are copied to the folder given in global or as + default to /tmp/FHEM_Backup. Please check if the fhem user has the rights + to create a folder for backup. +
    +
    + + Attributes
      + +
    • backupdir
      + A folder where updatefhem can store all files from modpath before executing the update. Please check if + the fhem user has the rights to create this folder. +

    • + Note: this is a global attribute, e.g.
      +
        + attr global backup /Volumes/BigHD
        +
      +

    +
@@ -925,13 +947,6 @@ A line ending with \ will be concatenated with the next one, so long lines the INITIALIZED event to execute commands after initialization.
- -
  • latitude
    - If set, this latitude is used to calculate sunset/sunrise
    - Notation need to be in decimal format (for example Berlin = 52.666) - As default Frankfurt/Main, Germany (50.112) is used. -

  • -
  • logfile
    Specify the logfile to write. You can use "-" for @@ -940,13 +955,6 @@ A line ending with \ will be concatenated with the next one, so long lines see the FileLog section.

  • -
  • modpath
    Specify the path to the modules directory FHEM. The path @@ -3071,10 +3079,7 @@ A line ending with \ will be concatenated with the next one, so long lines
  • desired-temp <value>
    Use the builtin PI regulator, and set the desired temperature to the specified degree. The actual value will be taken from the temperature - reported by the MD15.
  • -
  • desired+actual <value1> <value2>
    - Use the builtin PI regulator, and set the desired temperature to - <value1>. The actual value is supplied in <value2>
  • + reported by the MD15 or from the attribute actualTemp if it is set
  • unattended
    Do not regulate the MD15.
  • @@ -3126,6 +3131,11 @@ A line ending with \ will be concatenated with the next one, so long lines
  • showtime
  • model
  • subType
  • +
  • actualTemp
    + The value of the actual temperature, used when controlling MD15 devices. + Should by filled via a notify from a distinct temperature sensor. If + absent, the reported temperature from the MD15 is used. +

  • @@ -7472,10 +7482,10 @@ sunrise_rel, sunset_rel sunrise_abs, sunset_abs isday perl functions, to be used in at or FS20 on-till commands.
    - First you should edit SUNRISE_EL.pm, and set long and lat to the exact longitude - and latitude values (see e.g. maps.google.com for the exact values, which - should be in the form of a floating point value). The default value is - Frankfurt am Main, Germany. + First you should set the longitude and latitude global attributes to the + exact longitude and latitude values (see e.g. maps.google.com for the exact + values, which should be in the form of a floating point value). The default + value is Frankfurt am Main, Germany.

    The default altitude ($altit in SUNRISE_EL.pm) defines the sunrise/sunset for Civil twilight (i.e. one can no longer read outside without artificial @@ -7509,7 +7519,27 @@ isday Get
      N/A

    - Attributes
      N/A

    + Attributes
      + +
    • latitude
      + If set, this latitude is used to calculate sunset/sunrise
      + Notation need to be in decimal format (for example Berlin = 52.666) + As default Frankfurt/Main, Germany (50.112) is used. +

    • + +
    • longitude
      + If set, this longitude is used to calculate sunset/sunrise
      + Notation need to be in decimal format (for example Berlin = 13.400) + As default Frankfurt/Main, Germany (8.686) is used. +

    • + Note: these are global attributes, e.g.
      +
        + attr global latitude 50.112
        + attr global longitude 8.686
        +
      +

    + + diff --git a/fhem.pl b/fhem.pl index 83d37088f..11d13b629 100755 --- a/fhem.pl +++ b/fhem.pl @@ -167,7 +167,7 @@ my $nextat; # Time when next timer will be triggered. my $intAtCnt=0; my %duplicate; # Pool of received msg for multi-fhz/cul setups my $duplidx=0; # helper for the above pool -my $cvsid = '$Id: fhem.pl,v 1.155 2011-10-16 07:55:20 rudolfkoenig Exp $'; +my $cvsid = '$Id: fhem.pl,v 1.156 2011-10-18 08:19:07 rudolfkoenig Exp $'; my $namedef = "where is either:\n" . "- a single device name\n" . @@ -185,7 +185,7 @@ $modules{Global}{AttrList} = "archivecmd allowfrom archivedir configfile lastinclude logfile " . "modpath nrarchive pidfilename port statefile title userattr " . "verbose:1,2,3,4,5 mseclog version nofork logdir holiday2we " . - "autoload_undefined_devices dupTimeout latitude longitude"; + "autoload_undefined_devices dupTimeout"; $modules{Global}{AttrFn} = "GlobalAttr"; my $commonAttr = "eventMap";