Skip to content

Commit

Permalink
Add database client versioning logging
Browse files Browse the repository at this point in the history
  • Loading branch information
lukeliasi committed Aug 21, 2024
1 parent b717563 commit a0586e2
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,22 +70,34 @@ async function processBackup() {
console.log(`\n[${databaseIteration}/${totalDatabases}] ${dbType}/${dbName} Backup in progress...`);

let dumpCommand;
let versionCommand = 'echo "Unknown database type"';
switch (dbType) {
case 'postgresql':
dumpCommand = `pg_dump "${databaseURI}" -F c > "${filepath}.dump"`;
versionCommand = 'psql --version';
break;
case 'mongodb':
dumpCommand = `mongodump --uri="${databaseURI}" --archive="${filepath}.dump"`;
versionCommand = 'mongodump --version';
break;
case 'mysql':
dumpCommand = `mysqldump -u ${dbUser} -p${dbPassword} -h ${dbHostname} -P ${dbPort} ${dbName} > "${filepath}.dump"`;
versionCommand = 'mysql --version';
break;
default:
console.log(`Unknown database type: ${dbType}`);
return;
}

try {
// Log database client version
try {
const { stdout: versionOutput } = await exec(versionCommand);
console.log(`Using ${dbType} client version:`, versionOutput.trim());
} catch (versionError) {
console.warn(`Failed to get ${dbType} client version:`, versionError.message);
}

// 1. Execute the dump command
await exec(dumpCommand);

Expand Down Expand Up @@ -126,4 +138,4 @@ if (config.cron) {
if (config.run_on_startup) {
console.log("run_on_startup enabled, backing up now...")
processBackup();
}
}

0 comments on commit a0586e2

Please sign in to comment.