Guys i try download backups of my database... any help to make this?
This code create .sql file but nothing inside file, and not send in discord.
async function handleButtonInteraction(interaction) {
const collectorFilter = i => i.user.id === interaction.user.id;
try {
const confirmation = await interaction.channel.awaitMessageComponent({ filter: collectorFilter, time: 10000 });
if (confirmation.customId === 'confirm_bkp') {
try {
const backupFileName = `backup-${Date.now()}.sql`;
const dumpCommand = `mysqldump -h ${process.env.DB_HOST || 'localhost'} -u ${process.env.DB_USER || 'root'} -p${process.env.DB_PASSWORD || ''} ${process.env.DB_NAME || 'botv2'}`;
exec(dumpCommand, async (error, stdout, stderr) => {
if (error || stderr) {
console.error('Erro create db backup:', error || stderr);
if (!interaction.replied && !interaction.deferred) {
return interaction.reply({ content: 'Erro create db backup.', ephemeral: true });
}
return;
}
const backupBuffer = Buffer.from(stdout, 'utf-8');
const attachment = new AttachmentBuilder(backupBuffer, backupFileName);
if (!interaction.replied && !interaction.deferred) {
interaction.reply({ content: ':white_check_mark: Here your backup:', files: [attachment] });
}
});
} catch (error) {
await confirmation.update({ content: ':x: Erro create db backup.', components: [] });
}
} else if (confirmation.customId === 'cancel_bkp') {
await confirmation.update({ content: ':x: Canceled', components: [] });
}
} catch (e) {
await interaction.followUp({ content: ':x: Timeout! Action canceled.\n', ephemeral: true });
await sleep(2000);
await interaction.deleteReply();
}
}