/** * Cleanup the backup file and tmp directory * after every test * */ public function tearDown() { hmbkp_rmdirtree(hmbkp_path()); chmod($this->backup->get_root() . '/test-data.txt', 0664); unset($this->backup); HM\BackUpWordPress\Path::get_instance()->reset_path(); }
public function testBackUpDirIsExcludedWhenBackUpDirIsInRoot() { HM\BackUpWordPress\Path::get_instance()->set_path(dirname(__FILE__) . '/test-data/tmp'); $this->assertContains($this->backup->get_root(), hmbkp_path()); $this->assertNotEmpty($this->backup->get_excludes()); $this->assertContains(trailingslashit(hmbkp_path()), $this->backup->get_excludes()); }
/** * Make sure setting a custom path + database dump filename correctly sets the database dump filepath * */ public function testCustomDatabaseDumpPath() { HM\BackUpWordPress\Path::get_instance()->set_path(WP_CONTENT_DIR . '/custom'); $this->backup->set_database_dump_filename('dump.sql'); $this->assertEquals(wp_normalize_path(WP_CONTENT_DIR . '/custom/dump.sql'), $this->backup->get_database_dump_filepath()); $this->backup->dump_database(); $this->assertFileExists($this->backup->get_database_dump_filepath()); }
/** * Cleanup the backup file and tmp directory * after every test * */ public function tearDown() { hmbkp_rmdirtree(hmbkp_path()); unset($this->backup); if (file_exists($this->symlink)) { unlink($this->symlink); } HM\BackUpWordPress\Path::get_instance()->reset_path(); }
public function setUp() { // We need to mess with the $is_apache global so let's back it up now global $is_apache; $this->is_apache = $is_apache; $this->path = HM\BackUpWordPress\Path::get_instance(); $this->custom_path = WP_CONTENT_DIR . '/custom'; // Cleanup before we kickoff in-case theirs cruft around from previous failures $this->tearDown(); }
/** * Setup the backup object and create the tmp directory * */ public function setUp() { $this->backup = new HM\BackUpWordPress\Backup(); if (defined('HMBKP_PATH')) { $this->markTestSkipped('Skipped because of defines'); } $this->path = HM\BackUpWordPress\Path::get_instance(); // Cleanup before we kickoff in-case theirs cruft around from previous failures $this->tearDown(); }
/** * Cleanup the backup file and tmp directory * after every test * */ public function tearDown() { if (!function_exists('symlink')) { return; } hmbkp_rmdirtree(hmbkp_path()); unset($this->backup); @unlink($this->symlink); HM\BackUpWordPress\Path::get_instance()->reset_path(); }
/** * Perform a Backup. * * ## OPTIONS * * [--files_only] * : Backup files only, default to off * * [--database_only] * : Backup database only, defaults to off * * [--destination] * : dir that the backup should be save in, defaults to your existing backups directory * * [--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 * * [--archive_filename] * : filename for the resulting zip file * * [--excludes] * : list of paths you'd like to exclude * * ## Usage * * wp backupwordpress backup [--files_only] [--database_only] [--path<dir>] [--root<dir>] [--zip_command_path=<path>] [--mysqldump_command_path=<path>] * * @todo errors should be bubbled from Backup, Scheduled_Backup and the like instead of being repeated. */ public function backup($args, $assoc_args) { add_action('hmbkp_mysqldump_started', function () { WP_CLI::line(__('Backup: Dumping database...', 'backupwordpress')); }); add_action('hmbkp_archive_started', function () { WP_CLI::line(__('Backup: Zipping everything up...', 'backupwordpress')); }); $hm_backup = new HM\BackUpWordPress\Backup(); if (!empty($assoc_args['destination'])) { Path::get_instance()->set_path($assoc_args['destination']); } HM\BackUpWordPress\Path::get_instance()->cleanup(); if (!empty($assoc_args['root'])) { $hm_backup->set_root($assoc_args['root']); } if (!is_dir(hmbkp_path())) { WP_CLI::error(__('Invalid backup path', 'backupwordpress')); return false; } if (!is_dir($hm_backup->get_root()) || !is_readable($hm_backup->get_root())) { WP_CLI::error(__('Invalid root path', 'backupwordpress')); return false; } if (isset($assoc_args['archive_filename'])) { $hm_backup->set_archive_filename($assoc_args['archive_filename']); } 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(); if (file_exists($hm_backup->get_archive_filepath())) { WP_CLI::success(__('Backup Complete: ', 'backupwordpress') . $hm_backup->get_archive_filepath()); } else { WP_CLI::error(__('Backup Failed', 'backupwordpress')); } }
/** * Cleanup the backup file and tmp directory * after every test * */ public function tearDown() { hmbkp_rmdirtree(hmbkp_path()); unset($this->backup); HM\BackUpWordPress\Path::get_instance()->reset_path(); }
function run_schedule() { $schedule_id = $this->check_schedule(); HM\BackUpWordPress\Path::get_instance()->cleanup(); // Fixes an issue on servers which only allow a single session per client session_write_close(); $task = new \HM\Backdrop\Task('hmbkp_run_schedule_async', $schedule_id); $task->schedule(); $schedule = new HM\BackUpWordPress\Scheduled_Backup(sanitize_text_field(urldecode($schedule_id))); $information['scheduleStatus'] = $schedule->get_status(); $information['file_size_text'] = $this->hmbkp_get_site_size_text($schedule); $information['started_ago'] = human_time_diff($schedule->get_schedule_running_start_time()); return array('result' => 'SUCCESS'); }
/** * Dismiss an error and then redirect back to the backups page */ function hmbkp_dismiss_error() { check_admin_referer('hmbkp_dismiss_error', 'hmbkp_dismiss_error_nonce'); HM\BackUpWordPress\Path::get_instance()->cleanup(); HM\BackUpWordPress\Notices::get_instance()->clear_all_notices(); wp_safe_redirect(wp_get_referer(), 303); die; }
/** * Handles anything that needs to be * done when the plugin is updated */ function hmbkp_update() { // Update from backUpWordPress 0.4.5 if (get_option('bkpwp_max_backups')) { // Carry over the custom path if ($legacy_path = get_option('bkpwppath')) { update_option('hmbkp_path', $legacy_path); } // Options to remove $legacy_options = array('bkpwp_archive_types', 'bkpwp_automail_from', 'bkpwp_domain', 'bkpwp_domain_path', 'bkpwp_easy_mode', 'bkpwp_excludelists', 'bkpwp_install_user', 'bkpwp_listmax_backups', 'bkpwp_max_backups', 'bkpwp_presets', 'bkpwp_reccurrences', 'bkpwp_schedules', 'bkpwp_calculation', 'bkpwppath', 'bkpwp_status_config', 'bkpwp_status'); foreach ($legacy_options as $option) { delete_option($option); } global $wp_roles; $wp_roles->remove_cap('administrator', 'manage_backups'); $wp_roles->remove_cap('administrator', 'download_backups'); wp_clear_scheduled_hook('bkpwp_schedule_bkpwp_hook'); } // Version 1 to 2 if (get_option('hmbkp_plugin_version') && version_compare('2.0', get_option('hmbkp_plugin_version'), '>')) { /** * Setup a backwards compatible schedule */ $legacy_schedule = new HM\BackUpWordPress\Scheduled_Backup('backup'); // Backup type if (defined('HMBKP_FILES_ONLY') && HMBKP_FILES_ONLY || get_option('hmbkp_files_only')) { $legacy_schedule->set_type('file'); } elseif (defined('HMBKP_DATABASE_ONLY') && HMBKP_DATABASE_ONLY || get_option('hmbkp_database_only')) { $legacy_schedule->set_type('database'); } else { $legacy_schedule->set_type('complete'); } // Daily schedule time if (defined('HMBKP_DAILY_SCHEDULE_TIME') && HMBKP_DAILY_SCHEDULE_TIME) { $legacy_schedule->set_schedule_start_time(strtotime(HMBKP_DAILY_SCHEDULE_TIME)); } // Backup schedule $legacy_schedule->set_reoccurrence(get_option('hmbkp_schedule_frequency', 'daily')); // Automatic backups disabled? if (defined('HMBKP_DISABLE_AUTOMATIC_BACKUP') && HMBKP_DISABLE_AUTOMATIC_BACKUP || get_option('hmbkp_disable_automatic_backup')) { $legacy_schedule->set_reoccurrence('manually'); } // Max backups if (defined('HMBKP_MAX_BACKUPS') && is_numeric(HMBKP_MAX_BACKUPS)) { $legacy_schedule->set_max_backups((int) HMBKP_MAX_BACKUPS); } else { $legacy_schedule->set_max_backups((int) get_option('hmbkp_max_backups', 10)); } // Excludes if (get_option('hmbkp_excludes')) { $legacy_schedule->set_excludes(get_option('hmbkp_excludes')); } // Backup email if (defined('HMBKP_EMAIL') && is_email(HMBKP_EMAIL)) { $legacy_schedule->set_service_options('HMBKP_Email_Service', array('email' => HMBKP_EMAIL)); } elseif (is_email(get_option('hmbkp_email_address'))) { $legacy_schedule->set_service_options('HMBKP_Email_Service', array('email' => get_option('hmbkp_email_address'))); } // Set the archive filename to what it used to be $legacy_schedule->backup->set_archive_filename(implode('-', array(get_bloginfo('name'), 'backup', current_time('Y-m-d-H-i-s'))) . '.zip'); $legacy_schedule->save(); // Remove the legacy options foreach (array('hmbkp_database_only', 'hmbkp_files_only', 'hmbkp_max_backups', 'hmbkp_email_address', 'hmbkp_email', 'hmbkp_schedule_frequency', 'hmbkp_disable_automatic_backup') as $option_name) { delete_option($option_name); } } // Update from 2.x to 3.0 if (get_option('hmbkp_plugin_version') && version_compare('2.0', get_option('hmbkp_plugin_version'), '>')) { // Remove the plugin data cache delete_transient('hmbkp_plugin_data'); } // Update to 3.1 if (get_option('hmbkp_plugin_version') && version_compare('3.0', get_option('hmbkp_plugin_version'), '>')) { // Remove the plugin data cache delete_option('hmbkp_path'); delete_option('hmbkp_default_path'); } // update to 3.1.4 if (get_option('hmbkp_plugin_version') && version_compare('3.1.4', get_option('hmbkp_plugin_version'), '>')) { $old_option_names = array('HM\\BackUpWordPressDropbox\\Dropbox_Service' => 'dropbox', 'HMBKP_DX_Backup_Service' => 'dropbox', 'HM\\BackUpWordPressFTP\\FTP_Backup_Service' => 'ftp', 'HMBKP_FTP_Backup_Service' => 'ftp', 'HM\\BackUpWordPressGDrive\\Google_Drive_BackUp' => 'google-drive', 'HMBKP_GDV_Backup_Service' => 'google-drive', 'HM\\BackUpWordPressRackspace\\RackSpace_BackUp' => 'rackspace-cloud', 'HMBKP_RSC_Backup_Service' => 'rackspace-cloud', 'HM\\BackUpWordPressS3\\S3_Backup' => 's3', 'HMBKP_S3_Backup_Service' => 's3', 'HM\\BackUpWordPressWinAzure\\WinAzure_Backup' => 'azure', 'HMBKP_WAZ_Backup_Service' => 'azure', 'HM\\BackUpWordPress\\Email_Service' => 'email'); global $wpdb; // Get all schedule options with a SELECT query and delete them. $schedules = $wpdb->get_col($wpdb->prepare("SELECT option_name FROM {$wpdb->options} WHERE option_name LIKE %s", 'hmbkp_schedule_%')); if (0 < count($schedules)) { // Access each schedules settings to see if the addon settings names need to be be updated to the new naming convention which uses the service slug generated from the $name property. foreach ($schedules as $schedule_id) { // Load the settings for this schedule into an array // so we can loop through the different service settings $schedule_settings = get_option($schedule_id); // Iterate over each schedule setting for this schedule and check its name against our array. foreach ($schedule_settings as $key => $val) { // Find the current element key in our control array and get its value. Set a new element in the settings array with the found value as its key. Aka rename the element key if (array_key_exists($key, $old_option_names)) { // move the value to our new key $schedule_settings[$old_option_names[$key]] = $schedule_settings[$key]; unset($schedule_settings[$key]); } } // Save back to the DB update_option($schedule_id, $schedule_settings); } } } // Update to 3.1.5 if (get_option('hmbkp_plugin_version') && version_compare('3.1.5', get_option('hmbkp_plugin_version'), '>')) { // Delete all transients $transients = array('hmbkp_plugin_data', 'hmbkp_directory_filesizes', 'hmbkp_directory_filesizes_running', 'hmbkp_wp_cron_test_beacon', 'hm_backdrop'); array_map('delete_transient', $transients); // Clear duplicate schedules on multisite if (is_multisite()) { // get current blogs from DB $blogs = wp_get_sites(); foreach ($blogs as $blog) { switch_to_blog(get_current_blog_id()); if (is_main_site(get_current_blog_id())) { continue; } global $wpdb; // Get the schedule options $schedules = $wpdb->get_col($wpdb->prepare("SELECT option_name FROM {$wpdb->options} WHERE option_name LIKE %s", 'hmbkp_schedule_%')); // clear schedules foreach (array_map(function ($item) { return ltrim($item, 'hmbkp_schedule_'); }, $schedules) as $item) { wp_clear_scheduled_hook('hmbkp_schedule_hook', array('id' => $item)); } // delete options array_map('delete_option', $schedules); array_map('delete_option', array('hmbkp_enable_support', 'hmbkp_plugin_version', 'hmbkp_path', 'hmbkp_default_path', 'hmbkp_upsell')); // Delete all transients array_map('delete_transient', array('hmbkp_plugin_data', 'hmbkp_directory_filesizes', 'hmbkp_directory_filesize_running', 'timeout_hmbkp_wp_cron_test_beacon', 'hmbkp_wp_cron_test_beacon')); } restore_current_blog(); } } // Update from PRIOR_VERSION if (get_option('hmbkp_plugin_version') && version_compare('3.3.0', get_option('hmbkp_plugin_version'), '>')) { $schedules = HM\BackUpWordPress\Schedules::get_instance(); // Loop through all schedules and re-set the reccurrence to include hmbkp_ foreach ($schedules->get_schedules() as $schedule) { $reoccurrence = $schedule->get_reoccurrence(); if ($reoccurrence !== 'manually' && strpos($reoccurrence, 'hmbkp_') === 0) { $schedule->set_reoccurrence(substr($reoccurrence, 6)); } $schedule->save(); } } // Every update if (get_option('hmbkp_plugin_version') && version_compare(HM\BackUpWordPress\Plugin::PLUGIN_VERSION, get_option('hmbkp_plugin_version'), '>')) { HM\BackUpWordPress\Setup::deactivate(); HM\BackUpWordPress\Path::get_instance()->protect_path('reset'); } // Update the stored version if (get_option('hmbkp_plugin_version') !== HM\BackUpWordPress\Plugin::PLUGIN_VERSION) { update_option('hmbkp_plugin_version', HM\BackUpWordPress\Plugin::PLUGIN_VERSION); } }
/** * Cleanup the backup file and tmp directory * after every test */ public function tearDown() { hmbkp_rmdirtree(hmbkp_path()); @unlink($this->backup->get_root() . '/new.file'); HM\BackUpWordPress\Path::get_instance()->reset_path(); }