From f24ac20289f463a7db1074b6b9f6fcd5ad641d58 Mon Sep 17 00:00:00 2001 From: mfr69bs Date: Sat, 2 Jun 2012 16:51:25 +0000 Subject: [PATCH] Added new global attribute . Backuproutine from updatefhem removed. updatefhem use the command backup from now. git-svn-id: https://fhem.svn.sourceforge.net/svnroot/fhem/trunk/fhem@1596 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- CHANGED | 6 +- FHEM/99_updatefhem.pm | 136 ++++++++++++++++-------------------------- HISTORY | 4 ++ docs/commandref.html | 34 +++++++---- fhem.pl | 2 +- 5 files changed, 82 insertions(+), 100 deletions(-) diff --git a/CHANGED b/CHANGED index d4c7eb2d8..8de208a06 100644 --- a/CHANGED +++ b/CHANGED @@ -33,9 +33,11 @@ - change: FHEMWEB support for the new www/pgm2 directroy added (M. Fischer) - change: Makefile support for for the new www/pgm2 directroy and new targets backup and uninstall added. More verbose output. (M. Fischer) + - change: backuproutine separated from updatefhem to a new command (M. Fischer) - feature: new command backup added (M. Fischer) - - feature: new global attribute added - - feature: new global attribute added + new global attribute added + new global attribute added + new global attribute added - 2011-12-31 (5.2) - bugfix: applying smallscreen attributes to firefox/opera diff --git a/FHEM/99_updatefhem.pm b/FHEM/99_updatefhem.pm index c8b1db6cc..3573bcc66 100644 --- a/FHEM/99_updatefhem.pm +++ b/FHEM/99_updatefhem.pm @@ -9,7 +9,6 @@ use IO::Socket; sub CommandUpdatefhem($$); sub CommandCULflash($$); sub GetHttpFile($$@); -sub CreateBackup($); sub FileList($); my $server = "fhem.de:80"; @@ -41,14 +40,13 @@ CommandUpdatefhem($$) my $modpath = (-d "updatefhem.dir" ? "updatefhem.dir" : $attr{global}{modpath}); my $moddir = "$modpath/FHEM"; my $wwwdir = "$modpath/www"; - my $backuppaths = ""; my $preserve = 0; my $housekeeping = 0; my $clean = 0; my $msg; if(!$param && !-d $wwwdir) { - $ret = "Usage: updatefhem [|| [] []| []]\n"; + $ret = "Usage: updatefhem [| [] []| []]\n"; $ret .= "Please note: The update routine has changed! Please consider the manual of command 'updatefhem'!"; return $ret; } @@ -58,36 +56,12 @@ CommandUpdatefhem($$) if(@args) { - # Check if the first parameter is "backup" - # backup by RueBe, simplified by rudi, modified by M.Fischer - if(uc($args[0]) eq "BACKUP") { - return "Usage: updatefhem " if(@args > 1); - - if(-d $wwwdir) { - # backup new structure - $backuppaths = "FHEM www"; - } else { - # backup old structure - $backuppaths = "FHEM"; - } - my $ret = CreateBackup($backuppaths); - if($ret !~ m/backup done.*/) { - Log 1, "updatefhem backup: The operation was canceled. Please check manually!"; - $msg = "Something went wrong during backup:\n$ret\n"; - $msg .= "The operation was canceled. Please check manually!"; - return $msg; - } else { - Log 1, "updatefhem $ret"; - } - return $ret if($ret); - - # Check whether the old structure to be maintained - } elsif (uc($args[0]) eq "PRESERVE") { + if (uc($args[0]) eq "PRESERVE") { # Check if new wwwdir already exists and an argument is given if(-d $wwwdir && @args > 1) { Log 1, "updatefhem The operation was canceled! Argument not allowed in new structure!"; - $ret = "Usage: updatefhem [|]\n"; + $ret = "Usage: updatefhem []\n"; $ret .= "Please note: It seems as if 'updatefhem ' has already executed.\n"; $ret .= "The operation was canceled. Argument is not allowed in new structure!"; return $ret; @@ -139,24 +113,6 @@ CommandUpdatefhem($$) $clean = 1; } - # Backup existing structure - if(-d $wwwdir) { - # backup new structure - $backuppaths = "FHEM www"; - } else { - # backup old structure - $backuppaths = "FHEM"; - } - my $ret = CreateBackup($backuppaths); - if($ret !~ m/backup done.*/) { - Log 1, "updatefhem backup: The operation was canceled. Please check manually!"; - $msg = "Something went wrong during backup:\n$ret\n"; - $msg .= "The operation was canceled. Please check manually!"; - return $msg; - } else { - Log 1, "updatefhem $ret"; - } - # prepare for housekeeping $housekeeping = 1; # set new sourcedir for update @@ -180,9 +136,12 @@ CommandUpdatefhem($$) @args = (); $param = join("", @args); + # help + } elsif (uc($args[0]) eq "?") { + return "Usage: updatefhem [ [] []| []]"; # user wants to update a file / module of the old structure } elsif (!-d $wwwdir) { - return "Usage: updatefhem [| [] []| []]"; + return "Usage: updatefhem [ [] []| []]"; } } @@ -211,6 +170,35 @@ CommandUpdatefhem($$) $filesize{$file} = $fs; } + my $c = 0; + foreach my $f (sort keys %filetime) { + if($param) { + next if($f !~ m/$param/); + } else { + if(!$clean) { + next if($oldtime{$f} && $filetime{$f} eq $oldtime{$f}); + } + next if($f =~ m/.hex$/); # skip firmware files + } + $c = 1; + } + + return "nothing to do..." if (!$c); + + # do a backup first + my $doBackup = (!defined($attr{global}{backup_before_update}) ? 1 : $attr{global}{backup_before_update}); + + if ($doBackup) { + $ret = AnalyzeCommandChain(undef, "backup"); + if($ret !~ m/backup done.*/) { + Log 1, "updatefhem: The operation was canceled. Please check manually!"; + $msg = "Something went wrong during backup:\n$ret\n"; + $msg .= "The operation was canceled. Please check manually!"; + return $msg; + } + $ret .= "\n"; + } + my @reload; my $newfhem = 0; my $localfile; @@ -288,7 +276,7 @@ CommandUpdatefhem($$) } # final housekeeping -# if($clean) { + if($clean) { my @fl; push(@fl, FileList("$moddir/.*(example.*|gplot|html|css|js|gif|jpg|png|svg)")); foreach my $file (@fl) { @@ -296,18 +284,22 @@ CommandUpdatefhem($$) $ret .= "moved $moddir/$file\n"; Log 1, "updatefhem move $file to www/pgm2 $cmdret"; } -# } + } if($housekeeping) { $ret .= "Housekeeping finished. 'shutdown restart' is recommended!"; - my $backupdir; - if ($attr{global}{backupdir}) { - $backupdir = "$modpath/$attr{global}{backupdir}"; - } else { - $backupdir = "$modpath/backup"; - } $ret .= "\n=> Files for WebGUI pgm2 were moved to '$wwwdir/pgm2'" if($clean); - $ret .= "\n=> A backup has been created in '$backupdir'"; + if ($attr{global}{backupcmd}) { + $ret .= "\n=> A backup has been created with '$attr{global}{backupcmd}'"; + } else { + my $backupdir; + if ($attr{global}{backupdir}) { + $backupdir = $attr{global}{backupdir}; + } else { + $backupdir = "$modpath/backup"; + } + $ret .= "\n=> A backup has been created in '$backupdir'"; + } Log 1, "updatefhem Housekeeping finished, 'shutdown restart' is recommended!"; } else { $ret .= "update finished"; @@ -424,35 +416,6 @@ GetHttpFile($$@) return $ret; } -sub -CreateBackup($) -{ - my ($backuppaths) = shift; - my $modpath = (-d "updatefhem.dir" ? "updatefhem.dir" : $attr{global}{modpath}); - my ($dir,$conf) = $attr{global}{configfile} =~ m/(.*\/)(.*)$/; - my $backupdir; - my $ret; - if ($attr{global}{backupdir}) { - $backupdir = $attr{global}{backupdir}; - } else { - $backupdir = "$modpath/backup"; - } - $ret = `(cp $attr{global}{configfile} $modpath/)`; - $backuppaths .= " $conf"; - my $dateTime = TimeNow(); - $dateTime =~ s/ /_/g; - $dateTime =~ s/(:|-)//g; - # prevents tar's output of "Removing leading /" and return total bytes of archive - $ret = `(mkdir -p $backupdir && tar -C $modpath -cf - $backuppaths | gzip > $backupdir/FHEM-$dateTime.tar.gz) 2>&1`; - unlink("$modpath/$conf"); - if($ret) { - chomp $ret; - return $ret; - } - my $size = -s "$backupdir/FHEM-$dateTime.tar.gz"; - return "backup done: FHEM-$dateTime.tar.gz ($size Bytes)"; -} - sub FileList($) { @@ -471,4 +434,5 @@ FileList($) return sort @ret; } +# vim: ts=2:et 1; diff --git a/HISTORY b/HISTORY index 051a11cf4..65849ff3d 100644 --- a/HISTORY +++ b/HISTORY @@ -505,3 +505,7 @@ - Fri Jun 01 2012 (M. Fischer) - Added new global attribute + +- Sat Jun 02 2012 (M. Fischer) + - Added new global attribute + - Backuproutine from updatefhem removed. updatefhem use the command backup from now. diff --git a/docs/commandref.html b/docs/commandref.html index 354279c2c..f20f74d12 100644 --- a/docs/commandref.html +++ b/docs/commandref.html @@ -481,9 +481,9 @@ A line ending with \ will be concatenated with the next one, so long lines
The complete FHEM directory (containing the modules), the WebInterface pgm2 (if installed) and the config-file will be saved into a .tar.gz - file by default. The file is stored with a timestamp in the modpath/backup - directory or to a directory specified by the backupdir - global attribute.
+ file by default. The file is stored with a timestamp in the + modpath/backup directory or to a directory + specified by the global attribute backupdir.
Note: tar and gzip must be installed to use this feature.

