/** * @param BackupMigrateInterface $bam * The Backup and Migrate service object used to execute the backups * * @param bool $force * Run the schedule even if it is not due to be run. */ public function run(BackupMigrateInterface $bam, $force = FALSE) { $next_run_at = $this->getNextRun(); $should_run_now = REQUEST_TIME >= $next_run_at; $enabled = $this->get('enabled'); if ($force || $should_run_now && $enabled) { // Set the last run time before attempting backup. // This will prevent a failing schedule from retrying on every cron run. $this->setLastRun(REQUEST_TIME); try { $config = []; if ($settings_profile_id = $this->get('settings_profile_id')) { // Load the settings profile if one is selected. $profile = SettingsProfile::load($settings_profile_id); if (!$profile) { throw new BackupMigrateException("The settings profile '%profile' does not exist", ['%profile' => $settings_profile_id]); } $config = $profile->get('config'); } \Drupal::logger('backup_migrate')->info("Running schedule %name", ['%name' => $this->get('label')]); // TODO: Set the config (don't just use the defaults). // Run the backup. $bam->setConfig(new Config($config)); $bam->backup($this->get('source_id'), $this->get('destination_id'), $config); drupal_set_message('Backup Complete.'); } catch (BackupMigrateException $e) { \Drupal::logger('backup_migrate')->error("Scheduled backup '%name' failed: @err", ['%name' => $this->get('label'), '@err' => $e->getMessage()]); } } }
/** * {@inheritdoc} */ public function alterBackupMigrate(BackupMigrateInterface $bam, $key, $options = []) { if ($source = $this->getObject()) { $bam->sources()->add($key, $source); $config = ['exclude_tables' => [], 'nodata_tables' => []]; // @TODO: Allow modules to add their own excluded tables. $bam->plugins()->add('db_exclude', new DBExcludeFilter(new Config($config))); } }
/** * {@inheritdoc} */ public function alterBackupMigrate(BackupMigrateInterface $bam, $key, $options = []) { $source = $this->getObject(); $bam->sources()->add($key, $source); $config = ['exclude_filepaths' => [], 'source' => $source]; switch ($this->getConfig()->get('directory')) { case 'public://': $config['exclude_filepaths'] = ['js', 'css', 'php', 'styles', 'config_*', '.htaccess']; break; case 'private://': $config['exclude_filepaths'] = ['backup_migrate']; break; } // @TODO: Allow modules to add their own excluded defaults. $bam->plugins()->add($key . '_exclude', new FileExcludeFilter(new Config($config))); }
/** * @param BackupMigrateInterface $bam * The Backup and Migrate service object used to execute the backups * * @param bool $force * Run the schedule even if it is not due to be run. */ public function run(BackupMigrateInterface $bam, $force = FALSE) { $next_run_at = $this->getNextRun(); $should_run_now = REQUEST_TIME >= $next_run_at; if ($force || $should_run_now) { // Set the last run time before attempting backup. // This will prevent a failing schedule from retrying on every cron run. $this->setLastRun(REQUEST_TIME); try { \Drupal::logger('backup_migrate')->info("Running schedule %name", ['%name' => $this->get('label')]); // TODO: Set the config (don't just use the defaults). // Run the backup. $bam->backup($this->get('source_id'), $this->get('destination_id')); drupal_set_message('Backup Complete.'); } catch (BackupMigrateException $e) { \Drupal::logger('backup_migrate')->error("Error during scheduled backup (%name): %err", ['%name' => $this->get('label'), '%err' => $e->getMessage()]); } } }
/** * Get a select form item for the given list of sources * * @param \BackupMigrate\Core\Main\BackupMigrateInterface $bam * @param $title * @return array */ public static function getDestinationSelector(BackupMigrateInterface $bam, $title) { return DrupalConfigHelper::getPluginSelector($bam->destinations(), $title); }
/** * {@inheritdoc} */ public function alterBackupMigrate(BackupMigrateInterface $bam, $key, $options = []) { $bam->sources()->add($key, $this->getObject()); }