2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-01-31 12:49:34 +00:00

Added new global attribute <backup_before_update>. Backuproutine from updatefhem removed. updatefhem use the command backup from now.

git-svn-id: https://svn.fhem.de/fhem/trunk@1596 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
mfr69bs 2012-06-02 16:51:25 +00:00
parent 0bc43108f8
commit 36bc553df4
5 changed files with 82 additions and 100 deletions

View File

@ -33,9 +33,11 @@
- change: FHEMWEB support for the new www/pgm2 directroy added (M. Fischer) - 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 - change: Makefile support for for the new www/pgm2 directroy and new targets
backup and uninstall added. More verbose output. (M. Fischer) 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 command backup added (M. Fischer)
- feature: new global attribute <backupsymlink> added new global attribute <backupsymlink> added
- feature: new global attribute <backupcmd> added new global attribute <backupcmd> added
new global attribute <backup_before_update> added
- 2011-12-31 (5.2) - 2011-12-31 (5.2)
- bugfix: applying smallscreen attributes to firefox/opera - bugfix: applying smallscreen attributes to firefox/opera

View File

@ -9,7 +9,6 @@ use IO::Socket;
sub CommandUpdatefhem($$); sub CommandUpdatefhem($$);
sub CommandCULflash($$); sub CommandCULflash($$);
sub GetHttpFile($$@); sub GetHttpFile($$@);
sub CreateBackup($);
sub FileList($); sub FileList($);
my $server = "fhem.de:80"; my $server = "fhem.de:80";
@ -41,14 +40,13 @@ CommandUpdatefhem($$)
my $modpath = (-d "updatefhem.dir" ? "updatefhem.dir" : $attr{global}{modpath}); my $modpath = (-d "updatefhem.dir" ? "updatefhem.dir" : $attr{global}{modpath});
my $moddir = "$modpath/FHEM"; my $moddir = "$modpath/FHEM";
my $wwwdir = "$modpath/www"; my $wwwdir = "$modpath/www";
my $backuppaths = "";
my $preserve = 0; my $preserve = 0;
my $housekeeping = 0; my $housekeeping = 0;
my $clean = 0; my $clean = 0;
my $msg; my $msg;
if(!$param && !-d $wwwdir) { if(!$param && !-d $wwwdir) {
$ret = "Usage: updatefhem [<backup>|<filename>|<housekeeping> [<clean>] [<yes>]|<preserve> [<filename>]]\n"; $ret = "Usage: updatefhem [<filename>|<housekeeping> [<clean>] [<yes>]|<preserve> [<filename>]]\n";
$ret .= "Please note: The update routine has changed! Please consider the manual of command 'updatefhem'!"; $ret .= "Please note: The update routine has changed! Please consider the manual of command 'updatefhem'!";
return $ret; return $ret;
} }
@ -58,36 +56,12 @@ CommandUpdatefhem($$)
if(@args) { if(@args) {
# Check if the first parameter is "backup" if (uc($args[0]) eq "PRESERVE") {
# backup by RueBe, simplified by rudi, modified by M.Fischer
if(uc($args[0]) eq "BACKUP") {
return "Usage: updatefhem <backup>" 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") {
# Check if new wwwdir already exists and an argument is given # Check if new wwwdir already exists and an argument is given
if(-d $wwwdir && @args > 1) { if(-d $wwwdir && @args > 1) {
Log 1, "updatefhem The operation was canceled! Argument <preserve> not allowed in new structure!"; Log 1, "updatefhem The operation was canceled! Argument <preserve> not allowed in new structure!";
$ret = "Usage: updatefhem [<backup>|<filename>]\n"; $ret = "Usage: updatefhem [<filename>]\n";
$ret .= "Please note: It seems as if 'updatefhem <housekeeping>' has already executed.\n"; $ret .= "Please note: It seems as if 'updatefhem <housekeeping>' has already executed.\n";
$ret .= "The operation was canceled. Argument <preserve> is not allowed in new structure!"; $ret .= "The operation was canceled. Argument <preserve> is not allowed in new structure!";
return $ret; return $ret;
@ -139,24 +113,6 @@ CommandUpdatefhem($$)
$clean = 1; $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 # prepare for housekeeping
$housekeeping = 1; $housekeeping = 1;
# set new sourcedir for update # set new sourcedir for update
@ -180,9 +136,12 @@ CommandUpdatefhem($$)
@args = (); @args = ();
$param = join("", @args); $param = join("", @args);
# help
} elsif (uc($args[0]) eq "?") {
return "Usage: updatefhem [<housekeeping> [<clean>] [<yes>]|<preserve> [<filename>]]";
# user wants to update a file / module of the old structure # user wants to update a file / module of the old structure
} elsif (!-d $wwwdir) { } elsif (!-d $wwwdir) {
return "Usage: updatefhem [<backup>|<housekeeping> [<clean>] [<yes>]|<preserve> [<filename>]]"; return "Usage: updatefhem [<housekeeping> [<clean>] [<yes>]|<preserve> [<filename>]]";
} }
} }
@ -211,6 +170,35 @@ CommandUpdatefhem($$)
$filesize{$file} = $fs; $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 @reload;
my $newfhem = 0; my $newfhem = 0;
my $localfile; my $localfile;
@ -288,7 +276,7 @@ CommandUpdatefhem($$)
} }
# final housekeeping # final housekeeping
# if($clean) { if($clean) {
my @fl; my @fl;
push(@fl, FileList("$moddir/.*(example.*|gplot|html|css|js|gif|jpg|png|svg)")); push(@fl, FileList("$moddir/.*(example.*|gplot|html|css|js|gif|jpg|png|svg)"));
foreach my $file (@fl) { foreach my $file (@fl) {
@ -296,18 +284,22 @@ CommandUpdatefhem($$)
$ret .= "moved $moddir/$file\n"; $ret .= "moved $moddir/$file\n";
Log 1, "updatefhem move $file to www/pgm2 $cmdret"; Log 1, "updatefhem move $file to www/pgm2 $cmdret";
} }
# } }
if($housekeeping) { if($housekeeping) {
$ret .= "Housekeeping finished. 'shutdown restart' is recommended!"; $ret .= "Housekeeping finished. 'shutdown restart' is recommended!";
$ret .= "\n=> Files for WebGUI pgm2 were moved to '$wwwdir/pgm2'" if($clean);
if ($attr{global}{backupcmd}) {
$ret .= "\n=> A backup has been created with '$attr{global}{backupcmd}'";
} else {
my $backupdir; my $backupdir;
if ($attr{global}{backupdir}) { if ($attr{global}{backupdir}) {
$backupdir = "$modpath/$attr{global}{backupdir}"; $backupdir = $attr{global}{backupdir};
} else { } else {
$backupdir = "$modpath/backup"; $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'"; $ret .= "\n=> A backup has been created in '$backupdir'";
}
Log 1, "updatefhem Housekeeping finished, 'shutdown restart' is recommended!"; Log 1, "updatefhem Housekeeping finished, 'shutdown restart' is recommended!";
} else { } else {
$ret .= "update finished"; $ret .= "update finished";
@ -424,35 +416,6 @@ GetHttpFile($$@)
return $ret; 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 sub
FileList($) FileList($)
{ {
@ -471,4 +434,5 @@ FileList($)
return sort @ret; return sort @ret;
} }
# vim: ts=2:et
1; 1;

View File

@ -505,3 +505,7 @@
- Fri Jun 01 2012 (M. Fischer) - Fri Jun 01 2012 (M. Fischer)
- Added new global attribute <backupcmd> - Added new global attribute <backupcmd>
- Sat Jun 02 2012 (M. Fischer)
- Added new global attribute <backup_before_update>
- Backuproutine from updatefhem removed. updatefhem use the command backup from now.

View File

@ -481,9 +481,9 @@ A line ending with \ will be concatenated with the next one, so long lines
<br> <br>
The complete FHEM directory (containing the modules), the WebInterface The complete FHEM directory (containing the modules), the WebInterface
pgm2 (if installed) and the config-file will be saved into a .tar.gz 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 file by default. The file is stored with a timestamp in the
directory or to a directory specified by the <a href="#backupdir">backupdir</a> <a href="#modpath">modpath</a>/backup directory or to a directory
global attribute.<br> specified by the global attribute <a href="#backupdir">backupdir</a>.<br>
Note: tar and gzip must be installed to use this feature. Note: tar and gzip must be installed to use this feature.
<br> <br>
<br> <br>
@ -774,10 +774,10 @@ A line ending with \ will be concatenated with the next one, so long lines
<a name="updatefhem"></a> <a name="updatefhem"></a>
<h3>updatefhem</h3> <h3>updatefhem</h3>
<ul> <ul>
<code>updatefhem [&lt;backup&gt;|&lt;filename&gt;|&lt;housekeeping&gt; [&lt;clean&gt;] [&lt;yes&gt;]|&lt;preserve&gt; [&lt;filename&gt;]]</code> <br> <code>updatefhem [&lt;filename&gt;|&lt;housekeeping&gt; [&lt;clean&gt;] [&lt;yes&gt;]|&lt;preserve&gt; [&lt;filename&gt;]]</code> <br>
<br> <br>
Update the fhem modules and documentation from a nightly SVN checkout. For 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 timestamps of the local files with the filelist on the server, and
downloads the files changed on the server. For all downloaded modules a downloads the files changed on the server. For all downloaded modules a
reload will be scheduled if the corresponding module is loaded. 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
&lt;housekeeping&gt; arguments. &lt;housekeeping&gt; arguments.
<br> <br>
<br> <br>
If &lt;backup&gt; is specified, then the complete FHEM directory (containing The complete installation of Fhem will be saved via the <a href="#backup">backup</a>
the modules), the WebInterface pgm2 (if installed) and the config-file will command on every update. You can skip this backups by setting
be saved into a .tar.gz file. The file is stored with a timestamp in the the global attribute <a href="#backup_before_update">backup_before_update</a> to 0.
modpath/backup directory or to a directory specified
by the <a href="#backupdir">backupdir</a> global attribute.<br>
Note: tar and gzip must be installed to use this feature.
<br> <br>
<br> <br>
If an explicit &lt;filename&gt; is given, then only this file will be If an explicit &lt;filename&gt; 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. only connections from these addresses are allowed.
</li><br> </li><br>
<a name="backup_before_update"></a>
<li>backup_before_update<br>
If this attribute is set to 0, updatefhem skip always backing up your
installation via the <a href="#backup">backup</a> command. The default
is to backup always before updates.<br>
Note: Set this attribute only if you know what you do!<br>
This Attribute is used by the <a href="#updatefhem">updatefhem</a> command.<br>
Example:<br>
<ul>
attr global backup_before_update 0
</ul>
</li><br>
<a name="backupcmd"></a> <a name="backupcmd"></a>
<li>backupcmd<br> <li>backupcmd<br>
You could pass the backup to your own command / script by using this attribute. 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/FHEM /usr/share/fhem/foo /usr/share/fhem/foobar
/usr/share/fhem/www"</code> /usr/share/fhem/www"</code>
</ul> </ul>
Note: Your command / script has to return the string "backup done" or
everything else to report errors, to work properly with updatefhem!<br>
This Attribute is used by the <a href="#backup">backup</a> command.<br> This Attribute is used by the <a href="#backup">backup</a> command.<br>
Example:<br> Example:<br>
<ul> <ul>

View File

@ -194,7 +194,7 @@ $modules{Global}{AttrList} =
"modpath nrarchive pidfilename port statefile title userattr " . "modpath nrarchive pidfilename port statefile title userattr " .
"verbose:1,2,3,4,5 mseclog version nofork logdir holiday2we " . "verbose:1,2,3,4,5 mseclog version nofork logdir holiday2we " .
"autoload_undefined_devices dupTimeout latitude longitude ". "autoload_undefined_devices dupTimeout latitude longitude ".
"backupcmd backupdir backupsymlink"; "backupcmd backupdir backupsymlink backup_before_update";
$modules{Global}{AttrFn} = "GlobalAttr"; $modules{Global}{AttrFn} = "GlobalAttr";