mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-18 02:06:01 +00:00
SYNC: Merge branch 'feature/backup-restore'
This commit is contained in:
@@ -36,7 +36,6 @@
|
||||
"webpack-cli": "^5.1.4"
|
||||
},
|
||||
"dependencies": {
|
||||
"antares-mysql-dumper": "^0.0.1",
|
||||
"dbgate-query-splitter": "^4.11.3",
|
||||
"dbgate-tools": "^6.0.0-alpha.1",
|
||||
"lodash": "^4.17.21",
|
||||
|
||||
@@ -5,7 +5,6 @@ const Analyser = require('./Analyser');
|
||||
const mysql2 = require('mysql2');
|
||||
const { getLogger, createBulkInsertStreamBase, makeUniqueColumnNames, extractErrorLogData } =
|
||||
global.DBGATE_PACKAGES['dbgate-tools'];
|
||||
const { MySqlDumper } = require('antares-mysql-dumper');
|
||||
|
||||
const logger = getLogger('mysqlDriver');
|
||||
|
||||
@@ -203,15 +202,6 @@ const drivers = driverBases.map(driverBase => ({
|
||||
// @ts-ignore
|
||||
return createBulkInsertStreamBase(this, stream, dbhan, name, options);
|
||||
},
|
||||
async createBackupDumper(dbhan, options) {
|
||||
const { outputFile, databaseName, schemaName } = options;
|
||||
const res = new MySqlDumper({
|
||||
connection: dbhan.client,
|
||||
schema: databaseName || schemaName,
|
||||
outputFile,
|
||||
});
|
||||
return res;
|
||||
},
|
||||
getAuthTypes() {
|
||||
const res = [
|
||||
{
|
||||
|
||||
@@ -178,7 +178,8 @@ const mysqlDriverBase = {
|
||||
: mysqlSplitterOptions,
|
||||
|
||||
readOnlySessions: true,
|
||||
supportsDatabaseDump: true,
|
||||
supportsDatabaseBackup: true,
|
||||
supportsDatabaseRestore: true,
|
||||
authTypeLabel: 'Connection mode',
|
||||
defaultAuthTypeName: 'hostPort',
|
||||
defaultSocketPath: '/var/run/mysqld/mysqld.sock',
|
||||
@@ -199,6 +200,122 @@ const mysqlDriverBase = {
|
||||
},
|
||||
];
|
||||
},
|
||||
getCliConnectionArgs(connection, externalTools) {
|
||||
const args = [`--user=${connection.user}`, `--password=${connection.password}`, `--host=${connection.server}`];
|
||||
if (connection.port) {
|
||||
args.push(`--port=${connection.port}`);
|
||||
}
|
||||
if (externalTools.mysqlPlugins) {
|
||||
args.push(`--plugin-dir=${externalTools.mysqlPlugins}`);
|
||||
}
|
||||
if (connection.server == 'localhost') {
|
||||
args.push(`--protocol=tcp`);
|
||||
}
|
||||
return args;
|
||||
},
|
||||
backupDatabaseCommand(connection, settings, externalTools) {
|
||||
const { outputFile, database, skippedTables, options } = settings;
|
||||
const command = externalTools.mysqldump || 'mysqldump';
|
||||
const args = this.getCliConnectionArgs(connection, externalTools);
|
||||
args.push(`--result-file=${outputFile}`);
|
||||
args.push('--verbose');
|
||||
for (const table of skippedTables) {
|
||||
args.push(`--ignore-table=${database}.${table.pureName}`);
|
||||
}
|
||||
if (options.noData) {
|
||||
args.push('--no-data');
|
||||
}
|
||||
if (options.noStructure) {
|
||||
args.push('--no-create-info');
|
||||
}
|
||||
if (options.includeEvents !== false && !options.noStructure) {
|
||||
args.push('--events');
|
||||
}
|
||||
if (options.includeRoutines !== false && !options.noStructure) {
|
||||
args.push('--routines');
|
||||
}
|
||||
if (options.includeTriggers !== false && !options.noStructure) {
|
||||
args.push('--triggers');
|
||||
}
|
||||
if (options.force) {
|
||||
args.push('--force');
|
||||
}
|
||||
args.push(database);
|
||||
return { command, args };
|
||||
},
|
||||
restoreDatabaseCommand(connection, settings, externalTools) {
|
||||
const { inputFile, database } = settings;
|
||||
const command = externalTools.mysql || 'mysql';
|
||||
const args = this.getCliConnectionArgs(connection, externalTools);
|
||||
if (database) {
|
||||
args.push(database);
|
||||
}
|
||||
return { command, args, stdinFilePath: inputFile };
|
||||
},
|
||||
transformNativeCommandMessage(message) {
|
||||
if (message.message?.startsWith('--')) {
|
||||
if (message.message.startsWith('-- Retrieving table structure for table')) {
|
||||
return {
|
||||
...message,
|
||||
severity: 'info',
|
||||
message: message.message.replace('-- Retrieving table structure for table', 'Processing table'),
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
...message,
|
||||
severity: 'debug',
|
||||
message: message.message.replace('-- ', ''),
|
||||
};
|
||||
}
|
||||
}
|
||||
return message;
|
||||
},
|
||||
getNativeOperationFormArgs(operation) {
|
||||
if (operation == 'backup') {
|
||||
return [
|
||||
{
|
||||
type: 'checkbox',
|
||||
label: 'No data (dump only structure)',
|
||||
name: 'noData',
|
||||
default: false,
|
||||
},
|
||||
{
|
||||
type: 'checkbox',
|
||||
label: 'No structure (dump only data)',
|
||||
name: 'noStructure',
|
||||
default: false,
|
||||
},
|
||||
{
|
||||
type: 'checkbox',
|
||||
label: 'Force (ignore all errors)',
|
||||
name: 'force',
|
||||
default: false,
|
||||
},
|
||||
{
|
||||
type: 'checkbox',
|
||||
label: 'Backup events',
|
||||
name: 'includeEvents',
|
||||
default: true,
|
||||
disabledFn: values => values.noStructure,
|
||||
},
|
||||
{
|
||||
type: 'checkbox',
|
||||
label: 'Backup routines',
|
||||
name: 'includeRoutines',
|
||||
default: true,
|
||||
disabledFn: values => values.noStructure,
|
||||
},
|
||||
{
|
||||
type: 'checkbox',
|
||||
label: 'Backup triggers',
|
||||
name: 'includeTriggers',
|
||||
default: true,
|
||||
disabledFn: values => values.noStructure,
|
||||
},
|
||||
];
|
||||
}
|
||||
return null;
|
||||
},
|
||||
};
|
||||
|
||||
/** @type {import('dbgate-types').EngineDriver} */
|
||||
|
||||
Reference in New Issue
Block a user