Created
September 11, 2020 22:52
-
-
Save dmdboi/2b294d64adfaa022a993acd79c5086f5 to your computer and use it in GitHub Desktop.
A node.js script to backup a MySQL database using MySQLDump. Can be added to a node-cron timer to automate backups.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fs = require('fs'); | |
var spawn = require('child_process').spawn; | |
var wstream = fs.createWriteStream('dumpfilename.sql'); //Name of SQL dump file | |
var mysqldump = spawn('mysqldump', [ | |
'-u', | |
'DB_USER', | |
'-p DB_PASSWORD', | |
'DB_NAME' | |
]); | |
mysqldump | |
.stdout | |
.pipe(wstream) | |
.on('finish', function () { | |
console.log('Completed') | |
}) | |
.on('error', function (err) { | |
console.log(err) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment