Add backup cronjob

pull/1/head
Florian Hartwich 2017-07-15 12:03:38 +02:00
parent 909767fecf
commit a0e07b4322
4 changed files with 29 additions and 5 deletions

View File

@ -2,6 +2,7 @@
const cron = require('cron'); const cron = require('cron');
const async = require('async'); const async = require('async');
const {exec} = require('child_process');
const UserModel = require('../models/user'); const UserModel = require('../models/user');
const signatureTool = require('../signature-tool/signature-tool'); 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 // 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 = { module.exports = {
cronJob: cronJob, cronJobSignature: cronJobSignature,
cronJobBackup: cronJobBackup,
createAllSignatures: createAllSignatures createAllSignatures: createAllSignatures
}; };

View File

@ -8,7 +8,7 @@ const express = require('express');
const multer = require('multer'); const multer = require('multer');
const storage = multer.memoryStorage(); const storage = multer.memoryStorage();
const upload = multer({storage: storage}); const upload = multer({storage: storage});
const logger = require('debug')('cc:squads'); const logger = require('debug')('cc:wars');
// HTTP status codes by name // HTTP status codes by name
const codes = require('./http-codes'); const codes = require('./http-codes');

View File

@ -15,9 +15,10 @@ const urls = require('./config/api-url');
const restAPIchecks = require('./middleware/request-checks.js'); const restAPIchecks = require('./middleware/request-checks.js');
const errorResponseWare = require('./middleware/error-response'); const errorResponseWare = require('./middleware/error-response');
const apiAuthenticationMiddleware = require('./middleware/auth-middleware'); const apiAuthenticationMiddleware = require('./middleware/auth-middleware');
const checkSql = require('./middleware/permission-check').checkSql;
const checkAdmin = require('./middleware/permission-check').checkAdmin; 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 // router modules
const authenticateRouter = require('./routes/authenticate'); const authenticateRouter = require('./routes/authenticate');
@ -110,6 +111,7 @@ if (process.env.NODE_ENV !== config.test.env) {
else { else {
debug('Listening on port ' + config.port); debug('Listening on port ' + config.port);
signatureCronJob.start(); signatureCronJob.start();
backupCronJob.start();
} }
}); });
} else { } else {

View File

@ -1,5 +1,8 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# execute script in its location folder
cd $(dirname $0)
deleteOldest() { deleteOldest() {
line_num=0 line_num=0
while IFS= read -r -d $'\0'; do while IFS= read -r -d $'\0'; do