2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-01-31 06:39:11 +00:00

99_backup.pm supports <backupcmd> if set as a global attribute

git-svn-id: https://svn.fhem.de/fhem/trunk@1594 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
mfr69bs 2012-06-01 21:34:21 +00:00
parent 3847f7d8d1
commit 53a535c710
5 changed files with 85 additions and 33 deletions

View File

@ -35,6 +35,7 @@
backup and uninstall added. More verbose output. (M. Fischer)
- feature: new command backup added (M. Fischer)
- feature: new global attribute <backupsymlink> added
- feature: new global attribute <backupcmd> added
- 2011-12-31 (5.2)
- bugfix: applying smallscreen attributes to firefox/opera

View File

@ -39,16 +39,6 @@ backup_Initialize($$)
my %hash = ( Fn => "CommandBackup",
Hlp => ",create a backup of fhem configuration, state and modpath" );
$cmds{backup} = \%hash;
$modules{Global}{AttrList} .= " backupsymlink";
### remove me start
# my $dateTime = TimeNow();
# $dateTime =~ s/ /_/g;
# $dateTime =~ s/(:|-)//g;
# my $ret = `(cp /usr/share/fhem/FHEM/99_backup.pm /home/martin/src/fhem/build/backup/99_backup.pm-$dateTime) 2>&1`;
# Log 0, "==> copy 99_backup.pm to /home/martin/src/fhem/build/backup/99_backup.pm-$dateTime";
### remove me end
}
#####################################
@ -162,6 +152,7 @@ sub
createArchiv($)
{
my $backupdir = shift;
my $backupcmd = (!defined($attr{global}{backupcmd}) ? undef : $attr{global}{backupcmd});
my $symlink = (!defined($attr{global}{backupsymlink}) ? "no" : $attr{global}{backupsymlink});
my $tarOpts;
my $msg;
@ -171,19 +162,23 @@ createArchiv($)
$dateTime =~ s/ /_/g;
$dateTime =~ s/(:|-)//g;
if (lc($symlink) eq "no") {
$tarOpts = "cf";
} else {
$tarOpts = "chf";
}
if (!defined($backupcmd)) {
if (lc($symlink) eq "no") {
$tarOpts = "cf";
} else {
$tarOpts = "chf";
}
# prevents tar's output of "Removing leading /" and return total bytes of archive
$ret = `(tar -$tarOpts - @pathname | gzip > $backupdir/FHEM-$dateTime.tar.gz) 2>&1`;
# prevents tar's output of "Removing leading /" and return total bytes of archive
$ret = `(tar -$tarOpts - @pathname | gzip > $backupdir/FHEM-$dateTime.tar.gz) 2>&1`;
} else {
$ret = `($backupcmd "@pathname") 2>&1`;
}
if($ret) {
chomp $ret;
Log 1, "backup $ret";
}
if (-e "$backupdir/FHEM-$dateTime.tar.gz") {
if (!defined($backupcmd) && -e "$backupdir/FHEM-$dateTime.tar.gz") {
my $size = -s "$backupdir/FHEM-$dateTime.tar.gz";
$msg = "backup done: FHEM-$dateTime.tar.gz ($size Bytes)";
Log 1, $msg;

View File

@ -502,3 +502,6 @@
- Thu May 31 2012 (M. Fischer)
- Added new global attribute <backupsymlink>
- Fri Jun 01 2012 (M. Fischer)
- Added new global attribute <backupcmd>

View File

@ -30,6 +30,7 @@
<ul>
<a href="#attr">attr</a> &nbsp;
<a href="#backup">backup</a> &nbsp;
<a href="#CULflash">CULflash</a> &nbsp;
<a href="#createlog">createlog</a> &nbsp;
<a href="#define">define</a> &nbsp;
@ -473,6 +474,30 @@ A line ending with \ will be concatenated with the next one, so long lines
</ul>
<a name="backup"></a>
<h3>backup</h3>
<ul>
<code>backup</code><br>
<br>
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 <a href="#backupdir">backupdir</a>
global attribute.<br>
Note: tar and gzip must be installed to use this feature.
<br>
<br>
If you need to call tar with support for symlinks, you could set the
global attribute <a href="#backupsymlink">backupsymlink</a> to everything
else as "no".
<br>
<br>
You could pass the backup to your own command / script by using the
global attribute <a href="#backupcmd">backupcmd</a>.
<br>
<br>
</ul>
<a name="define"></a>
<h3>define</h3>
@ -804,20 +829,6 @@ A line ending with \ will be concatenated with the next one, so long lines
<li>After running &lt;housekeeping&gt; it is recommended to restart Fhem.</li>
</ul>
<br>
<b>Attributes</b>
<ul>
<a name="backupdir"></a>
<li>backupdir<br>
A folder where updatefhem will store the compressed backup file.
Note: this is a global attribute.<br>Example:
<ul>
attr global backupdir /Volumes/BigHD<br>
</ul>
</li>
</ul>
</ul>
<a name="CULflash"></a>
@ -1164,6 +1175,47 @@ A line ending with \ will be concatenated with the next one, so long lines
only connections from these addresses are allowed.
</li><br>
<a name="backupcmd"></a>
<li>backupcmd<br>
You could pass the backup to your own command / script by using this attribute.
If this attribute is specified, then it will be started as a shell command and
passes a space separated list of files / directories as <strong>one</strong>
argument to the command, like e.g.:
<br>
<ul>
<code>"/etc/fhem.cfg /var/log/fhem/fhem.save /usr/share/fhem/contrib
/usr/share/fhem/FHEM /usr/share/fhem/foo /usr/share/fhem/foobar
/usr/share/fhem/www"</code>
</ul>
This Attribute is used by the <a href="#backup">backup</a> command.<br>
Example:<br>
<ul>
attr global backupcmd /usr/local/bin/myBackupScript.sh
</ul>
</li><br>
<a name="backupdir"></a>
<li>backupdir<br>
A folder to store the compressed backup file.
This Attribute is used by the <a href="#backup">backup</a> command.<br>
Example:<br>
<ul>
attr global backupdir /Volumes/BigHD
</ul>
</li><br>
<a name="backupsymlink"></a>
<li>backupsymlink<br>
If this attribute is set to everything else as "no", the archive command tar
will support symlinks in your backup. Otherwise, if this attribute is set to
"no" symlinks are ignored by tar.
This Attribute is used by the <a href="#backup">backup</a> command.<br>
Example:<br>
<ul>
attr global backupsymlinks yes
</ul>
</li><br>
<a name="configfile"></a>
<li>configfile<br>
Contains the name of the fhem configuration file. If <a

View File

@ -193,7 +193,8 @@ $modules{Global}{AttrList} =
"archivecmd allowfrom apiversion 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 backupdir backupsymlink";
"autoload_undefined_devices dupTimeout latitude longitude ".
"backupcmd backupdir backupsymlink";
$modules{Global}{AttrFn} = "GlobalAttr";