Exemplo n.º 1
0
/**
 * Setup the HM_Backup class
 *
 * @return null
 */
function hmbkp_setup_hm_backup()
{
    $hm_backup = HM_Backup::get_instance();
    $hm_backup->path = hmbkp_path();
    $hm_backup->files_only = hmbkp_get_files_only();
    $hm_backup->database_only = hmbkp_get_database_only();
    if (defined('HMBKP_MYSQLDUMP_PATH')) {
        $hm_backup->mysql_command_path = HMBKP_MYSQLDUMP_PATH;
    }
    if (defined('HMBKP_ZIP_PATH')) {
        $hm_backup->zip_command_path = HMBKP_ZIP_PATH;
    }
    $hm_backup->excludes = hmbkp_valid_custom_excludes();
}
Exemplo n.º 2
0
/**
 * Get the exclude string from HM Backup
 *
 * @param string $context
 * @return string
 */
function hmbkp_exclude_string($context)
{
    return HM_Backup::get_instance()->exclude_string($context);
}
Exemplo n.º 3
0
 function __construct($args, $assoc_args)
 {
     // Make sure it's possible to do a backup
     if (hmbkp_is_safe_mode_active()) {
         WP_CLI::error('Backup not possible when php is running safe_mode on');
         return false;
     }
     remove_action('hmbkp_backup_started', 'hmbkp_set_status', 10, 0);
     remove_action('hmbkp_mysqldump_started', 'hmbkp_set_status_dumping_database');
     remove_action('hmbkp_archive_started', 'hmbkp_set_status_archiving');
     add_action('hmbkp_mysqldump_started', function () {
         WP_CLI::line('Backup: Dumping database...');
     });
     add_action('hmbkp_archive_started', function () {
         WP_CLI::line('Backup: Zipping everything up...');
     });
     // Clean up any mess left by a previous backup
     hmbkp_cleanup();
     $hm_backup = HM_Backup::get_instance();
     if (!empty($assoc_args['path'])) {
         $hm_backup->path = $assoc_args['path'];
     }
     if (!empty($assoc_args['root'])) {
         $hm_backup->root = $assoc_args['root'];
     }
     if (!is_dir($hm_backup->path()) && (!is_writable(dirname($hm_backup->path())) || !mkdir($hm_backup->path())) || !is_writable($hm_backup->path())) {
         WP_CLI::error('Invalid backup path');
         return false;
     }
     if (!is_dir($hm_backup->root()) || !is_readable($hm_backup->root())) {
         WP_CLI::error('Invalid root path');
         return false;
     }
     // Default to both
     $hm_backup->files_only = false;
     $hm_backup->database_only = false;
     if (!empty($assoc_args['files_only'])) {
         $hm_backup->files_only = true;
     }
     if (!empty($assoc_args['database_only'])) {
         $hm_backup->database_only = true;
     }
     if (!empty($assoc_args['mysqldump_command_path'])) {
         $hm_backup->mysqldump_command_path = empty($assoc_args['mysqldump_command_path']) || $assoc_args['mysqldump_command_path'] === 'false' ? false : true;
     }
     if (!empty($assoc_args['zip_command_path'])) {
         $hm_backup->zip_command_path = empty($assoc_args['zip_command_path']) || $assoc_args['zip_command_path'] === 'false' ? false : true;
     }
     if (!empty($assoc_args['excludes'])) {
         $hm_backup->excludes = $valid_rules = array_filter(array_map('trim', explode(',', $assoc_args['excludes'])));
     }
     $hm_backup->backup();
     WP_CLI::line('Backup: Deleting old backups...');
     // Delete any old backup files
     hmbkp_delete_old_backups();
     if (file_exists(HM_Backup::get_instance()->archive_filepath())) {
         WP_CLI::success('Backup Complete: ' . HM_Backup::get_instance()->archive_filepath());
     } else {
         WP_CLI::error('Backup Failed');
     }
 }