protected function execute($arguments = array(), $options = array())
 {
     $databaseManager = new sfDatabaseManager($this->configuration);
     $connection = $databaseManager->getDatabase($options['connection'])->getConnection();
     if (!function_exists('exec')) {
         throw new sfException('You must be able to run the exec() php function.');
     }
     $amazon = new sfAmazon();
     $s3 = $amazon->getS3();
     if (!$s3->if_bucket_exists($arguments['bucket'])) {
         throw new sfException(sprintf('The bucket "%s" does not exist', $arguments['bucket']));
     }
     $backupFiles = array();
     $configHandler = new sfDatabaseConfigHandler();
     $databases = $configHandler->getConfiguration(array($this->configuration->getRootDir() . '/config/databases.yml'));
     foreach ($databases as $databaseName => $conn) {
         $backupFiles[] = $backupFilename = $databaseName . '-' . date('Y-m-d') . '.gz';
         $user = $conn['param']['username'];
         $pass = $conn['param']['password'];
         $dsn = $conn['param']['dsn'];
         $host = preg_match("/host=(\\w*);/", $dsn, $match);
         $host = $match[1];
         $dbname = preg_match("/dbname=(\\w*)/", $dsn, $match);
         $dbname = $match[1];
         exec(sprintf('mysqldump --host=%s --user=%s --password=%s --quick --add-drop-table -v --databases %s | gzip -c > %s', $host, $user, $pass, $dbname, $backupFilename));
         $s3->batch()->create_object($arguments['bucket'], $backupFilename, array('fileUpload' => $backupFilename));
     }
     $response = $s3->batch()->send();
     if ($response->areOk()) {
         $this->log('pushed to s2 bucket');
         foreach ($backupFiles as $file) {
             unlink($file);
         }
     }
 }
示例#2
0
 /**
  * Loads database configuration.
  */
 public function loadConfiguration()
 {
     if ($this->configuration instanceof sfApplicationConfiguration) {
         $databases = (include $this->configuration->getConfigCache()->checkConfig('config/databases.yml'));
     } else {
         $configHandler = new sfDatabaseConfigHandler();
         $databases = $configHandler->evaluate(array($this->configuration->getRootDir() . '/config/databases.yml'));
     }
     foreach ($databases as $name => $database) {
         $this->setDatabase($name, $database);
     }
 }