Compare commits
2 Commits
410975e14e
...
a0e07b4322
Author | SHA1 | Date |
---|---|---|
Florian Hartwich | a0e07b4322 | |
Florian Hartwich | 909767fecf |
|
@ -2,6 +2,7 @@
|
|||
|
||||
const cron = require('cron');
|
||||
const async = require('async');
|
||||
const {exec} = require('child_process');
|
||||
const UserModel = require('../models/user');
|
||||
const signatureTool = require('../signature-tool/signature-tool');
|
||||
|
||||
|
@ -41,10 +42,28 @@ const createAllSignatures = () => {
|
|||
|
||||
};
|
||||
|
||||
const createBackup = () => {
|
||||
console.log('\x1b[35m%s\x1b[0m', new Date().toLocaleString()
|
||||
+ ': cron job started - CREATE BACKUP');
|
||||
exec(__dirname + '/../../backup/backup.sh', (error, stdout, stderr) => {
|
||||
if (error) {
|
||||
console.log(error);
|
||||
}
|
||||
console.log('\x1b[32m%s\x1b[0m',stderr);
|
||||
console.log('\x1b[35m%s\x1b[0m', new Date().toLocaleString()
|
||||
+ ': cron job finished - CREATE BACKUP');
|
||||
})
|
||||
};
|
||||
|
||||
|
||||
// Execute daily @ 02:30 AM
|
||||
const cronJob = cron.job('00 30 02 * * *', createAllSignatures);
|
||||
const cronJobSignature = cron.job('00 30 02 * * *', createAllSignatures);
|
||||
|
||||
// Execute daily @ 04:00 AM
|
||||
const cronJobBackup = cron.job('00 00 04 * * *', createBackup);
|
||||
|
||||
module.exports = {
|
||||
cronJob: cronJob,
|
||||
cronJobSignature: cronJobSignature,
|
||||
cronJobBackup: cronJobBackup,
|
||||
createAllSignatures: createAllSignatures
|
||||
};
|
||||
|
|
|
@ -8,7 +8,7 @@ const express = require('express');
|
|||
const multer = require('multer');
|
||||
const storage = multer.memoryStorage();
|
||||
const upload = multer({storage: storage});
|
||||
const logger = require('debug')('cc:squads');
|
||||
const logger = require('debug')('cc:wars');
|
||||
|
||||
// HTTP status codes by name
|
||||
const codes = require('./http-codes');
|
||||
|
|
|
@ -15,9 +15,10 @@ const urls = require('./config/api-url');
|
|||
const restAPIchecks = require('./middleware/request-checks.js');
|
||||
const errorResponseWare = require('./middleware/error-response');
|
||||
const apiAuthenticationMiddleware = require('./middleware/auth-middleware');
|
||||
const checkSql = require('./middleware/permission-check').checkSql;
|
||||
const checkAdmin = require('./middleware/permission-check').checkAdmin;
|
||||
const signatureCronJob = require('./cron-job/update-signatures').cronJob;
|
||||
const signatureCronJob = require('./cron-job/update-signatures').cronJobSignature;
|
||||
const backupCronJob = require('./cron-job/update-signatures').cronJobBackup;
|
||||
|
||||
|
||||
// router modules
|
||||
const authenticateRouter = require('./routes/authenticate');
|
||||
|
@ -110,6 +111,7 @@ if (process.env.NODE_ENV !== config.test.env) {
|
|||
else {
|
||||
debug('Listening on port ' + config.port);
|
||||
signatureCronJob.start();
|
||||
backupCronJob.start();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
|
|
|
@ -1,4 +1,17 @@
|
|||
#!/bin/bash
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# execute script in its location folder
|
||||
cd $(dirname $0)
|
||||
|
||||
deleteOldest() {
|
||||
line_num=0
|
||||
while IFS= read -r -d $'\0'; do
|
||||
if [ $line_num == 1 ]; then
|
||||
$(rm -rf ${REPLY})
|
||||
fi
|
||||
((line_num++))
|
||||
done < <(find -maxdepth 1 -type d -print0 | sort -z)
|
||||
}
|
||||
|
||||
# array of available collection names
|
||||
col=(app_user awarding decoration rank squad user promotion player war)
|
||||
|
@ -10,6 +23,9 @@ do
|
|||
then
|
||||
mongoexport --db cc --collection $i --out $(date '+%Y-%m-%d')/collections/${i}.json;
|
||||
cp -R ../api/resource $(date '+%Y-%m-%d')/
|
||||
if [ $(ls -l | grep -c ^d) -gt 5 ]; then
|
||||
deleteOldest
|
||||
fi
|
||||
else
|
||||
mongoimport --db cc --collection $i --drop --file ${1}/collections/${i}.json
|
||||
rm -rf ../api/resource
|
||||
|
|
Loading…
Reference in New Issue