mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-18 14:56:01 +00:00
SYNC: Merge branch 'feature/backup-restore'
This commit is contained in:
@@ -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