/**
  * Perform the file backup.
  *
  * @return bool Whether the backup completed successfully or not.
  */
 public function backup()
 {
     if (!Backup_Utilities::is_exec_available() || !$this->get_zip_executable_path()) {
         return false;
     }
     // cd to the site root
     $command[] = 'cd ' . escapeshellarg(Path::get_root());
     // Run the zip command with the recursive and quiet flags
     $command[] = '&& ' . escapeshellcmd($this->get_zip_executable_path()) . ' -rq';
     // Save the zip file to the correct path
     $command[] = escapeshellarg($this->get_backup_filepath()) . ' ./';
     // Pass exclude rules in if we have them
     if ($this->get_exclude_string()) {
         $command[] = '-x ' . $this->get_exclude_string();
     }
     // Push all output to STDERR
     $command[] = '2>&1';
     $command = implode(' ', $command);
     $output = $return_status = 0;
     exec($command, $output, $return_status);
     // Track any errors
     if ($output) {
         if ($return_status === 0) {
             $this->warning(__CLASS__, implode(', ', $output));
         } else {
             $this->error(__CLASS__, implode(', ', $output));
         }
     }
     return $this->verify_backup();
 }
 public function test_remove_default_command_path()
 {
     $paths = $this->paths;
     $paths[] = $path = trim(shell_exec('which mysql ' . ignore_stderr()));
     if (!$path) {
         $this->markTestSkipped('Couldn\'t find mysql');
     }
     unset($paths['mysql']);
     shuffle($paths);
     $this->assertEquals($path, Backup_Utilities::get_executable_path($paths));
 }
 function testSafeModeTrue()
 {
     $this->safe_mode = true;
     $this->assertEquals($this->ini_get_mock(), true);
     $this->assertTrue(Backup_Utilities::is_safe_mode_on(array($this, 'ini_get_mock')));
 }
Beispiel #4
0
function set_server_config_notices()
{
    $notices = Notices::get_instance();
    $messages = array();
    if (!is_dir(Path::get_path())) {
        $messages[] = sprintf(__('The backups directory can\'t be created because your %s directory isn\'t writable. Please create the folder manually.', 'backupwordpress'), '<code>' . esc_html(dirname(Path::get_path())) . '</code>');
    }
    if (is_dir(Path::get_path()) && !wp_is_writable(Path::get_path())) {
        $messages[] = __('The backups directory isn\'t writable. Please fix the permissions.', 'backupwordpress');
    }
    if (Backup_Utilities::is_safe_mode_on()) {
        $messages[] = sprintf(__('%1$s is running in %2$s, please contact your host and ask them to disable it. BackUpWordPress may not work correctly whilst %3$s is on.', 'backupwordpress'), '<code>PHP</code>', sprintf('<a href="%1$s">%2$s</a>', __('http://php.net/manual/en/features.safe-mode.php', 'backupwordpress'), __('Safe Mode', 'backupwordpress')), '<code>' . __('Safe Mode', 'backupwordpress') . '</code>');
    }
    if (defined('HMBKP_PATH') && HMBKP_PATH) {
        // Suppress open_basedir warning https://bugs.php.net/bug.php?id=53041
        if (!path_in_php_open_basedir(HMBKP_PATH)) {
            $messages[] = sprintf(__('Your server has an %1$s restriction in effect and your custom backups directory (%2$s) is not within the allowed path(s): (%3$s).', 'backupwordpress'), '<code>open_basedir</code>', '<code>' . esc_html(HMBKP_PATH) . '</code>', '<code>' . esc_html(@ini_get('open_basedir')) . '</code>');
        } elseif (!file_exists(HMBKP_PATH)) {
            $messages[] = sprintf(__('Your custom path does not exist', 'backupwordpress'));
        } else {
            if (!is_dir(HMBKP_PATH)) {
                $messages[] = sprintf(__('Your custom backups directory %1$s doesn\'t exist and can\'t be created, your backups will be saved to %2$s instead.', 'backupwordpress'), '<code>' . esc_html(HMBKP_PATH) . '</code>', '<code>' . esc_html(Path::get_path()) . '</code>');
            }
            if (is_dir(HMBKP_PATH) && !wp_is_writable(HMBKP_PATH)) {
                $messages[] = sprintf(__('Your custom backups directory %1$s isn\'t writable, new backups will be saved to %2$s instead.', 'backupwordpress'), '<code>' . esc_html(HMBKP_PATH) . '</code>', '<code>' . esc_html(Path::get_path()) . '</code>');
            }
        }
    }
    if (!is_readable(Path::get_root())) {
        $messages[] = sprintf(__('Your site root path %s isn\'t readable.', 'backupwordpress'), '<code>' . Path::get_root() . '</code>');
    }
    if (!Requirement_Mysqldump_Command_Path::test() && !Requirement_PDO::test()) {
        $messages[] = sprintf(__('Your database cannot be backed up because your server doesn\'t support %1$s or %2$s. Please contact your host and ask them to enable them.', 'backupwordpress'), '<code>mysqldump</code>', '<code>PDO</code>');
    }
    if (count($messages) > 0) {
        $notices->set_notices('server_config', $messages, false);
    }
}
 /**
  * @return bool
  */
 public static function test()
 {
     return Backup_Utilities::is_exec_available();
 }
 /**
  * @return bool
  */
 public static function test()
 {
     return Backup_Utilities::is_safe_mode_on();
 }