-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
26 lines (24 loc) · 883 Bytes
/
app.js
File metadata and controls
26 lines (24 loc) · 883 Bytes
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
const log = require('./class/log');
const AutoTasks = require('./class/AutoTasks');
const cron = require('node-cron');
const moment = require('moment');
log.info('数据库备份服务启动成功');
cron.schedule('15 * * * *', async () => {
// 每小时的第15分钟执行
try {
const taskId = moment().utcOffset(8).format('YYYY-MM-DD HH');
log.info(`备份任务 ${taskId} 开始执行`);
let start_at = new Date().getTime();
await AutoTasks.backupMysql();
await AutoTasks.bakupMongoDB();
await AutoTasks.deleteBackup();
let end_at = new Date().getTime();
let used_time = Math.round((end_at - start_at) / 1000 * 100) / 100;
log.info(`备份 ${taskId} 执行完成, 用时 ${used_time} 秒`);
} catch (e) {
log.error(e);
}
}, {
scheduled: true,
timezone: 'Asia/Shanghai'
});