-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.js
More file actions
59 lines (54 loc) · 2.04 KB
/
init.js
File metadata and controls
59 lines (54 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
'use strict'
const MysqlTools = require('mysql-tools');
let schedule = require('node-schedule');
const tool = new MysqlTools();
const nodemailer = require('nodemailer');
// create reusable transporter object using the default SMTP transport
let transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
user: '[email protected]',
pass: 'password'
}
});
let j = schedule.scheduleJob('59 59 23 * * *', function () {
tool.dumpDatabase({
host: 'localhost',
user: 'root',
password: 'a',
dumpPath: './',
database: 'test-gembus'
}, function (error, output, message, dumpFileName) {
console.log(error, output, message, dumpFileName)
let db = './' + dumpFileName
tool.restoreDatabase({
host: 'localhost',
user: 'root',
password: 'a',
sqlFilePath: db,
database: 'test-backup'
}, function (error, output, message) {
if (error instanceof Error) {
console.log(error);
} else {
console.log(output);
console.log(message);
// setup email data with unicode symbols
let mailOptions = {
from: '"yayan" <[email protected]>', // sender address
subject: '✔ Success backup database ', // Subject line
text: '✔ Hello world ?'+message, // plain text body
html: '<b>Backup data selesai ?</b> '+ message // html body
};
// send mail with defined transport object
transporter.sendMail(mailOptions, (error, info) => {
if (error) {
return console.log(error);
}
console.log('Message %s sent: %s', info.messageId, info.response);
});
}
});
})
});