/** Backups changed files before an update. */ public function backup($zip_file, $zip_digests, $root, $root_digests, $dest) { if (!is_readable($zip_file)) { throw new Exception(__('Archive not found.')); } if (!is_readable($root_digests)) { @unlink($zip_file); throw new Exception(__('Unable to read current digests file.')); } # Stop everything if a backup already exists and can not be overrided if (!is_writable(dirname($dest)) && !file_exists($dest)) { throw new Exception(__('Root directory is not writable.')); } if (file_exists($dest) && !is_writable($dest)) { return false; } $b_fp = @fopen($dest, 'wb'); if ($b_fp === false) { return false; } $zip = new fileUnzip($zip_file); $b_zip = new fileZip($b_fp); if (!$zip->hasFile($zip_digests)) { @unlink($zip_file); throw new Exception(__('Downloaded file seems not to be a valid archive.')); } $opts = FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES; $cur_digests = file($root_digests, $opts); $new_digests = explode("\n", $zip->unzip($zip_digests)); $new_files = $this->getNewFiles($cur_digests, $new_digests); $zip->close(); unset($opts, $cur_digests, $new_digests, $zip); $not_readable = array(); if (!empty($this->forced_files)) { $new_files = array_merge($new_files, $this->forced_files); } foreach ($new_files as $file) { if (!$file || !file_exists($root . '/' . $file)) { continue; } try { $b_zip->addFile($root . '/' . $file, $file); } catch (Exception $e) { $not_readable[] = $file; } } # If only one file is not readable, stop everything now if (!empty($not_readable)) { $e = new Exception('Some files are not readable.', self::ERR_FILES_UNREADABLE); $e->bad_files = $not_readable; throw $e; } $b_zip->write(); fclose($b_fp); $b_zip->close(); return true; }
/** * Backups changed files before an update. * * @param string $sZipFile * @param string $sZipDigests * @param string $sRoot * @param string $sRootDigests * @param string $sDest * @throws Exception * @return boolean */ public function backup($sZipFile, $sZipDigests, $sRoot, $sRootDigests, $sDest) { if (!is_readable($sZipFile)) { throw new Exception(__('c_a_update_archive_not_found')); } if (!is_readable($sRootDigests)) { @unlink($sZipFile); throw new Exception(__('c_a_update_unable_read_digests')); } # Stop everything if a backup already exists and can not be overrided if (!is_writable(dirname($sDest)) && !file_exists($sDest)) { throw new Exception(__('c_a_update_root_directory_not_writable')); } if (file_exists($sDest) && !is_writable($sDest)) { return false; } $b_fp = @fopen($sDest, 'wb'); if ($b_fp === false) { return false; } $oZip = new fileUnzip($sZipFile); $b_zip = new fileZip($b_fp); if (!$oZip->hasFile($sZipDigests)) { @unlink($sZipFile); throw new Exception(__('c_a_update_downloaded_file_not_valid_archive')); } $opts = FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES; $cur_digests = file($sRootDigests, $opts); $new_digests = explode("\n", $oZip->unzip($sZipDigests)); $aNewFiles = $this->getNewFiles($cur_digests, $new_digests); $oZip->close(); unset($opts, $cur_digests, $new_digests, $oZip); $aNotReadable = array(); if (!empty($this->aForcedFiles)) { $aNewFiles = array_merge($aNewFiles, $this->aForcedFiles); } foreach ($aNewFiles as $file) { if (!$file || !file_exists($sRoot . '/' . $file)) { continue; } try { $b_zip->addFile($sRoot . '/' . $file, $file); } catch (Exception $e) { $aNotReadable[] = $file; } } # If only one file is not readable, stop everything now if (!empty($aNotReadable)) { $e = new Exception('Some files are not readable.', self::ERR_FILES_UNREADABLE); $e->bad_files = $aNotReadable; throw $e; } $b_zip->write(); fclose($b_fp); $b_zip->close(); return true; }
// @ini_set('memory_limit',-1); set_time_limit(0); $zip = new fileZip($fp); //$zip->addExclusion('#(^|/).(.*?)_(m|s|sq|t).jpg$#'); $zip->addExclusion('#(^|/)_notes$#'); $zip->addExclusion('#(^|/)_old$#'); $zip->addExclusion('#(^|/)_source$#'); $zip->addExclusion('#(^|/)_sources$#'); $zip->addExclusion('#(^|/).svn$#'); $zip->addExclusion('#(^|/)oktCache$#'); $zip->addExclusion('#(^|/)stats$#'); $zip->addExclusion('#(^|/)' . preg_quote($sBackupFilenameBase, '#') . '(.*?).zip$#'); $zip->addDirectory(OKT_ROOT_PATH, $sBackupFilenameBase, true); $zip->write(); fclose($fp); $zip->close(); $okt->redirect('configuration.php?action=tools&bakcup_done=1'); } catch (Exception $e) { $okt->error->set($e->getMessage()); } } # création d'un fichier de backup de la base de données if (!empty($_GET['make_db_backup'])) { $return = ''; $tables = $okt->db->getTables(); foreach ($tables as $table) { $return .= 'DROP TABLE IF EXISTS ' . $table . ';'; $row2 = $okt->db->fetchRow($okt->db->query('SHOW CREATE TABLE ' . $table)); $return .= "\n\n" . $row2[1] . ";\n\n"; $result = $okt->db->query('SELECT * FROM ' . $table); $num_fields = $okt->db->numFields($result);