Backup database and server.
Make sure:
- You have SSH login without password.
- You have
mysql-client
installed andmysqldump
command is running on terminal. (In Linuxsudo apt-get install mysql-client
)
Install library to your project with yarn or npm.
yarn add database-and-server-backup
npm i database-and-server-backup
Import library to your JS file.
const backup = require('database-and-server-backup')
Create a config object.
const config = {
mysql: ['-u', 'yourUsername', '--password=yourPassword', '-h', 'yourIp', 'yourDatabaseName'],
server: 'yourUsername@yourIp:/your/folder',
backupFolder: '/home/user/full/path'
}
Pass config object to the backup function.
backup(config)
.then(() => {
// done
})
.catch((err) => {
console.log(err)
})
Run the script.
node file.js