Fix Restore databases from Backup & Migrate module with Autoslave module Drupal

In file: /sites/all/modules/third-party/backup_migrate/includes/sources.db.mysql.inc

/**
* Backup the databases to a file.
*/
function _restore_db_from_file($file, $settings) {
$num = 0;

#++
include_once("/var/www/html/drupal/includes/database/autoslave/database.inc");

#--
// if ($file->open() && $conn = $this->_get_db_connection()) {
#++
if ($file->open() && $conn = $this->_get_db_connection()->getMasterConnection()) {

// Read one line at a time and run the query.
while ($line = $this->_read_sql_command_from_file($file)) {
if (_backup_migrate_check_timeout()) {
return FALSE;
}

if ($line) {
// Prepeare and exexute the statement instead of the api function to avoid substitution of '{' etc.
$stmt = $conn->prepare($line);
$stmt->execute();
$num++;
}
}
// Close the file with fclose/gzclose.
$file->close();
}
else {
drupal_set_message(t("Unable to open file %file to restore database", array("%file" => $file->filepath())), 'error');
$num = FALSE;
}
return $num;
}
Advertisements

Onclick copy to clipboard javascript

<input type="text" id="copyTarget" value="Text to Copy"> <button id="copyButton">Copy</button><br><br>
<input type="text" placeholder="Click here and press Ctrl-V to see clipboard contents">

document.getElementById("copyButton").addEventListener("click", function() {
copyToClipboard(document.getElementById("copyTarget"));
});

function copyToClipboard(elem) {
// create hidden text element, if it doesn't already exist
var targetId = "_hiddenCopyText_";
var isInput = elem.tagName === "INPUT" || elem.tagName === "TEXTAREA";
var origSelectionStart, origSelectionEnd;
if (isInput) {
// can just use the original source element for the selection and copy
target = elem;
origSelectionStart = elem.selectionStart;
origSelectionEnd = elem.selectionEnd;
} else {
// must use a temporary form element for the selection and copy
target = document.getElementById(targetId);
if (!target) {
var target = document.createElement("textarea");
target.style.position = "absolute";
target.style.left = "-9999px";
target.style.top = "0";
target.id = targetId;
document.body.appendChild(target);
}
target.textContent = elem.textContent;
}
// select the content
var currentFocus = document.activeElement;
target.focus();
target.setSelectionRange(0, target.value.length);

// copy the selection
var succeed;
try {
succeed = document.execCommand("copy");
} catch(e) {
succeed = false;
}
// restore original focus
if (currentFocus && typeof currentFocus.focus === "function") {
currentFocus.focus();
}

if (isInput) {
// restore prior selection
elem.setSelectionRange(origSelectionStart, origSelectionEnd);
} else {
// clear temporary content
target.textContent = "";
}
return succeed;
}

MySQL database setup & user creation commands

Login as root user with below command.
mysql -u root -p

Create database with below command.
CREATE DATABASE db_name;

Check database using command.
show databases;

Create user using command.
CREATE USER ‘username’@’%’ IDENTIFIED BY ‘password’;

Grant privileges to the created user.
GRANT ALL PRIVILEGES ON db_name.* TO ‘username’@’%’ WITH GRANT OPTION;
than
FLUSH PRIVILEGES;

Check grants using command.
SHOW GRANTS FOR ‘username’@’%’;

————————————–

Logging in a specific db port
mysql -h hostname -P port -u username -p db_name

show table information, like engine, version, row_format_rows etc.
SHOW TABLE STATUS WHERE Name = ‘tbl_name’

change table storage engine
ALTER TABLE tbl_name ENGINE=NDBCLUSTER;

Show current DB Port:
SHOW VARIABLES WHERE Variable_name = ‘port’;
or
netstat -nat |grep :3306
(Instead 3306 you can mention your port number that you are finding)

Show current mysql user:
SELECT USER();