class backup_migrate_destination_db in Backup and Migrate 6.2
Same name and namespace in other branches
- 8.2 includes/destinations.db.inc \backup_migrate_destination_db
- 8.3 includes/destinations.db.inc \backup_migrate_destination_db
- 7.3 includes/destinations.db.inc \backup_migrate_destination_db
- 7.2 includes/destinations.db.inc \backup_migrate_destination_db
A destination type for saving to a database server.
Hierarchy
- class \backup_migrate_item
Expanded class hierarchy of backup_migrate_destination_db
1 string reference to 'backup_migrate_destination_db'
- backup_migrate_backup_migrate_destination_types in includes/
destinations.inc - Implementation of hook_backup_migrate_destination_types().
File
- includes/
destinations.db.inc, line 17 - Functions to handle the direct to database destination.
View source
class backup_migrate_destination_db extends backup_migrate_destination_remote {
var $supported_ops = array(
'scheduled backup',
'manual backup',
'configure',
'source',
);
function type_name() {
return t("Database");
}
/**
* Save the info by importing it into the database.
*/
function save_file($file, $settings) {
backup_migrate_include('files');
// Set the source_id to the destination_id in the settings since for a restore, the source_id is the
// database that gets restored to.
$settings
->set_source($this
->get_id());
// Restore the file to the source database.
$file = backup_migrate_perform_restore($this
->get_id(), $file, $settings);
return $file;
}
/**
* Destination configuration callback.
*/
function edit_form() {
$form = parent::edit_form();
$form['scheme']['#title'] = t('Database type');
$form['scheme']['#options'] = array(
$GLOBALS['db_type'] => $GLOBALS['db_type'],
);
$form['scheme']['#description'] = t('The type of the database. Drupal only supports one database type at a time, so this must be the same as the current database type.');
$form['path']['#title'] = t('Database name');
$form['path']['#description'] = t('The name of the database. The database must exist, it will not be created for you.');
$form['user']['#description'] = t('Enter the name of a user who has write access to the database.');
return $form;
}
/**
* Validate the configuration form. Make sure the db info is valid.
*/
function edit_form_validate($form, &$form_state) {
if (!preg_match('/[a-zA-Z0-9_\\$]+/', $form_state['values']['path'])) {
form_set_error('path', t('The database name is not valid.'));
}
parent::edit_form_validate($form, $form_state);
}
/**
* Get the form for the settings for this destination.
*
* Return the default tables whose data can be ignored. These tables mostly contain
* info which can be easily reproducted (such as cache or search index)
* but also tables which can become quite bloated but are not necessarily extremely
* important to back up or migrate during development (such ass access log and watchdog)
*/
function backup_settings_default() {
$core = array(
'cache',
'cache_filter',
'cache_calendar_ical',
'cache_menu',
'cache_page',
'cache_views',
'cache_block',
'cache_update',
'cache_form',
'sessions',
'search_dataset',
'search_index',
'search_keywords_log',
'search_total',
'watchdog',
'accesslog',
'devel_queries',
'devel_times',
);
$nodata_tables = array_merge(array_combine($core, $core), module_invoke_all('devel_caches'));
return array(
'nodata_tables' => $nodata_tables,
'exclude_tables' => array(),
'utils_lock_tables' => FALSE,
);
}
/**
* Get the form for the backup settings for this destination.
*/
function backup_settings_form($settings) {
$objects = $this
->get_object_names();
$form['#description'] = t("You may omit specific tables, or specific table data from the backup file. Only omit data that you know you will not need such as cache data, or tables from other applications. Excluding tables can break your Drupal install, so <strong>do not change these settings unless you know what you're doing</strong>.");
$form['exclude_tables'] = array(
"#type" => "select",
"#multiple" => TRUE,
"#title" => t("Exclude the following tables altogether"),
"#options" => $objects,
"#default_value" => array_filter($settings['exclude_tables']),
'#element_validate' => array(
'_backup_migrate_destination_complete_table_list',
),
"#description" => t("The selected tables will not be added to the backup file."),
);
$tables = $this
->get_table_names();
$form['nodata_tables'] = array(
"#type" => "select",
"#multiple" => TRUE,
"#title" => t("Exclude the data from the following tables"),
"#options" => $tables,
"#default_value" => array_filter($settings['nodata_tables']),
'#element_validate' => array(
'_backup_migrate_destination_complete_table_list',
),
"#description" => t("The selected tables will have their structure backed up but not their contents. This is useful for excluding cache data to reduce file size."),
);
$form['utils_lock_tables'] = array(
'#type' => 'checkbox',
'#title' => t('Lock tables during backup'),
'#default_value' => !empty($settings['utils_lock_tables']) ? $settings['utils_lock_tables'] : NULL,
'#description' => t('This can help reduce data corruption, but will make your site unresponsive.'),
);
return $form;
}
/**
* Backup from this source.
*/
function backup_to_file($file, $settings) {
$file
->push_type($this
->get_file_type_id());
backup_migrate_filters_invoke_all('pre_backup', $this, $file, $settings);
// Switch to a different db if specified.
$this
->switch_db();
$this
->lock_tables($settings);
$success = $this
->_backup_db_to_file($file, $settings);
$this
->unlock_tables($settings);
// Switch back to the previous db.
$this
->switch_db(TRUE);
backup_migrate_filters_invoke_all('post_backup', $this, $file, $settings, $success);
return $success ? $file : FALSE;
}
/**
* Restore to this source.
*/
function restore_from_file($file, &$settings) {
$num = 0;
$type = $this
->get_file_type_id();
// Open the file using the file wrapper. Check that the dump is of the right type (allow .sql for legacy reasons).
if ($file
->type_id() !== $this
->get_file_type_id() && $file
->type_id() !== 'sql') {
_backup_migrate_message("Unable to restore from file %file because a %type file can't be restored to this database.", array(
"%file" => $file
->filepath(),
'%type' => $file
->type_id(),
), 'error');
}
else {
backup_migrate_filters_invoke_all('pre_restore', $file, $settings);
// Switch to a different db if specified.
$this
->switch_db();
// Restore the database.
$num = $this
->_restore_db_from_file($file, $settings);
$settings->performed_action = $num ? t('%num SQL commands executed.', array(
'%num' => $num,
)) : '';
// Switch back to the previous db.
$this
->switch_db(TRUE);
backup_migrate_filters_invoke_all('post_restore', $file, $settings, $num);
}
return $num;
}
/**
* Backup the databases to a file.
*/
function _backup_db_to_file($file, $settings) {
// Must be overridden.
}
/**
* Backup the databases to a file.
*/
function _restore_db_from_file($file, $settings) {
// Must be overridden.
}
/**
* Get a list of objects in the database.
*/
function get_object_names() {
// Switch to a different db if specified.
$this
->switch_db();
// Must be overridden.
$out = $this
->_get_table_names();
if (method_exists($this, '_get_view_names')) {
$out += $this
->_get_view_names();
}
$this
->switch_db(TRUE);
return $out;
}
/**
* Get a list of tables in the database.
*/
function get_table_names() {
// Switch to a different db if specified.
$this
->switch_db();
// Must be overridden.
$out = $this
->_get_table_names();
$this
->switch_db(TRUE);
return $out;
}
/**
* Get a list of tables in the database.
*/
function _get_table_names() {
// Must be overridden.
return array();
}
/**
* Switch to the current database. Pass true to switch back to the previous db.
*/
function switch_db($switch_back = FALSE) {
static $db_stack = array();
global $db_url;
// If switch back is specified, pop the previous db and activate it.
if ($switch_back && $db_stack) {
db_set_active(array_pop($db_stack));
return;
}
// If there is a valid DB URL, switch to it.
if ($url = $this
->get_location()) {
// Make the db_url into an array if needed.
if (!is_array($db_url)) {
$db_url = array(
'default' => $db_url,
);
}
// Add the new db to the db_url array.
$db_url[$url] = $url;
// Switch to the new db and push the old one on the stack
$db_stack[] = db_set_active($url);
}
}
/**
* Lock the database in anticipation of a backup.
*/
function lock_tables($settings) {
if ($settings->filters['utils_lock_tables']) {
$tables = array();
foreach ($this
->get_table_names() as $table) {
// There's no need to lock excluded or structure only tables because it doesn't matter if they change.
if (empty($settings->filters['exclude_tables']) || !in_array($table, (array) $settings->filters['exclude_tables'])) {
$tables[] = $table;
}
}
$this
->_lock_tables($tables);
}
}
/**
* Lock the list of given tables in the database.
*/
function _lock_tables($tables) {
// Must be overridden.
}
/**
* Unlock any tables that have been locked.
*/
function unlock_tables($settings) {
if ($settings->filters['utils_lock_tables']) {
$this
->_unlock_tables();
}
}
/**
* Unlock the list of given tables in the database.
*/
function _unlock_tables($tables) {
// Must be overridden.
}
/**
* Get the file type for to backup this destination to.
*/
function get_file_type_id() {
return 'sql';
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
backup_migrate_destination:: |
property | |||
backup_migrate_destination:: |
property | 2 | ||
backup_migrate_destination:: |
property |
Overrides backup_migrate_item:: |
||
backup_migrate_destination:: |
property |
Overrides backup_migrate_item:: |
||
backup_migrate_destination:: |
property | |||
backup_migrate_destination:: |
property | |||
backup_migrate_destination:: |
property |
Overrides backup_migrate_item:: |
||
backup_migrate_destination:: |
property |
Overrides backup_migrate_item:: |
||
backup_migrate_destination:: |
property |
Overrides backup_migrate_item:: |
||
backup_migrate_destination:: |
function | Submit the settings form. Any values returned will be saved. | ||
backup_migrate_destination:: |
function | Get the form for the settings for this filter. | ||
backup_migrate_destination:: |
function | Determine if we can read the given file. | ||
backup_migrate_destination:: |
function | Determine if we can read the given file. | 1 | |
backup_migrate_destination:: |
function |
Create a new destination of the correct type. Overrides backup_migrate_item:: |
||
backup_migrate_destination:: |
function |
Get the message to send to the user when confirming the deletion of the item. Overrides backup_migrate_item:: |
||
backup_migrate_destination:: |
function | Delete the file with the given destination specific id. | 2 | |
backup_migrate_destination:: |
function | Retrieve the file list. | ||
backup_migrate_destination:: |
function | Retrieve the file list. | ||
backup_migrate_destination:: |
function | Cache the file list. | ||
backup_migrate_destination:: |
function | Check if a file exists in the given destination. | ||
backup_migrate_destination:: |
function | 1 | ||
backup_migrate_destination:: |
function |
Get the action links for a destination. Overrides backup_migrate_item:: |
||
backup_migrate_destination:: |
function | Get the type name of this destination for display to the user. | ||
backup_migrate_destination:: |
function | Get the action links for a file on a given destination. | ||
backup_migrate_destination:: |
function |
Get the columns needed to list the type. Overrides backup_migrate_item:: |
||
backup_migrate_destination:: |
function |
Get a row of data to be used in a list of items of this type. Overrides backup_migrate_item:: |
1 | |
backup_migrate_destination:: |
function |
Add the menu items specific to the destination type. Overrides backup_migrate_item:: |
||
backup_migrate_destination:: |
function |
Get the name of the item. Overrides backup_migrate_item:: |
1 | |
backup_migrate_destination:: |
function | List all the available files in the given destination with their destination specific id. | 1 | |
backup_migrate_destination:: |
function | Load the file with the given destination specific id and return as a backup_file object. | 5 | |
backup_migrate_destination:: |
function | Does this destination support the given operation. | ||
backup_migrate_destination:: |
function | |||
backup_migrate_destination:: |
function | Remove the given op from the support list. | ||
backup_migrate_destination:: |
function | Get the form for the settings for this filter. | ||
backup_migrate_destination:: |
function | Get the form for the settings for this filter. | ||
backup_migrate_destination:: |
function | Submit the settings form. Any values returned will be saved. | ||
backup_migrate_destination:: |
function | Get the form for the settings for this filter. | ||
backup_migrate_destination:: |
function | |||
backup_migrate_destination:: |
function | Get the form for the settings for this destination type. | ||
backup_migrate_destination:: |
function | Get the form for the settings for this destination. | ||
backup_migrate_destination:: |
function | Submit the settings form. Any values returned will be saved. | ||
backup_migrate_destination:: |
function | Validate the form for the settings for this destination. | 1 | |
backup_migrate_destination:: |
function | |||
backup_migrate_destination:: |
function | |||
backup_migrate_destination:: |
function |
This function is not supposed to be called. It is just here to help the po extractor out. Overrides backup_migrate_item:: |
||
backup_migrate_destination:: |
function | Delete the file with the given destination specific id. | 2 | |
backup_migrate_destination:: |
function | List all the available files in the given destination with their destination specific id. | 3 | |
backup_migrate_destination:: |
function | Save the given file to the destination. | 2 | |
backup_migrate_destination_db:: |
property |
Overrides backup_migrate_destination:: |
||
backup_migrate_destination_db:: |
function |
Get the form for the settings for this destination. Overrides backup_migrate_destination:: |
||
backup_migrate_destination_db:: |
function |
Get the form for the backup settings for this destination. Overrides backup_migrate_destination:: |
||
backup_migrate_destination_db:: |
function | Backup from this source. | ||
backup_migrate_destination_db:: |
function |
Destination configuration callback. Overrides backup_migrate_destination_remote:: |
||
backup_migrate_destination_db:: |
function |
Validate the configuration form. Make sure the db info is valid. Overrides backup_migrate_item:: |
||
backup_migrate_destination_db:: |
function | Get the file type for to backup this destination to. | 1 | |
backup_migrate_destination_db:: |
function | Get a list of objects in the database. | ||
backup_migrate_destination_db:: |
function | Get a list of tables in the database. | ||
backup_migrate_destination_db:: |
function | Lock the database in anticipation of a backup. | ||
backup_migrate_destination_db:: |
function | Restore to this source. | ||
backup_migrate_destination_db:: |
function |
Save the info by importing it into the database. Overrides backup_migrate_destination:: |
||
backup_migrate_destination_db:: |
function | Switch to the current database. Pass true to switch back to the previous db. | ||
backup_migrate_destination_db:: |
function | 1 | ||
backup_migrate_destination_db:: |
function | Unlock any tables that have been locked. | ||
backup_migrate_destination_db:: |
function | Backup the databases to a file. | 1 | |
backup_migrate_destination_db:: |
function | Get a list of tables in the database. | 1 | |
backup_migrate_destination_db:: |
function | Lock the list of given tables in the database. | 1 | |
backup_migrate_destination_db:: |
function | Backup the databases to a file. | 1 | |
backup_migrate_destination_db:: |
function | Unlock the list of given tables in the database. | 1 | |
backup_migrate_destination_remote:: |
function |
Submit the configuration form. Glue the url together and add the old password back if a new one was not specified. Overrides backup_migrate_item:: |
1 | |
backup_migrate_destination_remote:: |
function |
The location to display is the url without the password. Overrides backup_migrate_destination:: |
||
backup_migrate_destination_remote:: |
function |
The location is a URI so parse it and store the parts. Overrides backup_migrate_destination:: |
||
backup_migrate_destination_remote:: |
function | Glue a URLs component parts back into a URL. | ||
backup_migrate_destination_remote:: |
function |
Return the location with the password. Overrides backup_migrate_destination:: |
||
backup_migrate_destination_remote:: |
function | Break a URL into it's component parts. | ||
backup_migrate_destination_remote:: |
function | Get a url from the parts. | ||
backup_migrate_item:: |
property | |||
backup_migrate_item:: |
function | Get all of the given items. | ||
backup_migrate_item:: |
function | Decode a loaded db row (unserialize necessary fields). | ||
backup_migrate_item:: |
function | Delete the item from the database. | ||
backup_migrate_item:: |
function | Return as an exported array of values. | ||
backup_migrate_item:: |
function | Load an existing item from an array. | ||
backup_migrate_item:: |
function | Return a random (very very likely unique) string id for a new item. | ||
backup_migrate_item:: |
function | Get the member with the given key. | ||
backup_migrate_item:: |
function | Get the rendered action links for a destination. | ||
backup_migrate_item:: |
function | Get the default values for standard parameters. | 2 | |
backup_migrate_item:: |
function | Get the primary id for this item (if any is set). | ||
backup_migrate_item:: |
function | Get a table of all items of this type. | 1 | |
backup_migrate_item:: |
function | Get header for a lost of this type. | ||
backup_migrate_item:: |
function | Get the primary key field title from the schema. | ||
backup_migrate_item:: |
function | Get the schema for the item type. | ||
backup_migrate_item:: |
function | Return the fields which must be serialized before saving to the db. | ||
backup_migrate_item:: |
function | A particular item. | ||
backup_migrate_item:: |
function | Load an existing item from an database (serialized) array. | ||
backup_migrate_item:: |
function | Save the item to the database. | ||
backup_migrate_item:: |
function | Set the primary id for this item (if any is set). | ||
backup_migrate_item:: |
function | Return as an array of values. | ||
backup_migrate_item:: |
function | Merge parameters with the given defaults. | ||
backup_migrate_item:: |
function | Constructor, set the basic info pulled from the db or generated programatically. | 4 |