From 53a535c7109236360e061e8cf269442a5b3e1c0c Mon Sep 17 00:00:00 2001 From: mfr69bs <> Date: Fri, 1 Jun 2012 21:34:21 +0000 Subject: [PATCH] 99_backup.pm supports if set as a global attribute git-svn-id: https://svn.fhem.de/fhem/trunk@1594 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/CHANGED | 1 + fhem/FHEM/99_backup.pm | 31 +++++++-------- fhem/HISTORY | 3 ++ fhem/docs/commandref.html | 80 ++++++++++++++++++++++++++++++++------- fhem/fhem.pl | 3 +- 5 files changed, 85 insertions(+), 33 deletions(-) diff --git a/fhem/CHANGED b/fhem/CHANGED index 1ac532c88..d4c7eb2d8 100644 --- a/fhem/CHANGED +++ b/fhem/CHANGED @@ -35,6 +35,7 @@ backup and uninstall added. More verbose output. (M. Fischer) - feature: new command backup added (M. Fischer) - feature: new global attribute added + - feature: new global attribute added - 2011-12-31 (5.2) - bugfix: applying smallscreen attributes to firefox/opera diff --git a/fhem/FHEM/99_backup.pm b/fhem/FHEM/99_backup.pm index a5e0f4d06..de3c833df 100644 --- a/fhem/FHEM/99_backup.pm +++ b/fhem/FHEM/99_backup.pm @@ -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; diff --git a/fhem/HISTORY b/fhem/HISTORY index d5083957f..051a11cf4 100644 --- a/fhem/HISTORY +++ b/fhem/HISTORY @@ -502,3 +502,6 @@ - Thu May 31 2012 (M. Fischer) - Added new global attribute + +- Fri Jun 01 2012 (M. Fischer) + - Added new global attribute diff --git a/fhem/docs/commandref.html b/fhem/docs/commandref.html index 6182b526c..354279c2c 100644 --- a/fhem/docs/commandref.html +++ b/fhem/docs/commandref.html @@ -30,6 +30,7 @@ + +

backup

+
    + backup
    +
    + 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.
    + Note: tar and gzip must be installed to use this feature. +
    +
    + If you need to call tar with support for symlinks, you could set the + global attribute backupsymlink to everything + else as "no". +
    +
    + You could pass the backup to your own command / script by using the + global attribute backupcmd. +
    +
    +
+

define

@@ -804,20 +829,6 @@ A line ending with \ will be concatenated with the next one, so long lines
  • After running <housekeeping> it is recommended to restart Fhem.

  • - - - Attributes -
      - -
    • backupdir
      - A folder where updatefhem will store the compressed backup file. - Note: this is a global attribute.
      Example: -
        - attr global backupdir /Volumes/BigHD
        -
      -
    • -
    - @@ -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.
    + +
  • backupcmd
    + 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 one + argument to the command, like e.g.: +
    +
      + "/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" +
    + This Attribute is used by the backup command.
    + Example:
    +
      + attr global backupcmd /usr/local/bin/myBackupScript.sh +
    +

  • + + +
  • backupdir
    + A folder to store the compressed backup file. + This Attribute is used by the backup command.
    + Example:
    +
      + attr global backupdir /Volumes/BigHD +
    +

  • + + +
  • backupsymlink
    + 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 backup command.
    + Example:
    +
      + attr global backupsymlinks yes +
    +

  • +
  • configfile
    Contains the name of the fhem configuration file. If