<link href="//maxcdn.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css">
<script src="//maxcdn.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<!------ Include the above in your HEAD tag ---------->
<div class="container">
<div class="row">
<h2>company cron job</h2>
</div>
</div>
const cron = require("node-cron");
const express = require("express");
const databaseUpdation = require("./cronjobs/database");
import {getDbList} from './cronjobs/database'
// import
const app = express(); // Initializing app
// databaseUpdation
getDbList()
// Creating a cron job which runs on every 10 second
console.log('hello')
app.listen(3000);
import path from 'path';
import cron from 'node-cron'
const { spawn } = require('child_process');
const DB_NAME = 'ico-clientpanel';
const BACKUP_PATH= path.join(__dirname, '../../backup', `${DB_NAME}.gzip`);
console.log(BACKUP_PATH,">>>>>>>>>>")
export async function getDbList() {
try {
const child = spawn('mongodump',[
`--db=${DB_NAME}`,
`--archive=${BACKUP_PATH}`,
'--gzip'
]);
child.stdout.on('data',(data:any)=>{
console.log('stdoup',data)
})
child.stderr.on('data',(data:any)=>{
console.log('stdoup',Buffer.from(data).toString())
})
child.on('error',(err:any)=>{
console.log(err);
})
child.on('exit',(code:any,signal:any)=>{
if(code){
console.log('process exit with code', code)
}else if(signal){
console.log('process killed with signal',signal)
}else{
console.log("back up success");
}
})
} catch (error) {
console.log('Error', error)
}
}
// Scheduling the database backup every night
cron.schedule('00 00 00 * * *', () => getDbList ());
// cron.schedule('*/10 * * * * *', () => getDbList ());