/**
  * Exports the database
  * @return string Filename path
  * @uses DatabaseBackup\Utility\Backup::rotate()
  * @uses _executable()
  * @uses _extension()
  * @uses compression()
  * @uses filename()
  * @uses $compression
  * @uses $connection
  * @uses $directory
  * @uses $executable
  * @uses $extension
  * @uses $filename
  * @uses $rotate
  * @throws InternalErrorException
  */
 public function export()
 {
     //Sets default compression type
     if (empty($this->compression)) {
         $this->compression('none');
     }
     //Sets the executable and the extension
     $this->_executable();
     $this->_extension();
     //Sets the default filename where to export the database
     //This is not done in the constructor, because you can set and
     //alternative output directory
     if (empty($this->filename)) {
         $this->filename(sprintf('backup_{$DATABASE}_{$DATETIME}.%s', $this->extension));
     }
     //For security reasons, it's recommended to specify the password in
     //a configuration file and not in the command (a user can execute
     //a `ps aux | grep mysqldump` and see the password).
     //So it creates a temporary file to store the configuration options
     $auth = tempnam(sys_get_temp_dir(), 'auth');
     file_put_contents($auth, sprintf("[mysqldump]\nuser=%s\npassword=\"%s\"\nhost=%s", $this->connection['username'], $this->connection['password'], $this->connection['host']));
     //Executes
     exec(sprintf($this->executable, $auth, $this->connection['database'], $this->filename));
     //Deletes the temporary file
     unlink($auth);
     if (!is_readable($this->filename)) {
         throw new InternalErrorException(__d('database_backup', 'File or directory {0} has not been created', $this->filename));
     }
     chmod($this->filename, 0766);
     //Rotates backups
     if (!empty($this->rotate)) {
         Backup::rotate($this->rotate);
     }
     return $this->filename;
 }
 /**
  * Rotates backups.
  *
  * You must indicate the number of backups you want to keep. So, it will
  *  delete all backups that are older
  * @param int $keep Number of files that you want to keep
  * @return void
  * @uses DatabaseBackup\Utility\Backup::rotate()
  */
 public function rotate($keep)
 {
     try {
         //Gets deleted files
         $deleted = Backup::rotate($keep);
         if ($deleted) {
             foreach ($deleted as $file) {
                 $this->verbose(__d('database_backup', 'The file {0} has been deleted', $file));
             }
             $this->success(__d('database_backup', 'Deleted backup files: {0}', count($deleted)));
         } else {
             $this->verbose(__d('database_backup', 'No file has been deleted'));
         }
     } catch (InternalErrorException $e) {
         $this->abort($e->getMessage());
     }
 }