forked from brightcove/dog-watcher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
executable file
·66 lines (57 loc) · 1.77 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env node
'use strict';
/**
* This file will kick off a single backup when config.backupInterval is not defined. When it is
* defined this file will set up the backup process to run at the specified interval.
*/
var later = require('later'),
log4js = require('log4js'),
config = require('./config.json'),
backup = require('./lib/backup.js'),
logger = log4js.getLogger('dog-watcher'),
apiKey = config.dataDogApiKey,
appKey = config.dataDogAppKey,
repo = config.gitRepoForBackups,
backupInterval = config.backupInterval,
backupSchedule,
/**
* Make sure the config file has DataDog keys and a destination repo.
*/
validateConfig = function() {
if (!apiKey || !appKey) {
logger.error('You must provide DataDog keys in the config.json file.');
process.exit(1);
}
if (!repo) {
logger.error('You must provide a git repo in the config.json file.');
process.exit(1);
}
},
backupCallback = function(error) {
if (error) {
logger.error('Backup failed.', error);
} else {
logger.debug('Backup complete.')
}
};
logger.setLevel(process.env.LOG_LEVEL || 'INFO');
validateConfig();
if (backupInterval) {
backupSchedule = later.parse.cron(backupInterval);
if (backupSchedule.error && backupSchedule !== -1) {
logger.error('There was a problem parsing your interval [' + backupInterval + ']. Please ' +
'make sure that this is a valid cron interval.', backupSchedule.error);
process.exit(1);
}
logger.info('Scheduling backups to for ' + backupInterval);
logger.debug(JSON.stringify(backupSchedule.schedules));
later.setInterval(
function() {
backup(backupCallback);
},
backupSchedule
)
} else {
logger.info('Running a one-time backup.');
backup(backupCallback);
}