Esempio n. 1
0
 /**
  * Generate some posts.
  *
  * ## OPTIONS
  *
  * [--files_only]
  * : Backup files only, default to off
  *
  * [--database_only]
  * : Backup database only, defaults to off
  *
  * [--path]
  * : dir that the backup should be save in, defaults to wp-content/backups/
  *
  * [--root]
  * : dir that should be backed up, defaults to site root.
  *
  * [--zip_command_path]
  * : path to your zip binary, standard locations are automatically used
  *
  * [--mysqldump_command_path]
  * : path to your mysqldump binary, standard locations are automatically used
  *
  * ## Usage
  *
  *     wp backupwordpress backup [--files_only] [--database_only] [--path<dir>] [--root<dir>] [--zip_command_path=<path>] [--mysqldump_command_path=<path>]
  */
 public function backup($args, $assoc_args)
 {
     // Make sure it's possible to do a backup
     if (HM_Backup::is_safe_mode_active()) {
         WP_CLI::error(sprintf(__('BackUpWordPress may not work when php is running with %s on', 'hmbkp'), 'safe_mode'));
     }
     add_action('hmbkp_mysqldump_started', function () {
         WP_CLI::line(__('Backup: Dumping database...', 'hmbkp'));
     });
     add_action('hmbkp_archive_started', function () {
         WP_CLI::line(__('Backup: Zipping everything up...', 'hmbkp'));
     });
     // Clean up any mess left by a previous backup
     hmbkp_cleanup();
     $hm_backup = new HM_Backup();
     if (!empty($assoc_args['path'])) {
         $hm_backup->set_path($assoc_args['path']);
     }
     if (!empty($assoc_args['root'])) {
         $hm_backup->set_root($assoc_args['root']);
     }
     if (!is_dir($hm_backup->get_path()) && (!is_writable(dirname($hm_backup->get_path())) || !wp_mkdir_p($hm_backup->get_path())) || !is_writable($hm_backup->get_path())) {
         WP_CLI::error(__('Invalid backup path', 'hmbkp'));
         return false;
     }
     if (!is_dir($hm_backup->get_root()) || !is_readable($hm_backup->get_root())) {
         WP_CLI::error(__('Invalid root path', 'hmbkp'));
         return false;
     }
     if (!empty($assoc_args['files_only'])) {
         $hm_backup->set_type('file');
     }
     if (!empty($assoc_args['database_only'])) {
         $hm_backup->set_type('database');
     }
     if (isset($assoc_args['mysqldump_command_path'])) {
         $hm_backup->set_mysqldump_command_path($assoc_args['mysqldump_command_path']);
     }
     if (isset($assoc_args['zip_command_path'])) {
         $hm_backup->set_zip_command_path($assoc_args['zip_command_path']);
     }
     if (!empty($assoc_args['excludes'])) {
         $hm_backup->set_excludes($assoc_args['excludes']);
     }
     $hm_backup->backup();
     // Delete any old backup files
     //hmbkp_delete_old_backups();
     if (file_exists($hm_backup->get_archive_filepath())) {
         WP_CLI::success(__('Backup Complete: ', 'hmbkp') . $hm_backup->get_archive_filepath());
     } else {
         WP_CLI::error(__('Backup Failed', 'hmbkp'));
     }
 }
Esempio n. 2
0
/**
 * Displays admin notices for various error / warning
 * conditions
 *
 * @return void
 */
