expressgy 1 year ago
parent bc166215d8
commit a2f2ac7fd1
  1. BIN
      mysqldump
  2. BIN
      mysqldump.exe
  3. 3
      package.json
  4. 25
      server.js
  5. 33
      test.js

Binary file not shown.

Binary file not shown.

@ -14,6 +14,7 @@
"koa": "^2.14.2",
"koa-body": "^6.0.1",
"koa-router": "^12.0.0",
"moment": "^2.29.4"
"moment": "^2.29.4",
"mysqldump": "^3.2.0"
}
}

@ -9,6 +9,7 @@ const router = require('koa-router')()
const moment = require('moment')
const { DATABASELIST, SERVER_PORT, SERVERHOST} = require('./config')
const mysqldump = require("mysqldump");
// 备份间隔时间
const mintues = 60 * 24;// minute
@ -48,18 +49,16 @@ function back(){
* 数据库备份程序
* */
function backSQL(user, passwd, database){
return new Promise(rec => {
const cout = os.platform() == 'win32' ? '-r' : '>'
, filename = `back/BACKUP_${ database }_${ moment().format("YYYY_MM_DD_HH_mm_ss") }.sql`
console.log(cout, filename)
const backProcess = spawn('mysqldump',['-h' + SERVERHOST, database, cout, filename]);
backProcess.stdout.on('data', data => console.log('Data : ', out(data)))
backProcess.stderr.on('data', data => console.log('Error: ', out(data)))
backProcess.on('close', code => {
console.log('Exit :', code.toString())
rec(filename)
})
})
const filename = `./back/${ database }_${ moment().format("YYYY_MM_DD_HH_mm_ss") }.sql`
mysqldump({
connection: {
host: SERVERHOST,
user: user,
password: passwd,
database: database,
},
dumpToFile: filename,
});
}
// 开始备份数据库
@ -160,5 +159,5 @@ function back(){
startBackSQL()
}
server()
// server()
back()

@ -1,33 +0,0 @@
function getT(){
const temore = new Date().getTime() + 1000 * 60 * 60 * 24
const now = new Date(temore)
let year = now.getFullYear(); //得到年份
let month = now.getMonth();//得到月份
let date = now.getDate();//得到日期
return new Date(year + "-" + month + "-" + date).getTime()
}
function transformT(t){
let now = new Date(t);
let year = now.getFullYear(); //得到年份
let month = now.getMonth();//得到月份
let date = now.getDate();//得到日期
let day = now.getDay();//得到周几
let hour = now.getHours();//得到小时
let minu = now.getMinutes();//得到分钟
let sec = now.getSeconds();//得到秒
let MS = now.getMilliseconds();//获取毫秒
let week;
month = month + 1;
if (month < 10) month = "0" + month;
if (date < 10) date = "0" + date;
if (hour < 10) hour = "0" + hour;
if (minu < 10) minu = "0" + minu;
if (sec < 10) sec = "0" + sec;
if (MS < 100)MS = "0" + MS;
let time = "";
time = year + "-" + month + "-" + date + " " + hour + ":" + minu + ":" + sec;
return time
}
console.log(transformT(getT()))
Loading…
Cancel
Save