Add backup cronjob
parent
909767fecf
commit
a0e07b4322
|
@ -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,5 +1,8 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# execute script in its location folder
|
||||
cd $(dirname $0)
|
||||
|
||||
deleteOldest() {
|
||||
line_num=0
|
||||
while IFS= read -r -d $'\0'; do
|
||||
|
|
Loading…
Reference in New Issue