mirror of
https://gitlab.com/MrFry/mrfrys-node-server
synced 2025-04-01 20:24:18 +02:00
Data backuping every day, and on server startup
This commit is contained in:
parent
7a41281993
commit
a880d67eae
4 changed files with 57 additions and 39 deletions
|
@ -4,7 +4,6 @@ module.exports = {
|
|||
WriteFile: WriteFile,
|
||||
writeFileAsync: WriteFileAsync,
|
||||
AppendToFile: AppendToFile,
|
||||
WriteBackup: WriteBackup,
|
||||
FileExists: FileExists,
|
||||
CreatePath: CreatePath,
|
||||
WatchFile: WatchFile,
|
||||
|
@ -13,27 +12,35 @@ module.exports = {
|
|||
GetDateString: GetDateString,
|
||||
}
|
||||
|
||||
var fs = require('fs')
|
||||
const fs = require('fs')
|
||||
const logger = require('../utils/logger.js')
|
||||
|
||||
var logger = require('../utils/logger.js')
|
||||
|
||||
const dataFile = './qminingPublic/data.json'
|
||||
|
||||
function GetDateString() {
|
||||
function GetDateString(noTime) {
|
||||
const date = new Date()
|
||||
return (
|
||||
date.getFullYear() +
|
||||
'-' +
|
||||
('0' + (date.getMonth() + 1)).slice(-2) +
|
||||
'-' +
|
||||
('0' + date.getDate()).slice(-2) +
|
||||
' ' +
|
||||
('0' + date.getHours()).slice(-2) +
|
||||
':' +
|
||||
('0' + date.getMinutes()).slice(-2) +
|
||||
':' +
|
||||
('0' + date.getSeconds()).slice(-2)
|
||||
)
|
||||
|
||||
if (noTime) {
|
||||
return (
|
||||
date.getFullYear() +
|
||||
'-' +
|
||||
('0' + (date.getMonth() + 1)).slice(-2) +
|
||||
'-' +
|
||||
('0' + date.getDate()).slice(-2)
|
||||
)
|
||||
} else {
|
||||
return (
|
||||
date.getFullYear() +
|
||||
'-' +
|
||||
('0' + (date.getMonth() + 1)).slice(-2) +
|
||||
'-' +
|
||||
('0' + date.getDate()).slice(-2) +
|
||||
' ' +
|
||||
('0' + date.getHours()).slice(-2) +
|
||||
':' +
|
||||
('0' + date.getMinutes()).slice(-2) +
|
||||
':' +
|
||||
('0' + date.getSeconds()).slice(-2)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
function CopyFile(from, to) {
|
||||
|
@ -137,15 +144,3 @@ function AppendToFile(data, file) {
|
|||
console.error(err)
|
||||
}
|
||||
}
|
||||
|
||||
function WriteBackup() {
|
||||
try {
|
||||
WriteFileAsync(
|
||||
ReadFile(dataFile),
|
||||
'public/backs/data_' + new Date().toString()
|
||||
)
|
||||
} catch (err) {
|
||||
logger.Log('Error backing up data json file!', logger.GetColor('redbg'))
|
||||
console.error(err)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue