/** * Create full backup */ public function createFullBackup($excludes, $filePrefix = '', $addConfig = false, $includeCoreFiles = false, $file_descriptors = 0, $fileSuffix = false, $excludezip = false, $excludenonwp = false, $loadFilesBeforeZip = true, $ext = 'zip', $pid = false, $append = false) { $this->file_descriptors = $file_descriptors; $this->loadFilesBeforeZip = $loadFilesBeforeZip; $dirs = MainWP_Helper::getMainWPDir('backup'); $backupdir = $dirs[0]; if (!defined('PCLZIP_TEMPORARY_DIR')) { define('PCLZIP_TEMPORARY_DIR', $backupdir); } if (false !== $pid) { $pid = trailingslashit($backupdir) . 'backup-' . $pid . '.pid'; } //Verify if another backup is running, if so, return an error $files = glob($backupdir . '*.pid'); foreach ($files as $file) { if (basename($file) == basename($pid)) { continue; } if (time() - filemtime($file) < 160) { MainWP_Helper::error('Another backup process is running, try again later'); } } $timestamp = time(); if ('' !== $filePrefix) { $filePrefix .= '-'; } if ('zip' == $ext) { $this->archiver = null; $ext = '.zip'; } else { $this->archiver = new Tar_Archiver($this, $ext, $pid); $ext = $this->archiver->getExtension(); } // throw new Exception('Test 1 2 : ' . print_r($append,1)); if (false !== $fileSuffix && !empty($fileSuffix)) { $file = $fileSuffix . (true === $append ? '' : $ext); //Append already contains extension! } else { $file = 'backup-' . $filePrefix . $timestamp . $ext; } $filepath = $backupdir . $file; $fileurl = $file; // if (!$append) // { // if ($dh = opendir($backupdir)) // { // while (($file = readdir($dh)) !== false) // { // if ($file != '.' && $file != '..' && preg_match('/(.*).(zip|tar|tar.gz|tar.bz2|pid|done)$/', $file)) // { // @unlink($backupdir . $file); // } // } // closedir($dh); // } // } if (!$addConfig) { if (!in_array(str_replace(ABSPATH, '', WP_CONTENT_DIR), $excludes) && !in_array('wp-admin', $excludes) && !in_array(WPINC, $excludes)) { $addConfig = true; $includeCoreFiles = true; } } $this->timeout = 20 * 60 * 60; /*20 minutes*/ $mem = '512M'; // @codingStandardsIgnoreStart @ini_set('memory_limit', $mem); @set_time_limit($this->timeout); @ini_set('max_execution_time', $this->timeout); // @codingStandardsIgnoreEnd if (null !== $this->archiver) { $success = $this->archiver->createFullBackup($filepath, $excludes, $addConfig, $includeCoreFiles, $excludezip, $excludenonwp, $append); } else { if ($this->checkZipSupport()) { $success = $this->createZipFullBackup($filepath, $excludes, $addConfig, $includeCoreFiles, $excludezip, $excludenonwp); } else { if ($this->checkZipConsole()) { $success = $this->createZipConsoleFullBackup($filepath, $excludes, $addConfig, $includeCoreFiles, $excludezip, $excludenonwp); } else { $success = $this->createZipPclFullBackup2($filepath, $excludes, $addConfig, $includeCoreFiles, $excludezip, $excludenonwp); } } } return $success ? array('timestamp' => $timestamp, 'file' => $fileurl, 'filesize' => filesize($filepath)) : false; }