Changeset 13484 for modules

Show
Ignore:
Timestamp:
02/20/12 14:50:27 (1 year ago)
Author:
p_lindheimer
Message:

fixes #5598 move filtering to grep outside of php process, minimally fixes #5599 adds some logging on SQL dump error condition but a new ticket should be filed for much better integrity checking and reporting then this.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • modules/branches/2.10/backup/functions.inc/class.backup.php

    r13184 r13484  
    179179          //build command 
    180180          $s = str_replace('server-', '', $i['path']); 
     181          $sql_file = $this->b['_tmpdir'] . '/' . 'mysql-' . $s . '.sql'; 
    181182          $cmd[] = fpbx_which('mysqldump'); 
    182183          $cmd[] = '--host='    . backup__($this->s[$s]['host']); 
     
    193194          } 
    194195          $cmd[] = ' --opt --skip-comments'; 
    195           //$cmd[] = ' > ' . $this->b['_tmpdir'] . '/' . 'mysql-' . $s . '.sql'; 
     196 
     197          // Need to grep out leading /* comments and SET commands as they create problems 
     198          // restoring using the PEAR $db class 
     199          // 
     200          $cmd[] = ' | '; 
     201          $cmd[] = fpbx_which('grep'); 
     202          $cmd[] = "-v '^\/\*\|^SET'"; 
     203          $cmd[] = ' > ' .  $sql_file; 
     204           
    196205          exec(implode(' ', $cmd), $file, $status); 
    197  
    198           //dont keep the file if the command failed somehow 
     206          unset($cmd, $file); 
     207 
     208          // remove file and log error information if it failed. 
     209          // 
    199210          if ($status !== 0) { 
    200             unlink($this->b['_tmpdir'] . '/' . 'mysql-' . $s); 
    201           } else { 
    202             //remove comments from the file, otherwise we have difficulty restoring 
    203             foreach ($file as $f => $line) { 
    204               if (substr($line, 0, 2) == '/*' || substr($line, 0, 3) == 'SET') { 
    205                 unset($file[$f]); 
    206               } 
    207             } 
    208             file_put_contents($this->b['_tmpdir'] . '/' . 'mysql-' . $s . '.sql',  
    209                       implode("\n", $file)); 
    210           } 
    211 
    212           unset($cmd, $file); 
     211            unlink($sql_file); 
     212            $error_string = sprintf( 
     213              _("Backup failed dumping SQL database [%s] to file [%s], you have a corrupted backup from server [%s]."), 
     214              backup__($this->s[$s]['dbname']), $sql_file, backup__($this->s[$s]['host'])  
     215            ); 
     216            backup_log($error_string); 
     217            freepbx_log(FPBX_LOG_FATAL, $error_string); 
     218          } 
    213219          break; 
    214220        case 'astdb': 
     
    220226      } 
    221227    } 
    222      
    223      
    224228  } 
    225229