function hmbkp_admin_notices()
{
    // If the backups directory doesn't exist and can't be automatically created
    if (!is_dir(hmbkp_path())) {
        function hmbkp_path_exists_warning()
        {
            $php_user = exec('whoami');
            $php_group = reset(explode(' ', exec('groups')));
            echo '<div id="hmbkp-warning" class="updated fade"><p><strong>' . __('BackUpWordPress is almost ready.', 'hmbkp') . '</strong> ' . sprintf(__('The backups directory can\'t be created because your %1$s directory isn\'t writable, run %2$s or %3$s or create the folder yourself.', 'hmbkp'), '<code>wp-content</code>', '<code>chown ' . esc_html($php_user) . ':' . esc_html($php_group) . ' ' . esc_html(dirname(hmbkp_path())) . '</code>', '<code>chmod 777 ' . esc_html(dirname(hmbkp_path())) . '</code>') . '</p></div>';
        }
        add_action('admin_notices', 'hmbkp_path_exists_warning');
    }
    // If the backups directory exists but isn't writable
    if (is_dir(hmbkp_path()) && !is_writable(hmbkp_path())) {
        function hmbkp_writable_path_warning()
        {
            $php_user = exec('whoami');
            $php_group = reset(explode(' ', exec('groups')));
            echo '<div id="hmbkp-warning" class="updated fade"><p><strong>' . __('BackUpWordPress is almost ready.', 'hmbkp') . '</strong> ' . sprintf(__('Your backups directory isn\'t writable, run %1$s or %2$s or set the permissions yourself.', 'hmbkp'), '<code>chown -R ' . esc_html($php_user) . ':' . esc_html($php_group) . ' ' . esc_html(hmbkp_path()) . '</code>', '<code>chmod -R 777 ' . esc_html(hmbkp_path()) . '</code>') . '</p></div>';
        }
        add_action('admin_notices', 'hmbkp_writable_path_warning');
    }
    // If safe mode is active
    if (HM_Backup::is_safe_mode_active()) {
        function hmbkp_safe_mode_warning()
        {
            echo '<div id="hmbkp-warning" class="updated fade"><p><strong>' . __('BackUpWordPress has detected a problem.', 'hmbkp') . '</strong> ' . 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.', 'hmbkp'), '<code>PHP</code>', sprintf('<a href="%1$s">%2$s</a>', __('http://php.net/manual/en/features.safe-mode.php', 'hmbkp'), __('Safe Mode', 'hmbkp')), '<code>' . __('Safe Mode', 'hmbkp') . '</code>') . '</p></div>';
        }
        add_action('admin_notices', 'hmbkp_safe_mode_warning');
    }
    // If a custom backups directory is defined and it doesn't exist and can't be created
    if (defined('HMBKP_PATH') && HMBKP_PATH && !is_dir(HMBKP_PATH)) {
        function hmbkp_custom_path_exists_warning()
        {
            echo '<div id="hmbkp-warning" class="updated fade"><p><strong>' . __('BackUpWordPress has detected a problem.', 'hmbkp') . '</strong> ' . sprintf(__('Your custom backups directory %1$s doesn\'t exist and can\'t be created, your backups will be saved to %2$s instead.', 'hmbkp'), '<code>' . esc_html(HMBKP_PATH) . '</code>', '<code>' . esc_html(hmbkp_path()) . '</code>') . '</p></div>';
        }
        add_action('admin_notices', 'hmbkp_custom_path_exists_warning');
    }
    // If a custom backups directory is defined and exists but isn't writable
    if (defined('HMBKP_PATH') && HMBKP_PATH && is_dir(HMBKP_PATH) && !is_writable(HMBKP_PATH)) {
        function hmbkp_custom_path_writable_notice()
        {
            echo '<div id="hmbkp-warning" class="updated fade"><p><strong>' . __('BackUpWordPress has detected a problem.', 'hmbkp') . '</strong> ' . sprintf(__('Your custom backups directory %1$s isn\'t writable, new backups will be saved to %2$s instead.', 'hmbkp'), '<code>' . esc_html(HMBKP_PATH) . '</code>', '<code>' . esc_html(hmbkp_path()) . '</code>') . '</p></div>';
        }
        add_action('admin_notices', 'hmbkp_custom_path_writable_notice');
    }
    // If there are any errors reported in the backup
    if (hmbkp_backup_errors_message()) {
        function hmbkp_backup_errors_notice()
        {
            echo '<div id="hmbkp-warning" class="updated fade"><p><strong>' . __('BackUpWordPress detected issues with your last backup.', 'hmbkp') . '</strong><a href="' . esc_url(add_query_arg('action', 'hmbkp_dismiss_error')) . '" style="float: right;" class="button">Dismiss</a></p>' . hmbkp_backup_errors_message() . '</div>';
        }
        add_action('admin_notices', 'hmbkp_backup_errors_notice');
    }
}
Esempio n. 3
0
 function testSafeModeTrue()
 {
     $this->safe_mode = true;
     $this->assertEquals($this->ini_get_mock(), true);
     $this->assertTrue(HM_Backup::is_safe_mode_active(array($this, 'ini_get_mock')));
 }
 /**
  * @return bool
  */
 protected function test()
 {
     return HM_Backup::is_safe_mode_active();
 }
Esempio n. 5
0
function hmbkp_set_server_config_notices()
{
    $notices = HMBKP_Notices::get_instance();
    $messages = array();
    if (!HM_Backup::is_shell_exec_available()) {
        $php_user = '******';
        $php_group = '<PHP GROUP>';
    } else {
        $php_user = shell_exec('whoami');
        $groups = explode(' ', shell_exec('groups'));
        $php_group = reset($groups);
    }
    if (!is_dir(hmbkp_path())) {
        $messages[] = sprintf(__('The backups directory can\'t be created because your %1$s directory isn\'t writable, run %2$s or %3$s or create the folder yourself.', 'backupwordpress'), '<code>' . esc_html(dirname(hmbkp_path())) . '</code>', '<code>chown ' . esc_html($php_user) . ':' . esc_html($php_group) . ' ' . esc_html(dirname(hmbkp_path())) . '</code>', '<code>chmod 777 ' . esc_html(dirname(hmbkp_path())) . '</code>');
    }
    if (is_dir(hmbkp_path()) && !wp_is_writable(hmbkp_path())) {
        $messages[] = sprintf(__('Your backups directory isn\'t writable, run %1$s or %2$s or set the permissions yourself.', 'backupwordpress'), '<code>chown -R ' . esc_html($php_user) . ':' . esc_html($php_group) . ' ' . esc_html(hmbkp_path()) . '</code>', '<code>chmod -R 777 ' . esc_html(hmbkp_path()) . '</code>');
    }
    if (HM_Backup::is_safe_mode_active()) {
        $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 (!@file_exists(HMBKP_PATH)) {
            $messages[] = sprintf(__('Your custom path does not exist', 'backupwordpress'));
        } elseif (hmbkp_is_restricted_custom_path()) {
            $messages[] = sprintf(__('Your custom path is unreachable due to a restriction set in your PHP configuration (open_basedir)', '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(hmbkp_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(hmbkp_path()) . '</code>');
            }
        }
    }
    $test_backup = new HMBKP_Scheduled_Backup('test_backup');
    if (!is_readable($test_backup->get_root())) {
        $messages[] = sprintf(__('Your site root path %s isn\'t readable.', 'backupwordpress'), '<code>' . $test_backup->get_root() . '</code>');
    }
    if (count($messages) > 0) {
        $notices->set_notices('server_config', $messages, false);
    }
}