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
|
@ -137,13 +137,18 @@ function GetApp() {
|
||||||
|
|
||||||
function userSpecificMotdSeenBy(id) {
|
function userSpecificMotdSeenBy(id) {
|
||||||
if (!userSpecificMotd[id].seen) {
|
if (!userSpecificMotd[id].seen) {
|
||||||
logger.Log(`User #${id}'s user specific motd is now seen.`, logger.GetColor('bluebg'))
|
logger.Log(
|
||||||
|
`User #${id}'s user specific motd is now seen.`,
|
||||||
|
logger.GetColor('bluebg')
|
||||||
|
)
|
||||||
userSpecificMotd[id].seen = true
|
userSpecificMotd[id].seen = true
|
||||||
utils.WriteFile(JSON.stringify(userSpecificMotd), userSpecificMotdFile)
|
utils.WriteFile(JSON.stringify(userSpecificMotd), userSpecificMotdFile)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function Load() {
|
function Load() {
|
||||||
|
actions.backupData(data)
|
||||||
|
|
||||||
utils.WatchFile(userSpecificMotdFile, (newData) => {
|
utils.WatchFile(userSpecificMotdFile, (newData) => {
|
||||||
logger.Log(`User Specific Motd changed: ${newData.replace(/\/n/g, '')}`)
|
logger.Log(`User Specific Motd changed: ${newData.replace(/\/n/g, '')}`)
|
||||||
LoadUserSpecificMOTD()
|
LoadUserSpecificMOTD()
|
||||||
|
@ -985,8 +990,9 @@ function GetApp() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function DailyAction() {
|
function DailyAction() {
|
||||||
ExportDailyDataCount()
|
actions.backupData(data)
|
||||||
BackupDB()
|
BackupDB()
|
||||||
|
ExportDailyDataCount()
|
||||||
IncrementAvaiblePWs()
|
IncrementAvaiblePWs()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,7 @@ Question Server
|
||||||
module.exports = {
|
module.exports = {
|
||||||
ProcessIncomingRequest: ProcessIncomingRequest,
|
ProcessIncomingRequest: ProcessIncomingRequest,
|
||||||
LoadJSON: LoadJSON,
|
LoadJSON: LoadJSON,
|
||||||
|
backupData: backupData,
|
||||||
}
|
}
|
||||||
|
|
||||||
const dataFile = './publicDirs/qminingPublic/data.json'
|
const dataFile = './publicDirs/qminingPublic/data.json'
|
||||||
|
@ -196,3 +197,19 @@ function LoadJSON(dataFile) {
|
||||||
}
|
}
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function backupData(data) {
|
||||||
|
const path = './publicDirs/qminingPublic/backs/'
|
||||||
|
utils.CreatePath(path)
|
||||||
|
try {
|
||||||
|
logger.Log('Backing up data...')
|
||||||
|
utils.WriteFile(
|
||||||
|
JSON.stringify(data),
|
||||||
|
`${path}data_${utils.GetDateString(true)}.json`
|
||||||
|
)
|
||||||
|
logger.Log('Done')
|
||||||
|
} catch (err) {
|
||||||
|
logger.Log('Error backing up data file!', logger.GetColor('redbg'))
|
||||||
|
console.error(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -30,6 +30,7 @@ Exportált funkciók:
|
||||||
|
|
||||||
1. ProcessIncomingRequest
|
1. ProcessIncomingRequest
|
||||||
2. LoadJSON
|
2. LoadJSON
|
||||||
|
3. backupData
|
||||||
|
|
||||||
## utils.js
|
## utils.js
|
||||||
|
|
||||||
|
@ -41,11 +42,10 @@ Exportált funkciók:
|
||||||
2. WriteFile
|
2. WriteFile
|
||||||
3. writeFileAsync
|
3. writeFileAsync
|
||||||
4. AppendToFile
|
4. AppendToFile
|
||||||
6. WriteBackup
|
5. FileExists
|
||||||
7. FileExists
|
6. CreatePath
|
||||||
8. CreatePath
|
7. WatchFile
|
||||||
9. WatchFile
|
8. ReadDir
|
||||||
10. ReadDir
|
|
||||||
|
|
||||||
## logger.js
|
## logger.js
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,6 @@ module.exports = {
|
||||||
WriteFile: WriteFile,
|
WriteFile: WriteFile,
|
||||||
writeFileAsync: WriteFileAsync,
|
writeFileAsync: WriteFileAsync,
|
||||||
AppendToFile: AppendToFile,
|
AppendToFile: AppendToFile,
|
||||||
WriteBackup: WriteBackup,
|
|
||||||
FileExists: FileExists,
|
FileExists: FileExists,
|
||||||
CreatePath: CreatePath,
|
CreatePath: CreatePath,
|
||||||
WatchFile: WatchFile,
|
WatchFile: WatchFile,
|
||||||
|
@ -13,14 +12,21 @@ module.exports = {
|
||||||
GetDateString: GetDateString,
|
GetDateString: GetDateString,
|
||||||
}
|
}
|
||||||
|
|
||||||
var fs = require('fs')
|
const fs = require('fs')
|
||||||
|
const logger = require('../utils/logger.js')
|
||||||
|
|
||||||
var logger = require('../utils/logger.js')
|
function GetDateString(noTime) {
|
||||||
|
|
||||||
const dataFile = './qminingPublic/data.json'
|
|
||||||
|
|
||||||
function GetDateString() {
|
|
||||||
const date = new Date()
|
const date = new Date()
|
||||||
|
|
||||||
|
if (noTime) {
|
||||||
|
return (
|
||||||
|
date.getFullYear() +
|
||||||
|
'-' +
|
||||||
|
('0' + (date.getMonth() + 1)).slice(-2) +
|
||||||
|
'-' +
|
||||||
|
('0' + date.getDate()).slice(-2)
|
||||||
|
)
|
||||||
|
} else {
|
||||||
return (
|
return (
|
||||||
date.getFullYear() +
|
date.getFullYear() +
|
||||||
'-' +
|
'-' +
|
||||||
|
@ -35,6 +41,7 @@ function GetDateString() {
|
||||||
('0' + date.getSeconds()).slice(-2)
|
('0' + date.getSeconds()).slice(-2)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function CopyFile(from, to) {
|
function CopyFile(from, to) {
|
||||||
CreatePath(to)
|
CreatePath(to)
|
||||||
|
@ -137,15 +144,3 @@ function AppendToFile(data, file) {
|
||||||
console.error(err)
|
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