/**
  * backup
  *
  * @param $options array(
  *      'backupDir'  => string // where to store the backup
  *      'noTimestamp => bool   // don't append timestamp to backup dir
  *      'config'     => bool   // backup config
  *      'db'         => bool   // backup database
  *      'files'      => bool   // backup files
  *    )
  */
 public function backup($options)
 {
     $config = Setup_Core::getConfig();
     $backupDir = isset($options['backupDir']) ? $options['backupDir'] : $config->backupDir;
     if (!$backupDir) {
         throw new Exception('backupDir not configured');
     }
     if (!isset($options['noTimestamp'])) {
         $backupDir .= '/' . date_create('now', new DateTimeZone('UTC'))->format('Y-m-d-H-i-s');
     }
     if (!is_dir($backupDir) && !mkdir($backupDir, 0700, true)) {
         throw new Exception("{$backupDir} could  not be created");
     }
     if ($options['config']) {
         $configFile = stream_resolve_include_path('config.inc.php');
         $configDir = dirname($configFile);
         $files = file_exists("{$configDir}/index.php") ? 'config.inc.php' : '.';
         `cd {$configDir}; tar cjf {$backupDir}/tine20_config.tar.bz2 {$files}`;
     }
     if ($options['db']) {
         if (!$this->_backend) {
             throw new Exception('db not configured, cannot backup');
         }
         $backupOptions = array('backupDir' => $backupDir, 'structTables' => $this->_getBackupStructureOnlyTables());
         $this->_backend->backup($backupOptions);
     }
     $filesDir = isset($config->filesdir) ? $config->filesdir : false;
     if ($options['files'] && $filesDir) {
         `cd {$filesDir}; tar cjf {$backupDir}/tine20_files.tar.bz2 .`;
     }
 }