@@ -774,10 +774,10 @@ A line ending with \ will be concatenated with the next one, so long lines

updatefhem

    - updatefhem [<backup>|<filename>|<housekeeping> [<clean>] [<yes>]|<preserve> [<filename>]]
    + updatefhem [<filename>|<housekeeping> [<clean>] [<yes>]|<preserve> [<filename>]]

    Update the fhem modules and documentation from a nightly SVN checkout. For - this purpose fhem contacts http://fhem.de/fhemupdate, compares the stored + this purpose Fhem contacts http://fhem.de/fhemupdate, compares the stored timestamps of the local files with the filelist on the server, and downloads the files changed on the server. For all downloaded modules a reload will be scheduled if the corresponding module is loaded. @@ -790,12 +790,9 @@ A line ending with \ will be concatenated with the next one, so long lines <housekeeping> arguments.

    - If <backup> is specified, then the complete FHEM directory (containing - the modules), the WebInterface pgm2 (if installed) and the config-file will - be saved into a .tar.gz file. The file is stored with a timestamp in the - modpath/backup directory or to a directory specified - by the backupdir global attribute.
    - Note: tar and gzip must be installed to use this feature. + The complete installation of Fhem will be saved via the backup + command on every update. You can skip this backups by setting + the global attribute backup_before_update to 0.

    If an explicit <filename> is given, then only this file will be @@ -1175,6 +1172,19 @@ A line ending with \ will be concatenated with the next one, so long lines only connections from these addresses are allowed.
    + +
  • backup_before_update
    + If this attribute is set to 0, updatefhem skip always backing up your + installation via the backup command. The default + is to backup always before updates.
    + Note: Set this attribute only if you know what you do!
    + This Attribute is used by the updatefhem command.
    + Example:
    +
      + attr global backup_before_update 0 +
    +

  • +
  • backupcmd
    You could pass the backup to your own command / script by using this attribute. @@ -1187,6 +1197,8 @@ A line ending with \ will be concatenated with the next one, so long lines /usr/share/fhem/FHEM /usr/share/fhem/foo /usr/share/fhem/foobar /usr/share/fhem/www"
+ Note: Your command / script has to return the string "backup done" or + everything else to report errors, to work properly with updatefhem!
This Attribute is used by the backup command.
Example:
    diff --git a/fhem.pl b/fhem.pl index 45d688e56..c1836af14 100755 --- a/fhem.pl +++ b/fhem.pl @@ -194,7 +194,7 @@ $modules{Global}{AttrList} = "modpath nrarchive pidfilename port statefile title userattr " . "verbose:1,2,3,4,5 mseclog version nofork logdir holiday2we " . "autoload_undefined_devices dupTimeout latitude longitude ". - "backupcmd backupdir backupsymlink"; + "backupcmd backupdir backupsymlink backup_before_update"; $modules{Global}{AttrFn} = "GlobalAttr";