Source for file backupdatabase.php

Documentation is available at backupdatabase.php

  1. <?php
  2. /**
  3. * Create a dump of the database for backup purposes
  4. *
  5. @author    Stuart Prescott
  6. @copyright  Copyright Stuart Prescott
  7. @license    http://opensource.org/licenses/gpl-license.php GNU Public License
  8. @version    $Id$
  9. @package    Bumblebee
  10. @subpackage Actions
  11. *
  12. *  path (bumblebee root)/inc/actions/backupdatabase.php
  13. */
  14.  
  15. /** Load ancillary functions */
  16. require_once 'inc/typeinfo.php';
  17.  
  18. require_once 'inc/bb/configreader.php';
  19.  
  20. /** parent object */
  21. require_once 'inc/actions/bufferedaction.php';
  22. /** status codes for success/failure of database actions */
  23. require_once 'inc/statuscodes.php';
  24.  
  25. /**
  26. * Create a dump of the database for backup purposes
  27. @package    Bumblebee
  28. @subpackage Actions
  29. */
  30. class ActionBackupDB extends BufferedAction {
  31.  
  32.   /**
  33.   * Initialising the class
  34.   *
  35.   * @param  BumblebeeAuth $auth  Authorisation object
  36.   * @param  array $pdata   extra state data from the call path
  37.   * @return void nothing
  38.   */
  39.   function ActionBackupDB($auth$pdata{
  40.     parent::BufferedAction($auth$pdata);
  41.   }
  42.  
  43.   function go({
  44.     $success $this->makeDump();
  45.     //echo $success;
  46.     //echo $this->errorMessage;
  47.     echo $this->reportAction($success,
  48.               array(STATUS_ERR =>  T_('Error making backup: ').$this->errorMessage
  49.                    )
  50.                );
  51.   }
  52.  
  53.   /**
  54.   * Make the sql dump and save it to memory for output later
  55.   */
  56.   function makeDump({
  57.     // get a MySQL dump of the database
  58.     $conf ConfigReader::getInstance();
  59.     $output array();
  60.     $retstring exec($this->_mysqldump_invocation(.' 2>&1',
  61.                 $output,
  62.                 $returnError);
  63.     $dump join($output"\n");
  64.     if ($returnError{
  65.       return $this->unbufferForError($dump);
  66.     else {
  67.       // $dump now contains the data stream.
  68.       // let's work out a nice filename and dump it out
  69.       $this->filename = $this->getFilename('backup'$conf->value('database''dbname')'sql');
  70.       $this->bufferedStream = $dump;
  71.       // the data itself will be dumped later by the action driver (index.php)
  72.     }
  73.   }
  74.  
  75.  
  76.   /**
  77.   * Send the sql dump to the browser immediately
  78.   * (can't be used if you have heavy HTML templates)
  79.   */
  80.   function godirect({
  81.     $this->startOutputTextFile($filename);
  82.     system($this->_mysqldump_invocation(),
  83.                 $returnError);
  84.   }
  85.  
  86.   /**
  87.   * Obtain the correct mysqldump command line to make the backup
  88.   */
  89.   function _mysqldump_invocation({
  90.     $conf ConfigReader::getInstance();
  91.     return $conf->value('sqldump''mysqldump').' '
  92.                 .$conf->value('sqldump''options')
  93.                 .' --host='.escapeshellarg($conf->value('database''host'))
  94.                 .' --user='.escapeshellarg($conf->value('database''username'))
  95.                 .' --password='.escapeshellarg($conf->value('database''passwd'))
  96.                 .' '.escapeshellarg($conf->value('database''database'))
  97.             ;
  98.   }
  99. }
  100.  
  101. ?>

Documentation generated on Tue, 06 Mar 2007 10:00:37 +0000 by phpDocumentor 1.3.0