title: I'm having trouble trying to create a backup of a MySql database, using Node.js. How can I resolve this error?
body: <p>I'm trying to perform automatic backups using Node.js and the mysqldump package. It does the backup a few times, however, sometimes it generates the error below and shuts down the application.</p>
  <p><strong>The error:</strong></p>
  <blockquote>
  <p>Error: ENOENT no such file or directory, open '/root/backups/backup_781926531667722261_1611607259273.sql.gz.temp'</p>
  </blockquote>
  <p><strong>My code:</strong></p>
  <pre><code>const mysqldump = require('mysqldump')
  const path = require('path')
  const fs = require('fs')
  
  const Guild = require('../../mongodb/Schemas/Guild.js')
  
  const moment = require('moment')
  moment.locale('pt-BR')
  
  module.exports = async (client) =&gt; {    
      global.backupInterval = setInterval(async () =&gt; {
          const guilds = await Guild.find({ &quot;backupStatus&quot;: true })
  
          guilds.forEach(async guild =&gt; {    
              console.log(path.join(process.cwd(), 'backups', 'a'))        
              const channel = client.channels.cache.get(guild.backupChannel)
              if (!channel) return
              const timestamp = Date.now()
              const dumpfile = `backup_${channel.guild.id}_${timestamp}.sql.gz`
              mysqldump({
                  connection: {
                      host: guild.mysqlcon.ip,
                      user: guild.mysqlcon.user,
                      password: guild.mysqlcon.senha,
                      database: guild.mysqlcon.db,
                  },
                  dumpToFile: path.join(process.cwd(), 'backups', dumpfile),
                  compressFile: true
              }).then(async () =&gt; {                
                  await channel.send(`${moment(new Date()).format('LLLL')}`, { files: [path.join(process.cwd(), 'backups', dumpfile)] })
                  fs.unlinkSync(`./backups/${dumpfile}`)
              }, () =&gt; {}).catch(err =&gt; {
                  console.log(err)
                  channel.send('Backup não realizado no servidor pois a conexão não pôde ser estabelecida.')
              })
          })
      }, global.backupTime * 60000)
  }
  </code></pre>