/** * Triggers the database backup including all DML and DDL and writes it out to a file. * * @param string $backupFileName An alternate file name for the backup file. * * @return string The path to the database backup file. */ public function run($backupFileName = '') { // Normalize the ignored table names if there is a table prefix set. if (($tablePrefix = craft()->config->get('tablePrefix', ConfigFile::Db)) !== '') { foreach ($this->_ignoreDataTables as $key => $tableName) { $this->_ignoreDataTables[$key] = $tablePrefix . '_' . $tableName; } } $this->_currentVersion = 'v' . craft()->getVersion() . '.' . craft()->getBuild(); $fileName = $backupFileName !== '' ? IOHelper::cleanFilename($backupFileName) : IOHelper::cleanFilename(craft()->getSiteName()) . '_' . gmdate('ymd_His') . '_' . $this->_currentVersion . '.sql'; $this->_filePath = craft()->path->getDbBackupPath() . StringHelper::toLowerCase($fileName); // Clear the file before beginning this backup. If you lose data, that's your problem! if (IOHelper::fileExists($this->_filePath)) { IOHelper::clearFile($this->_filePath); } $this->_processHeader(); foreach (craft()->db->getSchema()->getTables() as $resultName => $val) { $this->_processResult($resultName); } $this->_processConstraints(); $this->_processFooter(); return $this->_filePath; }
/** * @return bool */ public function clear() { if (!IOHelper::clearFile($this->getRealPath())) { return false; } return true; }