take backup
parent
b73c16c8c4
commit
9c48e80748
28
app.js
28
app.js
|
@ -28,8 +28,9 @@ app.get(routes.root, function(req, res) {
|
||||||
//crontab.create_new("/sbin/ping -c 1 192.168.0.1 > /dev/null", "* * * * *");
|
//crontab.create_new("/sbin/ping -c 1 192.168.0.1 > /dev/null", "* * * * *");
|
||||||
crontab.crontabs( function(docs){
|
crontab.crontabs( function(docs){
|
||||||
res.render('index', {
|
res.render('index', {
|
||||||
routes : routes,
|
routes : JSON.stringify(routes),
|
||||||
crontabs : JSON.stringify(docs)
|
crontabs : JSON.stringify(docs),
|
||||||
|
backups : crontab.get_backup_names()
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
@ -46,6 +47,29 @@ app.post(routes.save, function(req, res) {
|
||||||
res.end();
|
res.end();
|
||||||
})
|
})
|
||||||
|
|
||||||
|
app.post(routes.stop, function(req, res) {
|
||||||
|
crontab.status(req.body._id, true);
|
||||||
|
res.end();
|
||||||
|
})
|
||||||
|
|
||||||
|
app.post(routes.start, function(req, res) {
|
||||||
|
crontab.status(req.body._id, false);
|
||||||
|
res.end();
|
||||||
|
})
|
||||||
|
|
||||||
|
app.post(routes.remove, function(req, res) {
|
||||||
|
crontab.remove(req.body._id);
|
||||||
|
res.end();
|
||||||
|
})
|
||||||
|
app.get(routes.crontab, function(req, res) {
|
||||||
|
crontab.set_crontab();
|
||||||
|
res.end();
|
||||||
|
})
|
||||||
|
|
||||||
|
app.get(routes.backup, function(req, res) {
|
||||||
|
crontab.backup();
|
||||||
|
res.end();
|
||||||
|
})
|
||||||
app.listen(app.get('port'), function() {
|
app.listen(app.get('port'), function() {
|
||||||
console.log("Crontab UI is running at localhost:" + app.get('port'))
|
console.log("Crontab UI is running at localhost:" + app.get('port'))
|
||||||
})
|
})
|
||||||
|
|
25
crontab.js
25
crontab.js
|
@ -24,6 +24,14 @@ exports.create_new = function(name, command, schedule){
|
||||||
exports.update = function(data){
|
exports.update = function(data){
|
||||||
db.update({_id: data._id}, crontab(data.name, data.command, data.schedule, null));
|
db.update({_id: data._id}, crontab(data.name, data.command, data.schedule, null));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
exports.status = function(_id, stopped){
|
||||||
|
db.update({_id: _id},{$set: {stopped: stopped}});
|
||||||
|
}
|
||||||
|
|
||||||
|
exports.remove = function(_id){
|
||||||
|
db.remove({_id: _id}, {});
|
||||||
|
}
|
||||||
exports.crontabs = function(callback){
|
exports.crontabs = function(callback){
|
||||||
db.find({}, function(err, docs){
|
db.find({}, function(err, docs){
|
||||||
callback(docs);
|
callback(docs);
|
||||||
|
@ -43,3 +51,20 @@ exports.set_crontab = function(){
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
exports.get_backup_names = function(){
|
||||||
|
var backups = []
|
||||||
|
fs.readdirSync(__dirname + '/crontabs').forEach(function(file){
|
||||||
|
// file name begins with backup
|
||||||
|
if(file.indexOf("backup") == 0){
|
||||||
|
backups.push(file);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return backups;
|
||||||
|
}
|
||||||
|
|
||||||
|
exports.backup = function(){
|
||||||
|
//TODO check if it failed
|
||||||
|
fs.createReadStream( __dirname + '/crontabs/crontab.db').pipe(fs.createWriteStream( __dirname + '/crontabs/backup ' + (new Date()).toString() + '.db'));
|
||||||
|
}
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
/*********** MessageBox ****************/
|
/*********** MessageBox ****************/
|
||||||
// simply show info. Only close button
|
// simply show info. Only close button
|
||||||
function infoMessageBox(message, title){
|
function infoMessageBox(message, title){
|
||||||
$("#modal-body").html(message);
|
$("#info-body").html(message);
|
||||||
$("#modal-title").html(title);
|
$("#info-title").html(title);
|
||||||
$("#modal-button").hide();
|
$("#info-popup").modal('show');
|
||||||
$("#popup").modal('show');
|
|
||||||
}
|
}
|
||||||
// modal with full control
|
// modal with full control
|
||||||
function messageBox(body, title, ok_text, close_text, callback){
|
function messageBox(body, title, ok_text, close_text, callback){
|
||||||
|
@ -23,23 +22,39 @@ function messageBox(body, title, ok_text, close_text, callback){
|
||||||
function deleteJob(_id){
|
function deleteJob(_id){
|
||||||
// TODO fix this. pass callback properly
|
// TODO fix this. pass callback properly
|
||||||
messageBox("<p> Do you want to delete this Job? </p>", "Confirm delete", null, null, function(){
|
messageBox("<p> Do you want to delete this Job? </p>", "Confirm delete", null, null, function(){
|
||||||
console.log("delete job");
|
$.post(routes.remove, {_id: _id}, function(){
|
||||||
|
location.reload();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function stopJob(_id){
|
function stopJob(_id){
|
||||||
messageBox("<p> Do you want to stop this Job? </p>", "Confirm stop job", null, null, function(){
|
messageBox("<p> Do you want to stop this Job? </p>", "Confirm stop job", null, null, function(){
|
||||||
console.log("stop job");
|
$.post(routes.stop, {_id: _id}, function(){
|
||||||
|
location.reload();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function startJob(_id){
|
function startJob(_id){
|
||||||
messageBox("<p> Do you want to start this Job? </p>", "Confirm start job", null, null, function(){
|
messageBox("<p> Do you want to start this Job? </p>", "Confirm start job", null, null, function(){
|
||||||
console.log("start job");
|
$.post(routes.start, {_id: _id}, function(){
|
||||||
|
location.reload();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function setCrontab(){
|
||||||
|
messageBox("<p> Do you want to set the crontab file? </p>", "Confirm crontab setup", null, null, function(){
|
||||||
|
$.get(routes.crontab, {}, function(){
|
||||||
|
// TODO show only if success
|
||||||
|
infoMessageBox("Successfuly set crontab file!","Information");
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function editJob(_id){
|
function editJob(_id){
|
||||||
|
console.log(_id);
|
||||||
var job = null;
|
var job = null;
|
||||||
crontabs.forEach(function(crontab){
|
crontabs.forEach(function(crontab){
|
||||||
if(crontab._id == _id)
|
if(crontab._id == _id)
|
||||||
|
@ -48,7 +63,7 @@ function editJob(_id){
|
||||||
if(job){
|
if(job){
|
||||||
$("#job").modal("show");
|
$("#job").modal("show");
|
||||||
$("#job-name").val(job.name);
|
$("#job-name").val(job.name);
|
||||||
$("#job-command").val(job.command);
|
$("#job-command").val(job.command.replace("\"","\\\""));
|
||||||
// if macro not used
|
// if macro not used
|
||||||
if(job.schedule.indexOf("@") != 0){
|
if(job.schedule.indexOf("@") != 0){
|
||||||
var components = job.schedule.split(" ");
|
var components = job.schedule.split(" ");
|
||||||
|
@ -65,7 +80,7 @@ function editJob(_id){
|
||||||
|
|
||||||
$("#job-save").click(function(){
|
$("#job-save").click(function(){
|
||||||
// TODO good old boring validations
|
// TODO good old boring validations
|
||||||
$.post("/save", {name: $("#job-name").val(), command: job_command , schedule: schedule, _id: _id}, function(){
|
$.post(routes.save, {name: $("#job-name").val(), command: job_command , schedule: schedule, _id: _id}, function(){
|
||||||
location.reload();
|
location.reload();
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
@ -86,12 +101,19 @@ function newJob(){
|
||||||
job_string();
|
job_string();
|
||||||
$("#job-save").click(function(){
|
$("#job-save").click(function(){
|
||||||
// TODO good old boring validations
|
// TODO good old boring validations
|
||||||
$.post("/save", {name: $("#job-name").val(), command: job_command , schedule: schedule, _id: -1}, function(){
|
$.post(routes.save, {name: $("#job-name").val(), command: job_command , schedule: schedule, _id: -1}, function(){
|
||||||
location.reload();
|
location.reload();
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function doBackup(){
|
||||||
|
messageBox("<p> Do you want to take backup? </p>", "Confirm backup", null, null, function(){
|
||||||
|
$.get(routes.backup, {}, function(){
|
||||||
|
location.reload();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// script corresponding to job popup management
|
// script corresponding to job popup management
|
||||||
var schedule = "";
|
var schedule = "";
|
||||||
|
@ -105,4 +127,5 @@ function set_schedule(){
|
||||||
schedule = $("#job-minute").val() + " " +$("#job-hour").val() + " " +$("#job-day").val() + " " +$("#job-month").val() + " " +$("#job-week").val();
|
schedule = $("#job-minute").val() + " " +$("#job-hour").val() + " " +$("#job-day").val() + " " +$("#job-month").val() + " " +$("#job-week").val();
|
||||||
job_string();
|
job_string();
|
||||||
}
|
}
|
||||||
|
// popup management ends
|
||||||
|
|
||||||
|
|
|
@ -2,5 +2,9 @@ exports.routes = {
|
||||||
"root" : "/",
|
"root" : "/",
|
||||||
"downloads" : "/downloads",
|
"downloads" : "/downloads",
|
||||||
"save" : "/save",
|
"save" : "/save",
|
||||||
"crontab" : "/crontab"
|
"crontab" : "/crontab",
|
||||||
|
"stop" : "/stop",
|
||||||
|
"start" : "/start",
|
||||||
|
"remove": "/remove",
|
||||||
|
"backup": "/backup",
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,10 +7,13 @@
|
||||||
<link rel="stylesheet" href="bootstrap.min.css" />
|
<link rel="stylesheet" href="bootstrap.min.css" />
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
var crontabs = [];
|
var crontabs = [];
|
||||||
|
var routes = [];
|
||||||
$(function () {
|
$(function () {
|
||||||
// initialize tooltips
|
// initialize tooltips
|
||||||
$('[data-toggle="tooltip"]').tooltip();
|
$('[data-toggle="tooltip"]').tooltip();
|
||||||
|
// TODO handle the commands with quotes
|
||||||
crontabs = JSON.parse('<%- crontabs %>');
|
crontabs = JSON.parse('<%- crontabs %>');
|
||||||
|
routes = JSON.parse('<%- routes %>');
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
|
@ -61,10 +64,10 @@
|
||||||
|
|
||||||
</table>
|
</table>
|
||||||
<a class="btn btn-primary" onclick="newJob();"><span class="glyphicon glyphicon-plus-sign" aria-hidden="true"></span> New</a>
|
<a class="btn btn-primary" onclick="newJob();"><span class="glyphicon glyphicon-plus-sign" aria-hidden="true"></span> New</a>
|
||||||
<a class="btn btn-info"><span class="glyphicon glyphicon-floppy-save" aria-hidden="true"></span> Backup</a>
|
<a class="btn btn-info" onclick="doBackup();"><span class="glyphicon glyphicon-floppy-save" aria-hidden="true"></span> Backup</a>
|
||||||
<a class="btn btn-info"><span class="glyphicon glyphicon-download-alt" aria-hidden="true"></span> Export</a>
|
<a class="btn btn-info"><span class="glyphicon glyphicon-download-alt" aria-hidden="true"></span> Export</a>
|
||||||
<a class="btn btn-info"><span class="glyphicon glyphicon-import" aria-hidden="true"></span> Import from crontab</a>
|
<a class="btn btn-info"><span class="glyphicon glyphicon-import" aria-hidden="true"></span> Import from crontab</a>
|
||||||
<a class="btn btn-success"><span class="glyphicon glyphicon-save" aria-hidden="true"></span> Save to crontab</a>
|
<a class="btn btn-success" onclick="setCrontab();"><span class="glyphicon glyphicon-save" aria-hidden="true"></span> Save to crontab</a>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -15,12 +15,16 @@
|
||||||
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
|
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
|
||||||
<ul class="nav navbar-nav">
|
<ul class="nav navbar-nav">
|
||||||
<li><a href="#">Import</a></li>
|
<li><a href="#">Import</a></li>
|
||||||
<li><a href="<%= routes.downloads %>">Downloads<span class="sr-only">(current)</span></a></li>
|
|
||||||
<li class="dropdown">
|
<li class="dropdown">
|
||||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">Backups <span class="caret"></span></a>
|
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">Backups <span class="caret"></span></a>
|
||||||
<ul class="dropdown-menu" role="menu">
|
<ul class="dropdown-menu" role="menu">
|
||||||
<!-- TODO -->
|
<% if (backups.length == 0){ %>
|
||||||
<li><a href="#">None</a></li>
|
<li><a href="#">None</a></li>
|
||||||
|
<% } else { %>
|
||||||
|
<% backups.forEach(function(file){ %>
|
||||||
|
<li><a href="#"><%= file %></a></li>
|
||||||
|
<% }) %>
|
||||||
|
<% } %>
|
||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
|
@ -15,6 +15,22 @@
|
||||||
</div><!-- /.modal-dialog -->
|
</div><!-- /.modal-dialog -->
|
||||||
</div><!-- /.modal -->
|
</div><!-- /.modal -->
|
||||||
|
|
||||||
|
<div class="modal fade" id="info-popup">
|
||||||
|
<div class="modal-dialog">
|
||||||
|
<div class="modal-content">
|
||||||
|
<div class="modal-header">
|
||||||
|
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
|
||||||
|
<h4 class="modal-title" id="info-title">Message</h4>
|
||||||
|
</div>
|
||||||
|
<div class="modal-body" id="info-body">
|
||||||
|
</div>
|
||||||
|
<div class="modal-footer">
|
||||||
|
<button type="button" class="btn btn-primary" data-dismiss="modal" id="info-button">Ok</button>
|
||||||
|
</div>
|
||||||
|
</div><!-- /.modal-content -->
|
||||||
|
</div><!-- /.modal-dialog -->
|
||||||
|
</div><!-- /.modal -->
|
||||||
|
|
||||||
<!-- Job -->
|
<!-- Job -->
|
||||||
<div class="modal fade" id="job">
|
<div class="modal fade" id="job">
|
||||||
<div class="modal-dialog">
|
<div class="modal-dialog">
|
||||||
|
|
Loading…
Reference in New Issue